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

Consider the Taylor series for a sine wave shown below. Write a script file that

ID: 671709 • Letter: C

Question

Consider the Taylor series for a sine wave shown below.

Write a script file that does the following:

Prompts the user for an angle (in radians) between 0 and 2pi.

Prompts the user for the number of terms to use in the Taylor series

Uses a for loop to calculate the estimate for the sine of the angle by summing the number of terms in the Taylor series specified by the user. (Note: don’t count the missing terms – the even powers of x – in your count of terms).

Uses fprintf statement(s) to display the estimate of the sine, the actual sine, and the absolute value of the difference between actual and estimate. All of these values should be displayed using 6 places behind the decimal point.

Explanation / Answer

Matlab code:

so=0;

se=0;

s=0;

x=input('enter the value of x');

N=input('enter the value of N');

for i=1:N

s0=so-((x^i))/i

i=i+4;

for i=3:N

se=se-((x^i))/i

i=i+4;

s=so-se;

fprintf('estimate of the sine is %.6f',s);

fprintf('actual sine, is %.6f',sin(x));

diff=sin(x)-s;

fprintf(' difference between actual and estimate is %.6f',abs(diff));

end;

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