Write a MATLAB script, which asks the user to input the angle xd (in deg) and th
ID: 2268372 • Letter: W
Question
Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: .ur....-z-$+-$ sin(x) = 5 (-1)+12-1 (-(2n-1)! sin(r) 1 3! 5! 7! 9! Note that x in Taylor's equation is in radian, so make sure to do the conversion first. Start with defining the vector n=1.5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number, you may use factorial function in MATLAB. Check your code for input xd 38° and compare the result to sind(38).Use fprintf to report the results on the screen.Explanation / Answer
code:
close all;
clc;
prompt = 'What is the original value? ';
xd=input(prompt);
x=(3.14/180)*xd;
sin(xd)=x-(x^3/factorial(3))+(x^5/factorial(5))-(x^7/factorial(7))+(x^9/factorial(9));
display(sin(xd))
A1=[0.6154,sin(38)];
formatSpec = 'X is 38 then resut is sin(38)=%4.2f or sin(xd)=%8.3f ';
fprintf(formatSpec,A1)
result:
What is the original value? 38
0.6154
X is 38 then resut is sin(38)=0.62 or sin(xd)= 0.615 >>
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.