Variable not recognized after program restart
2 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
madhan ravi
on 6 Jan 2019
Edited: madhan ravi
on 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 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!