MATLAB: Unrecognized function or variable ‘x’.

MATLABunrecognized function or variable 'x'.

function y = Tsin(x,n)
x=input('Degrees: ');
y=input('Terms: ');
%Tsin calculates the sin using Taylor formula.
%Input arguments:
%x The angle in degrees, n number of terms.
z=x*pi/180;
y=0;
for k=0:n-1
y=y+(-1)^k*z^(2*k+1)/factorial(2*k+1);
end
RUN then
>> Tsin(x, n)
Unrecognized function or variable 'x'.

Best Answer

You need to define the input variables. You cannot simply run a function that has undefined input variables.
x = 45
n = 8
Tsin(x,n)
____________________________________
Copy of question:
function y = Tsin(x,n)
x=input('Degrees: ');
y=input('Terms: ');
%Tsin calculates the sin using Taylor formula.
%Input arguments:
%x The angle in degrees, n number of terms.
z=x*pi/180;
y=0;
for k=0:n-1
y=y+(-1)^k*z^(2*k+1)/factorial(2*k+1);
end
RUN then
>> Tsin(x, n)
Unrecognized function or variable 'x'.