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

Please anwser using scilab notation thank you Write a program to compute sin(x).

ID: 3791731 • Letter: P

Question

Please anwser using scilab notation thank you

Write a program to compute sin(x). The name of the program is dsin, and it accepts the user input – x – in degrees. Your program converts x to radians, and uses taylor series to compute sin(x) within some defined accuracy. The program has two versions; one version uses the ‘while’ construct, and the other version uses the ‘for’ construct.

Note: • Taylor series approximates the sinusoidal function for -180 x 180 degrees (or -pi x pi). If your input is out of this range, your program must translate it to a value within the range. • When you run dsin, it prompts; Enter angle in degrees: • After you type desired angle, the result will return. • You are not allowed to use the trigonometric functions provided by Matlab!

Explanation / Answer

Here is the code for you:

x = input('Enter the value for x: ');

n = 100;

sum = 0.0;

for i = 0 : n-1

sum = sum + (-1)^i * x^(2*i+1)/Factorial(2*i+1);

end

fprintf('Sin(%d) = %f ', x, sum);

And the code using while loop is:

x = input('Enter the value for x: ');

n = 100;

sum = 0.0;

%for i = 0 : n-1

% sum = sum + (-1)^i * x^(2*i+1)/Factorial(2*i+1);

%end

i = 0;

while(i < n)

sum = sum + (-1)^i * x^(2*i+1)/Factorial(2*i+1);

i = i + 1;

end

fprintf('Sin(%d) = %f ', x, sum);