[Solved] Writing a function that calculates sine for inputted number of terms. MATLAB [closed]


found the answer myself.. note that there is a difference between sinx and sin(x)

function  [sinx, error] = sinx_approx(x)
%   approximates the value of sin(x), the approximation is more accurate as
%   the number of terms selected is increased. 

n= input('Up to how many terms would you like to evaluate?');

sinx=0;
for i=1:1:n
    sinx=(-1)^(i+1) * x.^(2*i-1)/ factorial(2*i-1)+ sinx;
    error=((sin(x)-sinx)/sin(x))*100;
    display(sinx);
    display(error);
end    



end

%%Factorial is a built in command

solved Writing a function that calculates sine for inputted number of terms. MATLAB [closed]