Variable not recognized after program restart

2 ビュー (過去 30 日間)
Fjolfrin
Fjolfrin 2019 年 1 月 6 日
コメント済み: madhan ravi 2019 年 1 月 6 日
So I've been writing some code for a university project, and while I was doing the exact same thing every time I opened my project (open it and when i tried to run it, i added it to the default matlab path). for some reason I get this error:
Undefined function or variable 'x'.
Error in Ex1 (line 4)
df = matlabFunction( diff(f, x) );
My code is this on the first lines:
%Setting of initial functions and variables. Plotting of our function.
h = 10^-6;
f = @(x) 14*x.*exp(x-2) - 12*exp(x-2) - 7*x.^3 + 20*x.^2 - 26*x + 12;
df = matlabFunction( diff(f, x) );
ddf = matlabFunction( diff(df, x) );
...
I believe the code is correct. Besides I have run the code multiple times without a problem!
Do you have any ideas?

採用された回答

madhan ravi
madhan ravi 2019 年 1 月 6 日
編集済み: madhan ravi 2019 年 1 月 6 日
diff recognises symbolic x but not as a function handle
syms x
h = 10^-6;
f = 14*x.*exp(x-2) - 12*exp(x-2) - 7*x.^3 + 20*x.^2 - 26*x + 12;
df = matlabFunction( diff(f, x) );
ddf = matlabFunction( diff(df, x) );
  8 件のコメント
Fjolfrin
Fjolfrin 2019 年 1 月 6 日
It does work!
I have some rutnrime problems down the line with some of my functions, but that is another problem, I must have an infinite loop somewhere.
Thanks a lot!
BTW I just realised I've been reading your comments on many occations while I was browsing for various answers for problems I had. Additional thanks for those tips! Keep up!
madhan ravi
madhan ravi 2019 年 1 月 6 日
Anytime :) ,
Thank you

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by