I should calculate each "hiz" values with for loop. If i accept the starting value as "hiz":
hiz(inclined_road(1))=15;
the code can not work.
Error using fzero (line 306)FZERO cannot continue because user-supplied function_handle ==>@(hiz) (1/2)*1750*hiz(inclined_road (h-1))^2-total_loss(hiz)-(1/2)*1750*hiz.^2;failed with the error below. Index exceeds matrix dimensions.
I don't understand where the wrong is.
dgs=[1 204 332 396 428 499 578 630 661]; for z=2:1:numel(dgs); if (ele(dgs(z))-ele(dgs(z-1)))<0; inclined_road=dgs(z-1):1:dgs(z); for h=2:1:numel(inclined_road); WR= 0.015.*(1+hiz(inclined_road(h-1))^2/1500)*1750*9.81*cos(slope(inclined_road(h-1))); WS(h-1)=1750*9.81*sin(slope(inclined_road(h-1))); WB(h-1)=0; WL=@(hiz) (1/2)*0.99.*((0.5)*(hiz+hiz(inclined_road(h-1))))^2; total= @(hiz) WR(h-1)+WL(hiz)+WS(h-1); total_loss= @(hiz) total(hiz)*5; hiz_fun=@(hiz) (1/2)*1750*hiz(inclined_road (h-1))^2-total_loss(hiz)-(1/2)*1750*hiz.^2; x1 = [-100 100]; for k1 = 1:numel(x1); hiz_along_route(h,k1) = fzero(hiz_fun, x1(k1)); hiz_along_route(h,2)=hiz(inclined_road(h)); end end end end
I am waiting your helps,
Thx
Best Answer