Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How I can fix it? In [33]: from math import factorial def mysin(x): tsin = 0 for n in range(N): if(n%2): sign=-1 else: sign= 1
How I can fix it?
In [33]: from math import factorial def mysin(x): tsin = 0 for n in range(N): if(n%2): sign=-1 else: sign= 1 num = sign*x**(2*n+1) denom = factorial(2*n+1) tsin += num/denom return tsin In [36]: %matplotlib inline import numpy as np from matplotlib import pylab as pit from math import pi from math import sin x = pi/4 terms = 100 N = np.arange(terms) tsin = np.zeros(terms) for n in N: pit.figure() pit.plot(N, mysin(x), label = 'mysin') pit.axhline(y=sin(x), color='k', label = 'sin - Exact') pit.legend() TypeError Traceback (most recent call last) in () 9 n= np.arange(terms) 10 pit.figure() ---- > 11 pit.plot(N, mysin(x), label = 'mysin') 12 pit.axhline(y=sin(x), color='k', label = 'sin - Exact') 13 pit.legend() in mysin(x) 2 def mysin(x): 3 tsin = 0 --- > 4 for n in range(N): 5 if(n%2): 6 sign=-1 TypeError: only integer scalar arrays can be converted to a scalar indexStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started