Map3D=load('Map3D');Map3D=Map3D.Map3D;
Speed = 0:10:60;
Power = 5:10:205;
Altitude = [0 300 600 700];
[S,P,A]=ndgrid(Speed,Power,Altitude);
L_speed_nonzero=S~=0;
[P,S,A,Map3D]=deal(P(L_speed_nonzero),S(L_speed_nonzero),...
A(L_speed_nonzero),Map3D(L_speed_nonzero));
b_initial_guess=[-10 0.1 -200 -0.05 50 40];
OLS=@(b,x,y,z,v) sum((MyFun(b,x,y,z) - v).^2);
opts = optimset('MaxFunEvals',50000, 'MaxIter',10000);
b_fitted=fminsearch(OLS, b_initial_guess(:), opts,S(:),P(:),A(:),Map3D(:));
clc
fprintf('b_fitted=[')
fprintf('%.4e ',b_fitted)
fprintf('];\n')
b_fitted=[1.6348e+02 1.0524e-05 -3.2690e-03 6.0934e-08 -1.8714e-04 5.3567e-01 ];
Speed = 0:10:60;
Power = 5:10:205;
Altitude = [0 300 600 700];
[S,P,A]=ndgrid(Speed,Power,Altitude);
predicted_value=MyFun(b_fitted,S,P,A);
real_value=load('Map3D');real_value=real_value.Map3D;
delta=predicted_value-real_value;
delta(i
sinf(delta))=[];
fprintf(['difference between non-inf fitted values and true values ',...
'is:\nmean= %.2e\nabs max= %.2e\n\n'],mean(delta),max(abs(delta)))
function val=MyFun(b,Power,Speed,Altitude)
val = Power.^-b(1) ...
+b(2)*Speed.^2 ...
+b(3).*Speed ...
+b(4)*Altitude.^2 ...
+b(5)*Altitude ...
+b(6);
end
Best Answer