Question: Can't get it to run need help A script file to calculate sine series Calculate g(x) = sin(x) using the Taylor series expansion for a
Can't get it to run need help



A script file to calculate sine series Calculate g(x) = sin(x) using the Taylor series expansion for a given value of x. Solve for s(pi/3) using 5, 10, 20 and 100 terms in the Taylor series (use a loop). Please also use the commands: INPUT, DISP for the program's input/ output Tylor series: X3 X5 (-1)" sin(x) = x = X- + += 3! 5! (2n + 1)! n=0 x2n+1 A function file to compute sine series Take the script file written above and convert it into a function file and repeat all requirements of part one. >> x = input('Enter value for x: '); Enter value for x: pi/3 >> n = [5,10,20,100]; >> y = zeros (length(n), max (n)); >> for j=1:length (n) nn = n()); for i = 0:nn-1 y(),i+1) = (((-1)^i)*(x^(2*1+1))) /factorial (2*1+1); end fprintf('For $d terms: ', nn) disp (sum (v (j, 1:end) ) ) end For 5 terms: 0.8660 For 10 terms: 0.8660 For 20 terms: 0.8660 For 100 terms: 0.8660 >> taylor_series error: parse error near line 1 of file C:\Users taylor_series.m syntax error >>> >> x = input ("Enter value for x: '); >> taylor_series error: parse error near line l of file C:\Users taylor_series.m syntax error >>> >> x = input ("Enter value for x: '); >> pi/3 ans = 1.0472 >> taylor_series error: parse error near line 1 of file C:\Users taylor_series.m syntax error >>> >> x = input('Enter value for x: '); >> pi/3 ans = 1.0472 >> | taylor_series.mx 1 >> X = input('Enter value for x: "); 2 Enter value for x: pi/3 3 [5,10,20,100]; 4 >> y = zeros (length(n), max (n)); 5 ]>> for j=1:length (n) nn = n(j); 7 for i = 0:nn-1 8 y(j,i+1) = (((-1)^i) * (x^(2*1+1)))/factorial (2*1+); 9 Fend 10 fprintf('For sd terms: nn) 11 disp (sum (v (), 1:end))) 12 Fend 13 For 5 terms: 0.8660 14 For 10 terms: 0.8660 15 For 20 terms: 0.8660 16 For 100 terms: 0.8660 17 18 function sinx = taylor_series (x, term) 19 sinx = 0; 20 for i = 0; term-1 21 sinx = sinx + (-1)^i * ( ** (2*1+1) ) ) / factorial (2*i+1); 22 Fend 23 end 24
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
