Variable not recognized after program restart

2 vues (au cours des 30 derniers jours)
Fjolfrin
Fjolfrin le 6 Jan 2019
Commenté : madhan ravi le 6 Jan 2019
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?

Réponse acceptée

madhan ravi
madhan ravi le 6 Jan 2019
Modifié(e) : madhan ravi le 6 Jan 2019
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 commentaires
Fjolfrin
Fjolfrin le 6 Jan 2019
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 le 6 Jan 2019
Anytime :) ,
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by