Using matlab The trigonometric sine function can be expresse
Using matlab
The trigonometric sine function can be expressed as the following infinite Taylor series. sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! Use the for loop control structure to write a MATLAB function m file that evaluates the first n terms of this series. Your function should be defined as follows: function sinx = mysin(x, n) Although you may assume that the input arguments passed to your function will be numeric, your function should trap for invalid input agrument values (e. g nonpositive and/or noninteger values for n); if your program detects invalid input, it should display an appropriate error message and stop. You may; not use the MATLAB built in sin trigonietirc funciton in your program. Name your subrinited file sysin mSolution
Below code will solve your problem.
clear
clc
n = 200;
x = pi/3;
y = zeros(x,n);
for i = 1:n
y(i) = (-1)^i*x^(2*i+1)/factorial(2*i+1);
end
result = sum(y);
disp(result);
