The value that makes the derivative zero
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
fert
am 17 Jan. 2016
Bearbeitet: John D'Errico
am 17 Jan. 2016
Consider the function:
f(x) = x^2* e^(-x)
.
I want to find the point that makes the derivative of this function zero. My code is:
syms x
f=(x.^2).*exp(-x);
k=diff(f);
a = @(x) k;
b=fzero(a,0,1000)
I am getting this error:
"Function value at starting guess must be finite and real."
What do you think it is wrong?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 17 Jan. 2016
Bearbeitet: John D'Errico
am 17 Jan. 2016
Why not see what MATLAB thinks you are giving it? When you get an error, think about what it is telling you. Then use MATLAB to see what your code does. GET YOUR HANDS DIRTY.
a(0)
ans =
2*x*exp(-x) - x^2*exp(-x)
See that when you created the function handle a, you never told MATLAB that k was actually a function of x. You might have tried this instead:
a = @(x) double(subs(k,x));
a(0)
ans =
0
So now MATLAB can evaluate a as a function of x.
fzero(a,[1,10])
ans =
2
fzero(a,.5)
ans =
7.844e-23
It seems to work now. Of course, simpler was just:
solve(k==0)
ans =
0
2
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!