11.0k views
5 votes
3. Given the Taylor series expansion for sin x = x − x3/ 3! + x5/5! − x7/7! . Write a program that takes in an arbitrary integer for an angle in degrees, converted the degrees to radians and performs the calculation above. Remember you will need a loop to calculate the ! term and float variables to hold the term(s) in the expansion and the converted degrees to radian.

1 Answer

4 votes

Answer:

clc

clear

x = input('type value of angle in degrees:\\');

x = x*pi/180; %convverting fron degree to radian

sin_x = x; %as first term of taylor series is x

E = 1; %just giving a value of error greater than desired error

n = 0;

while E > 0.000001

previous = sin_x;

n = n+1;

sin_x = sin_x + ((-1)^n)*(x^(2*n+1))/factorial(2*n+1);

E = abs(sin_x - previous); %calculating error

end

a = sprintf('sin(x) = %1.6f',sin_x);

disp(a)

Step-by-step explanation:

User Kapa
by
5.5k points