Undefined function or variable

2 ビュー (過去 30 日間)
Batuhan Karaoglu
Batuhan Karaoglu 2019 年 4 月 30 日
コメント済み: Walter Roberson 2019 年 4 月 30 日
function j()
syms x
syms y
f = @(x)((a*x^3)+(b*x^2)+(c*x)+d);
e = @(x,y)(abs(f(x)-y)^2);
fda = diff(e,a);
fdb = diff(e,b);
fdc = diff(e,c);
fdd = diff(e,d);
n=input('Enter the number of points you want to enter, more than 2');
m=imput;
for i=1:1:2
for j=1:1:n
m(i,j) = input;
end
end
  2 件のコメント
Batuhan Karaoglu
Batuhan Karaoglu 2019 年 4 月 30 日
>> j
Undefined function or variable 'a'.
Error in j (line 8)
fda = diff(e,a);
>>
Walter Roberson
Walter Roberson 2019 年 4 月 30 日
You cannot apply diff() to a function handle unless the second parameter (such as a) is a symbolic variable

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

回答 (1 件)

Rik
Rik 2019 年 4 月 30 日
編集済み: Rik 2019 年 4 月 30 日
You don't define a, so it doesn't exist. But that is far from the only issue with your code.
Also, why are you using j as a function? It is already used as the imaginary unit (even if you should use 1j instead of j), and it is often used as a loop variable.
You also forgot to explain what your function should do (either with explanatory text here, or in comments with your code) and you forgot to use the layout tools to make your question more readable.
After fixing the missing a, you should also have a look at your last block of code. The second line you're using the non-existant function imput, which I suspect is a typo and should be input instead. Then you proceed to use the function name as your loop iterator. Depending on your release this will either error, or cause unexpected behavior. Then you also proceed to overwrite the value entered by the user in m, as well as expanding it dynamically.
As the last point: your function doesn't return any outputs, so the calculations it does probably don't have any use, except keeping your computer busy.

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by