I am trying to solve the max of the following nonlinear function:
F = (((.8*buyp*1.1+.2*buyp*.95)-buyp)*265000*7.33)/(1+0.00027397)^(distla+distab/(24*v(1)))-(fixc*(distla+distab/(24*v(1)))+ExogParams.HFO*tpd*((v(1)/v_des)^3)*(distla+distab/(24*v(1)))+ fixc*(distab/(24*v(2)))+645*tpd*((v(2)/v_des)^3)*(distab/(24*v(2)))));
I need to pass in the parameters: buyp,fixc,v_des, distla, distab,tpd to the function each time using FMINCON to solve. So for example, the function could look like:
F = ((( 0.8*100*1.1+0.2*100*.95-100)*265000*7.33)/(1+0.00027397)^(22706/(24*v1)) -(23400*(22706/(24*v1))+ ... 645*83*((v1/15.8)^3)*(22706/(24*v1))+ 23400*(11353/(24*v2))+ ... 645*83*((v2/15.8)^3)*(11353/(24*v2))));
My implementation of the general function F returns incorrect values and I can't figure out why (been staring at this for hours now). Call the first M file objspeedfun1.m:
function F = objspeedfun1(v, buyp,fixc,v_des, distla, distab,tpd) F = (((.8*buyp*1.1+.2*buyp*.95)-... buyp)*265000*7.33)/(1+0.00027397)^(distla+distab/(24*v(1)))-(fixc*(distla+distab/(24*v(1)))+ExogParams.HFO*tpd*((v(1)/v_des)^3)*(distla+distab/(24*v(1)))+ fixc*(distab/(24*v(2)))+645*tpd*((v(2)/v_des)^3)*(distab/(24*v(2))))); F=-F; %solves for max instead of min
The second M file calls F:
function [v1, v2, fval] = solveOptimalSpeed1(buyp, fixc,v_des, distla, distab,tpd)%@brief: maximizes objective function objspeedfun1 given parameters
%> v_laden is optimal laden speed
%> v_ballast is optimal ballast speed
%> fval is the value you get from maximisation problem with optimal speed
%params
f = @(v)objspeedfun1(v,buyp, fixc,v_des, distla, distab,tpd); %Assign parameter values
options = optimset('Algorithm','active-set');x0 = [13.5; 8]; %Make a starting guess at the solution
lb = [8 8];ub = [15.8 15.8];[x,fval] = fmincon(f,x0,[],[],[],[],lb,ub,[],options); %Call solver
v1 = x(1);v2 = x(2);
When I call the function solveOptimalSpeed1, I get the following result:
v1=8v2=9.5171fval=3.4749e+08
which is incorrect. Using trial and error, the solution should be around (or of magnitude) 7966644.13, using the example above.
Your help is really appreciated.
Best Answer