Unrecognized function or variable 'x'.

73 ビュー (過去 30 日間)
Emre Can Usengul
Emre Can Usengul 2020 年 4 月 13 日
コメント済み: Stephen23 2024 年 10 月 20 日
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
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));
Voss
Voss 2024 年 4 月 6 日

Instead of

sym x;

use

syms x;

or

x = sym('x');

サインインしてコメントする。

採用された回答

Adam Danz
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 件のコメント
Dylan Radey
Dylan Radey 2021 年 3 月 3 日
can't define a variable for fiding a root :\
Adam Danz
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
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
Adam Danz 2021 年 8 月 9 日
Good advice. However, in this question, the function name is Tsin but the unrecognized variable name is x.
Jordan Wood
Jordan Wood 2021 年 8 月 10 日
Need to reinput the values you want for x and n in the command window

サインインしてコメントする。


SUNIL KUMAR
SUNIL KUMAR 2024 年 10 月 20 日
syms x
solve('x+3=4',x)
Error using sym/solve>getEqns (line 418)
List of equations must not be empty.

Error in sym/solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});

SUNIL KUMAR
SUNIL KUMAR 2024 年 10 月 20 日
f=inline('x^2','x')
f = Inline function: f(x) = x^2
diff(f(x),x)
Unrecognized function or variable 'x'.
  1 件のコメント
Stephen23
Stephen23 2024 年 10 月 20 日
syms x
f = x^2
diff(f,x)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by