Is there a mistake on my code which determines value that minimizes the function?

I have been creating a minimal code located at the code-box for minimize the function, but i'm not sure working of code is correctly. Is there any wrong?
Thx.
clear all
clc
slo=[0.01 0.012 0.013 0.012 0.008 0];
for i=1:1:numel(slo);
WR(i)=0.01*9.81*1700*cos(i);
WL=@(velo) 0.5*0.25*1.2*2.65.*velo^2;
WS(i)=9.81*1700*sin(i);
WB=0;
end
WT=@(velo) sum(WR)+WL(velo)+sum(WS)+WB;
fun = @(velo) WT(velo);
x1 = 50/3.6;
x2 = 90/3.6;
options = optimset('Display','iter');
velo = (fminbnd(fun,x1,x2,options))*3.6 %km/h

 채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 26일
You could give a smaller tolerance in your options if you wanted to get a more accurate result.
Or you could just skip the fminbnd and use x1 as location where the minimum occurs.
Your function calculates a quadratic function with its minima at 0, so the bound closest to 0 is always going to be the point of the constrained minima.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by