Question: 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? ![How I can fix it? In [33]: from math import factorial def](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3932aa7293_95466f3932a08bff.jpg)
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 index
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
