Undefined function or variable

1 Ansicht (letzte 30 Tage)
Batuhan Karaoglu
Batuhan Karaoglu am 30 Apr. 2019
Kommentiert: Walter Roberson am 30 Apr. 2019
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 Kommentare
Batuhan Karaoglu
Batuhan Karaoglu am 30 Apr. 2019
>> j
Undefined function or variable 'a'.
Error in j (line 8)
fda = diff(e,a);
>>
Walter Roberson
Walter Roberson am 30 Apr. 2019
You cannot apply diff() to a function handle unless the second parameter (such as a) is a symbolic variable

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 30 Apr. 2019
Bearbeitet: Rik am 30 Apr. 2019
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.

Community Treasure Hunt

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

Start Hunting!

Translated by