How to plot non-quadratic functions?
4 views (last 30 days)
Show older comments
Hi everyone,
I have 3 non-quadratic/nonlinear profit functions (see below) in terms of 3 parameters which are alfa, F and delta.
To find for which alfa and F values which profit function is optimum, I need to compare these 3 profit functions and draw a plot based on alfa (x-axis) and F (y-axis) also alfa=F=[0, 1].
Manually I know how to solve it by I couldn't find a way to code it in Matlab.
I would appreciate if anyone can help me. Many thanks in advance!
totalprofit1=(8*F*(delta^3 - 3*delta^2 + 4*delta - 2))/((delta - 2)^2*(8*F*delta - 8*alfa - 4*delta - 12*F + 8*alfa*delta - 2*alfa*delta^2 - 4*alfa^2*delta + 4*alfa^2 + delta^2 + alfa^2*delta^2 + 4))
totalprofit2 =((delta - 1)^2*(- alfa^2 + 2*alfa + 4*F - 1)*(alfa^2 - 2*alfa - 4*F + 2*F*delta + 1)^2)/(4*(- 32*F^3*delta^3 + 112*F^3*delta^2 - 128*F^3*delta + 48*F^3 + 8*F^2*alfa^2*delta^3 - 56*F^2*alfa^2*delta^2 + 88*F^2*alfa^2*delta - 40*F^2*alfa^2 + 8*F^2*alfa*delta^4 - 40*F^2*alfa*delta^3 + 136*F^2*alfa*delta^2 - 184*F^2*alfa*delta + 80*F^2*alfa - 8*F^2*delta^4 + 32*F^2*delta^3 - 80*F^2*delta^2 + 96*F^2*delta - 40*F^2 + 6*F*alfa^4*delta^2 - 18*F*alfa^4*delta + 11*F*alfa^4 - 2*F*alfa^3*delta^4 + 12*F*alfa^3*delta^3 - 40*F*alfa^3*delta^2 + 78*F*alfa^3*delta - 44*F*alfa^3 + 5*F*alfa^2*delta^4 - 34*F*alfa^2*delta^3 + 83*F*alfa^2*delta^2 - 126*F*alfa^2*delta + 66*F*alfa^2 - 4*F*alfa*delta^4 + 32*F*alfa*delta^3 - 70*F*alfa*delta^2 + 90*F*alfa*delta - 44*F*alfa + F*delta^4 - 10*F*delta^3 + 21*F*delta^2 - 24*F*delta + 11*F + alfa^6*delta - alfa^6 - alfa^5*delta^3 + 2*alfa^5*delta^2 - 7*alfa^5*delta + 6*alfa^5 + 5*alfa^4*delta^3 - 10*alfa^4*delta^2 + 20*alfa^4*delta - 15*alfa^4 - 10*alfa^3*delta^3 + 20*alfa^3*delta^2 - 30*alfa^3*delta + 20*alfa^3 + 10*alfa^2*delta^3 - 20*alfa^2*delta^2 + 25*alfa^2*delta - 15*alfa^2 - 5*alfa*delta^3 + 10*alfa*delta^2 - 11*alfa*delta + 6*alfa + delta^3 - 2*delta^2 + 2*delta - 1))
totalprofit3 =-((delta - 2)^2*(2*F^2*delta^5 - 19*F^2*delta^4 + 72*F^2*delta^3 - 136*F^2*delta^2 + 128*F^2*delta - 48*F^2 + F*alfa^2*delta^4 - 10*F*alfa^2*delta^3 + 35*F*alfa^2*delta^2 - 52*F*alfa^2*delta + 28*F*alfa^2 - 2*F*alfa*delta^4 + 20*F*alfa*delta^3 - 70*F*alfa*delta^2 + 104*F*alfa*delta - 56*F*alfa + F*delta^4 - 14*F*delta^3 + 57*F*delta^2 - 92*F*delta + 52*F - alfa^4*delta^2 + 4*alfa^4*delta - 4*alfa^4 + 4*alfa^3*delta^2 - 16*alfa^3*delta + 16*alfa^3 - 6*alfa^2*delta^2 + 28*alfa^2*delta - 30*alfa^2 + 4*alfa*delta^2 - 24*alfa*delta + 28*alfa - delta^2 + 10*delta - 13))/(4*(20*F*delta - 8*alfa - 6*delta - 12*F + 8*alfa*delta - 11*F*delta^2 + 2*F*delta^3 - 2*alfa*delta^2 - 4*alfa^2*delta + 4*alfa^2 + delta^2 + alfa^2*delta^2 + 7)^2)
0 Comments
Accepted Answer
Torsten
on 30 Jan 2023
Edited: Torsten
on 30 Jan 2023
I suggest you evaluate the three profit functions for a rectangular region [alpha_min,alpha_max] x [ F_min,F_max] and introduce a third variable profit_max that is 1 if the first profit function is maximum, 2 if the second profit function is maximum and 3 if the third profit function is maximum. Then use "contourf" to plot z in the region [alpha_min,alpha_max] x [ F_min,F_max].
delta = 1;
totalprofit1=@(F,alfa)(8*F*(delta^3 - 3*delta^2 + 4*delta - 2))/((delta - 2)^2*(8*F*delta - 8*alfa - 4*delta - 12*F + 8*alfa*delta - 2*alfa*delta^2 - 4*alfa^2*delta + 4*alfa^2 + delta^2 + alfa^2*delta^2 + 4));
totalprofit2 =@(F,alfa)((delta - 1)^2*(- alfa^2 + 2*alfa + 4*F - 1)*(alfa^2 - 2*alfa - 4*F + 2*F*delta + 1)^2)/(4*(- 32*F^3*delta^3 + 112*F^3*delta^2 - 128*F^3*delta + 48*F^3 + 8*F^2*alfa^2*delta^3 - 56*F^2*alfa^2*delta^2 + 88*F^2*alfa^2*delta - 40*F^2*alfa^2 + 8*F^2*alfa*delta^4 - 40*F^2*alfa*delta^3 + 136*F^2*alfa*delta^2 - 184*F^2*alfa*delta + 80*F^2*alfa - 8*F^2*delta^4 + 32*F^2*delta^3 - 80*F^2*delta^2 + 96*F^2*delta - 40*F^2 + 6*F*alfa^4*delta^2 - 18*F*alfa^4*delta + 11*F*alfa^4 - 2*F*alfa^3*delta^4 + 12*F*alfa^3*delta^3 - 40*F*alfa^3*delta^2 + 78*F*alfa^3*delta - 44*F*alfa^3 + 5*F*alfa^2*delta^4 - 34*F*alfa^2*delta^3 + 83*F*alfa^2*delta^2 - 126*F*alfa^2*delta + 66*F*alfa^2 - 4*F*alfa*delta^4 + 32*F*alfa*delta^3 - 70*F*alfa*delta^2 + 90*F*alfa*delta - 44*F*alfa + F*delta^4 - 10*F*delta^3 + 21*F*delta^2 - 24*F*delta + 11*F + alfa^6*delta - alfa^6 - alfa^5*delta^3 + 2*alfa^5*delta^2 - 7*alfa^5*delta + 6*alfa^5 + 5*alfa^4*delta^3 - 10*alfa^4*delta^2 + 20*alfa^4*delta - 15*alfa^4 - 10*alfa^3*delta^3 + 20*alfa^3*delta^2 - 30*alfa^3*delta + 20*alfa^3 + 10*alfa^2*delta^3 - 20*alfa^2*delta^2 + 25*alfa^2*delta - 15*alfa^2 - 5*alfa*delta^3 + 10*alfa*delta^2 - 11*alfa*delta + 6*alfa + delta^3 - 2*delta^2 + 2*delta - 1));
totalprofit3 =@(F,alfa)-((delta - 2)^2*(2*F^2*delta^5 - 19*F^2*delta^4 + 72*F^2*delta^3 - 136*F^2*delta^2 + 128*F^2*delta - 48*F^2 + F*alfa^2*delta^4 - 10*F*alfa^2*delta^3 + 35*F*alfa^2*delta^2 - 52*F*alfa^2*delta + 28*F*alfa^2 - 2*F*alfa*delta^4 + 20*F*alfa*delta^3 - 70*F*alfa*delta^2 + 104*F*alfa*delta - 56*F*alfa + F*delta^4 - 14*F*delta^3 + 57*F*delta^2 - 92*F*delta + 52*F - alfa^4*delta^2 + 4*alfa^4*delta - 4*alfa^4 + 4*alfa^3*delta^2 - 16*alfa^3*delta + 16*alfa^3 - 6*alfa^2*delta^2 + 28*alfa^2*delta - 30*alfa^2 + 4*alfa*delta^2 - 24*alfa*delta + 28*alfa - delta^2 + 10*delta - 13))/(4*(20*F*delta - 8*alfa - 6*delta - 12*F + 8*alfa*delta - 11*F*delta^2 + 2*F*delta^3 - 2*alfa*delta^2 - 4*alfa^2*delta + 4*alfa^2 + delta^2 + alfa^2*delta^2 + 7)^2);
n = 100;
alfa = linspace(0,1,n);
F = linspace(0,1,n);
[F,alfa] = meshgrid(F,alfa);
for i=1:n
for j=1:n
f = F(i,j);
a = alfa(i,j);
z1 = totalprofit1(f,a);
z2 = totalprofit2(f,a);
z3 = totalprofit3(f,a);
[~,index] = max([z1,z2,z3]);
profit_max(i,j) = index;
end
end
contourf(F,alfa,profit_max)
colorbar
4 Comments
Torsten
on 1 Feb 2023
Edited: Torsten
on 1 Feb 2023
Maybe you can even choose the color for a certain value of Fun. Ad hoc, I can't.
Don't forget to set N to the correct value.
delta=0.8;
N = 1;
totalprofit1=@(alfa,F)(8*F*(delta^3 - 3*delta^2 + 4*delta - 2))/((delta - 2)^2*(8*F*delta - 8*alfa - 4*delta - 12*F + 8*alfa*delta - 2*alfa*delta^2 - 4*alfa^2*delta + 4*alfa^2 + delta^2 + alfa^2*delta^2 + 4));
totalprofit2 =@(alfa,F)((delta - 1)^2*(- alfa^2 + 2*alfa + 4*F - 1)*(alfa^2 - 2*alfa - 4*F + 2*F*delta + 1)^2)/(4*(- 32*F^3*delta^3 + 112*F^3*delta^2 - 128*F^3*delta + 48*F^3 + 8*F^2*alfa^2*delta^3 - 56*F^2*alfa^2*delta^2 + 88*F^2*alfa^2*delta - 40*F^2*alfa^2 + 8*F^2*alfa*delta^4 - 40*F^2*alfa*delta^3 + 136*F^2*alfa*delta^2 - 184*F^2*alfa*delta + 80*F^2*alfa - 8*F^2*delta^4 + 32*F^2*delta^3 - 80*F^2*delta^2 + 96*F^2*delta - 40*F^2 + 6*F*alfa^4*delta^2 - 18*F*alfa^4*delta + 11*F*alfa^4 - 2*F*alfa^3*delta^4 + 12*F*alfa^3*delta^3 - 40*F*alfa^3*delta^2 + 78*F*alfa^3*delta - 44*F*alfa^3 + 5*F*alfa^2*delta^4 - 34*F*alfa^2*delta^3 + 83*F*alfa^2*delta^2 - 126*F*alfa^2*delta + 66*F*alfa^2 - 4*F*alfa*delta^4 + 32*F*alfa*delta^3 - 70*F*alfa*delta^2 + 90*F*alfa*delta - 44*F*alfa + F*delta^4 - 10*F*delta^3 + 21*F*delta^2 - 24*F*delta + 11*F + alfa^6*delta - alfa^6 - alfa^5*delta^3 + 2*alfa^5*delta^2 - 7*alfa^5*delta + 6*alfa^5 + 5*alfa^4*delta^3 - 10*alfa^4*delta^2 + 20*alfa^4*delta - 15*alfa^4 - 10*alfa^3*delta^3 + 20*alfa^3*delta^2 - 30*alfa^3*delta + 20*alfa^3 + 10*alfa^2*delta^3 - 20*alfa^2*delta^2 + 25*alfa^2*delta - 15*alfa^2 - 5*alfa*delta^3 + 10*alfa*delta^2 - 11*alfa*delta + 6*alfa + delta^3 - 2*delta^2 + 2*delta - 1));
totalprofit3 =@(alfa,F)-((delta - 2)^2*(2*F^2*delta^5 - 19*F^2*delta^4 + 72*F^2*delta^3 - 136*F^2*delta^2 + 128*F^2*delta - 48*F^2 + F*alfa^2*delta^4 - 10*F*alfa^2*delta^3 + 35*F*alfa^2*delta^2 - 52*F*alfa^2*delta + 28*F*alfa^2 - 2*F*alfa*delta^4 + 20*F*alfa*delta^3 - 70*F*alfa*delta^2 + 104*F*alfa*delta - 56*F*alfa + F*delta^4 - 14*F*delta^3 + 57*F*delta^2 - 92*F*delta + 52*F - alfa^4*delta^2 + 4*alfa^4*delta - 4*alfa^4 + 4*alfa^3*delta^2 - 16*alfa^3*delta + 16*alfa^3 - 6*alfa^2*delta^2 + 28*alfa^2*delta - 30*alfa^2 + 4*alfa*delta^2 - 24*alfa*delta + 28*alfa - delta^2 + 10*delta - 13))/(4*(20*F*delta - 8*alfa - 6*delta - 12*F + 8*alfa*delta - 11*F*delta^2 + 2*F*delta^3 - 2*alfa*delta^2 - 4*alfa^2*delta + 4*alfa^2 + delta^2 + alfa^2*delta^2 + 7)^2);
alfa = 0:0.005:1;
f = 0:0.005:1;
for i = 1:numel(alfa)
Alfa = alfa(i);
for j = 1:numel(f)
F = f(j);
t1 = totalprofit1(Alfa,F);
t2 = totalprofit2(Alfa,F);
t3 = totalprofit3(Alfa,F);
[tmax,idx] = max([t1,t2,t3]);
if idx==1
if - (Alfa - 1)^2 - (2*F*(4*delta - 6))/(delta - 2)^2>0 &((Alfa - 1)*(2*N - 4*delta - 4*Alfa*delta + 6))/(delta + Alfa*delta - 2)^2<0 & - (Alfa - 1)^2 - (2*F*(Alfa - 1)*(2*Alfa - 4*delta - 4*Alfa*delta + 6))/(delta + Alfa*delta - 2)^2 >0
Fun(i,j) = 1;
else
Fun(i,j) = 2;
end
end
if idx==2
if 4*F>(1-Alfa)^2 & delta <(0.5*(4.0*F + Alfa - 1.0*(16.0*F^2 - 8.0*F*Alfa + 8.0*F + 4.0*Alfa^3 - 11.0*Alfa^2 + 10.0*Alfa - 3.0)^(1/2) - 1.0))/(Alfa - 1.0) & delta< (1.0*(F*Alfa - 2.0*Alfa - 4.0*F + Alfa^2 + 1.0))/(2.0*F*Alfa - 2.0*Alfa - 4.0*F + Alfa^2 + 1.0)
Fun(i,j) = 3;
else
Fun(i,j) = 4;
end
end
if idx==3
if -(4*(Alfa^2 - 2*Alfa - 3*F + 2*F*delta + 1))/(delta - 2)^2>0 & Alfa <1 & (3*F+F*Alfa-2*F*delta+Alfa*delta^2-delta^2-2*F*Alfa*delta)>0
Fun(i,j) = 5;
else
Fun(i,j) = 6;
end
end
end
end
colormap(jet(6))
contourf(alfa,f,Fun)
colorbar('Ticks',1:6,'TickLabels',["1" "2" "3" "4" "5" "6" " "]);
More Answers (1)
Alan Weiss
on 30 Jan 2023
This sounds like a multiobjective optimization problem. See Generate and Plot Pareto Front and, if you have Global Optimization Toolbox, Multiobjective Optimization.
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
Alan Weiss
on 30 Jan 2023
I do not understand your problem. You say that you have three objective functions. But you say that you do not have a multiobjective problem. So what are you trying to do? I do not understand what "compare these 3 scenarios based on parameters, alfa and F" means.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Categories
Find more on Multiobjective Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!