fmindnd problem doesnt run
Afficher commentaires plus anciens
I have this code in MATLAB, it doesnt run,what is the wrong?
g=9.81;zo=50;vo=15;m=50;c=13;
z=@(t) -(zo+m/c*(vo+m*g/c)*(1-exp(-c/m*t))-m*g/c*t);
[xmin fval]=fminbnd(z,0,8)
Réponses (2)
It runs here —
g=9.81;zo=50;vo=15;m=50;c=13;
z=@(t) -(zo+m/c*(vo+m*g/c)*(1-exp(-c/m*t))-m*g/c*t);
[xmin fval]=fminbnd(z,0,8)
Does it throw any errors?
The fminbnd functon is part of core MATLAB and was introduced before R2006a, so you should have it.
.
John D'Errico
le 18 Juin 2023
Modifié(e) : John D'Errico
le 18 Juin 2023
Never just say something does not run, and nothing more. Would you tell your doctor that something seems wrong, and hope they can diagnose your problem over the phone without saying anything more? Surely not.
If you got an error, then report the entire error, so EVERYTHING in red.
Does your code run? We can test it in Answers itself.
g=9.81;zo=50;vo=15;m=50;c=13;
z=@(t) -(zo+m/c*(vo+m*g/c)*(1-exp(-c/m*t))-m*g/c*t);
format long g
[xmin fval]=fminbnd(z,0,8)
I'll add a few more lines to see what it found.
fplot(z,[0,8],'b')
hold on
plot(xmin,fval,'ro')
So indeed, it does run, and appears to have found the minimum of that function. How well did it do?
syms T
Z = z(T)
If it has a (local) minimum, then you can differentiate it, and solve for a solution.
tmin = solve(diff(Z,T,1) == 0,'returnconditions',true)
So there are infinitely many solutions, but all of them are complex, except for the one where k==0.
subs(tmin.T,'k',0)
tmin = double(ans)
To within the tolerances provided to fminbnd, AND the capabilities of floating point arithmetic in double precision, fminbnd found a reasonable solution.
Catégories
En savoir plus sur Signal Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


