Info

This question is closed. Reopen it to edit or answer.

How to display parts of a Function Value in an Optimization Problem

2 views (last 30 days)
Hello,
Below I have two files. The first is a function file and the second is the Optimization file. I am trying to display individual parts that are in my function file (MaxFunctionProblem.m) to make sure that the function value is correct. For instance I would like to see the actual value for Q that matlab computed for the end function value in the Optimization file (MaxFunExe.m). I am unable to display it on the MaxFunctionProblem.m file because of the unknowns in the file before the MaxFunExe.m is run. Could anyone kindly help me with this please?
Thanks,
Kam
First file (MaxFunctionFile)
function E = MaxFunctionProblem(x)
P = x(1);
W = x(2);
U = x(3);
Wprime = x(4);
Uprime = x(5);
% Function Formulations
% Multiobjective function
D1 = 0.2;
a = 2;
b = 0.2;
d = 0.1;
e = 2;
k = 1;
P1 = 1;
P2 = 6;
W1 = 1;
W2 = 5;
U1 = 1;
U2 = 6;
W3 = 10;
% N = 2
L = 10;
% W = 2
% P = 5
a2 = 0.01;
b2 = 0.005;
i = 1;
g = 0.1;
t = 0;
r = mvnrnd (0,6);
Theta0 = .005;
Theta1 = .01;
Theta2 = .01;
Theta3 = .02;
% U = 1
%y1 = U/W;
%Xr = U/r;
Inf = 50;
% Uprime = 1
% Expected Unit Profit
% Unknown variables: P,W,U, Uprime, Unit Price
% P = unit price
% v = unit premium
Pprime = 0.2;
v = (0.1*Pprime);
% Expected Unit Production Costs
Ltr = Theta0+(Theta1*r)+(Theta2+(Theta3*r))*t;
FuncEct = @(t,L)(a2 + (b2/(Ltr^i)))*(1-(g*(t)));
ECTf = integral(FuncEct,t,L);
% ECTf = @ExpUnitProdCost;
%%%%%%Expected Unit Profit %%%%%%
% q = integral(fun,xmin,xmax) example
% q = integral(fun,xmin,xmax,Name,Value)
%FuncEct = @(t,L)(a2 + (b1/(Ltr^i)))*(1-(g*t));
%ExpUnitProdCostX = integral(ECTf,t,L);
Lfun = @(t,r)Theta0+(Theta1*r)+((Theta2+(Theta3*r)).*t);
L1 = integral2(Lfun,t,W,r,(U/W));
L2 = integral2(Lfun,t,(U/r),(U/W),Inf);
Cs = 0.05*P;
ExpUnitWarCost = Cs*(L1 + L2);
ExpUnitProfit = (P + v) - ECTf - ExpUnitWarCost;
%%%%%%Expected increase in market share %%%%%%
Pprime = .2;
D = D1/((P1^(-a))*((W2 + k)^b)*U2^d);
Q = (D*(P^(-a))*((W + k)^b)*(U^d));
Qprime = (D*(P^(-a))*((Wprime + k)^b)*(((Uprime)^d)*((1 + v)^(-e))));
ExpIncMarketShare = (Pprime*Qprime) + ((1 - Pprime))*Q - Q;
%%%%%%Unit Price %%%%%
UnitPrice = P;
%%%%%%Market share without extension of warranty %%%%%%
MarShareWOExtWar = Q;
E = -(ExpUnitProfit*ExpIncMarketShare)/(UnitPrice*MarShareWOExtWar);
Second File (MaxFunExe.m)
x0 = [3,2,4,8,10];
options = optimset('Algorithm','active-set');
[x,fval] = fmincon(@MaxFunctionProblem,x0,[],[],[],[],[],[],@confun,options);
display(fval)

Answers (1)

Matt J
Matt J on 3 Oct 2012
Edited: Matt J on 3 Oct 2012
Use the 'OutputFcn' option
Essentially, you will want to nest both MaxFunctionProblem and your output function inside MaxFunExe. Then initialize a Q=[] variable in the workspace of MaxFunExe. Once you do this, Q will be an externally scoped variable and all 3 functions will share access to Q.

This question is closed.

Community Treasure Hunt

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

Start Hunting!