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

The series expansion for the sine function is: sin(x)= x3/ 3!+ x5 /5+x7 /7!+ x9

ID: 2988627 • Letter: T

Question

The series expansion for the sine function is: sin(x)= x3/ 3!+ x5 /5+x7 /7!+ x9 /9!+... Make a graph showing the value of sin(x) with five functions consisting of the series with an additional term. Specifically, the first function is just the first term, f1(x) = x, the second function consists of the first two terms f2(x) = x3 /3!, the third consists of the first 3 terms, etc.

Make the code for this function:

function [sValue, sTerms] = sinsum(x, errorLimit)

%This function returns an estimate of the sin of x

% x is the value in radians of the angle (one number only no vectors)

% errorLimit is the difference between sinsum and the true value of sin

% sValue is the estimated sin(x)

% sTerms is the number of terms it took in the series expansion. Demonstrate this function by calling it from a script with x = 1 and errorLimit = 0.01.

Explanation / Answer

Matlab script for generating the Graphs

x = 0:0.01:2*pi;
y = sin(x);
y1 = x;
y2 = x - x.^3/factorial(3);
y3 = x - x.^3/factorial(3) + x.^5/factorial(5);
y4 = x - x.^3/factorial(3) + x.^5/factorial(5) - x.^7/factorial(7);
y5 = x - x.^3/factorial(3) + x.^5/factorial(5) - x.^7/factorial(7) + x.^9/factorial(9);
plot(x,y,'r');
hold on;
plot(x,y1);
hold on;
plot(x,y2);
hold on;
plot(x,y3);
hold on;
plot(x,y4);
hold on;
plot(x,y5);
axis([0 7 -5 5]);

Matlab script for function sinsum

function [sValue, sTerms] = sinsum(x, errorLimit)
count = 1;
value = x;
True_value = sin(x);
error = value - True_value;
error = abs(error);
while(error > errorLimit)
for i = 1:count
value = value + (((-1)^i)*(x^(2*i+1)))/factorial(2*i+1);
end
error = value - True_value;
error = abs(error);
count = count + 1;
end
sValue = value;
sTerms = count;

Testing it.

[sValue, sTerms] = sinsum(1,0.01);

sValue = 0.8333

sTerms = 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote