please write the code and expline ..... USE MATLAB Write a program to compute si
ID: 3790219 • Letter: P
Question
please write the code and expline ..... USE MATLAB
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. When you run dsin, it prompts; Enter angle in degrees: After you type the desired angle, the result will be returned. You are not allowed to use the trigonometric functions provided by Matlab!Explanation / Answer
clear
clc
deg = input('Enter angle in degrees ' );
rad=(pi/180)*deg;
x=rad;
n=100
y = zeros(1,n);
for i = 0:n
y(i+1) = (-1)^i*x^(2*i+1)/factorial(2*i+1);
end
SINx = sum(y);
disp(SINx);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.