(25%) Write a program that calculates the sine of the following angles in degree
ID: 1867584 • Letter: #
Question
(25%) Write a program that calculates the sine of the following angles in degrees: 0, 20, 40, 60, 80, 100. The program uses a loop for adding the terms of the Taylor series: sin(x) ? -1)H 2n+1 = 012n+1), x In each pass calculate the estimated error E S-Sn-1 n--1 Stop adding terms when E s0.00000001. Note the number of terms used for each angle. Output results to the command window in the format: angle sine value mber of terms 0.0000 20 40 60 80 100 x.xxXX umber of terms (y-axis) vs angle in degrees (x-axis) as squares. a) script; b) output of values in the command window; c) figure.Explanation / Answer
CODE:
clear all;close all;clc;
j=1;
for x=20:20:100
S(1)=0;i=2;n=0;dec=1;
while (dec)
S(i)=S(i-1)+(((-1.^n)*(x.^((2*n)+1)))/(factorial((2*n)+1)));
E=abs((S(i)-S(i-1))/S(i-1));
i=i+1;
if E<=0.00000001
dec=0;
else
n=n+1;
end
end
angle(j)=x;sine_value(j)=S(n);term(j)=n;
j=j+1;
end
figure;
plot(term,x);
T=table(angle',sine_value',term')
OUTPUT:
20 -2.4258e+08 25
40 -1.1769e+17 40
60 -5.71e+25 54
80 -2.7703e+34 68
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.