Unrecognized function or variable 'x'.
조회 수: 31 (최근 30일)
이전 댓글 표시
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'.
댓글 수: 10
Juan David
2024년 4월 6일
이동: Voss
2024년 4월 6일
% Función para calcular el valor de Lagrange
function y = lagrange2(X, Y)
n=length(X);
sym x;
for i=1:n
w=1;
for j=1:n
if j~=1
w = w * (x - X(j)) / (X(i) - X(j));
end
end
end
y = 0;
for i=1:n
y = y + w(i) * Y(i);
end
y=simplify(expand(ecuacion));
end
RUN then
Unrecognized function or variable 'x'.
Error in lagrange2 (line 10)
w = w * (x - X(j)) / (X(i) - X(j));
채택된 답변
Adam Danz
2020년 4월 13일
편집: Adam Danz
2020년 4월 13일
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'.
댓글 수: 2
Adam Danz
2021년 7월 29일
@Dylan Radey I don't know what that means. All variables are defined either directly by the user or from computations within the function/script.
추가 답변 (3개)
Yuyang Mao
2021년 8월 5일
I got the same problem before.
Explaination: Please make sure that you have add your function to the path!
solution:
- Click run, it jumps out a window
- click 'add to path', is shows error in red color which is fine
- now give the name of your function again, in your case is 'Tsin(x,n)'
And this should work.
Best,
Yuyang
댓글 수: 2
Adam Danz
2021년 8월 9일
Good advice. However, in this question, the function name is Tsin but the unrecognized variable name is x.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!