Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a) >> Exp7_4a Enter the number of terms 20 The sum of the series is: -0.222216 b

ID: 2262155 • Letter: A

Question

a)

>> Exp7_4a

Enter the number of terms 20

The sum of the series is: -0.222216

b)

>>Tsin(150,3)

ans =

          0.65227308508921

>> Tsin(150,7)

ans =

         0.500001387290603

MATLAB programming a) Use a for-end loop in a script file to calculate the sum of the first n terms of the series: -1 (-1, k. Execute the script file for n-4 and n-20. -k=1 b) The function sin(x) can be written as a Taylor series by: sin x = oo (-1)* 2k+1 Write a user-defined function file that calculates sinx) by using the Taylor's Series For the function name and arguments use y - Tsin(x, n). The input arguments are the angle x in degrees, and n the number of terms in the series. Use the function to calculate sin(150°) using 3 and 7 terms. Here is the answer when you run the code

Explanation / Answer

clc;
clear all;
sum=0;
n=4;
for k=1:n
sum=sum+(-1)^k*k/2^k;
n=n+1;
end
sum

sum =

-0.125000000000000

>>

clc;
clear all;
sum=0;
n=20;
for k=1:n
sum=sum+(-1)^k*k/2^k;
n=n+1;
end
sum

sum =

-0.222215652465820

function y=Tsin(x,n)
z=degtorad(150);
y=0;
for k=0:n
y=y+(-1)^k*z^(2*k+1)/factorial(2*k+1);
n=n+1;
end

y=Tsin(150,3)

y =

   0.485029353117664

>> y=Tsin(150,7)

y =

   0.499999964864254

>> y=Tsin(150,10)

y =

   0.500000000000157

>>