This is a Matlab code which illustrates some of the Matlab capabilities of solving a multivariable (unconstraint) optimization problem (Example 2.1 of Meerschaert's book).
It is generally recommended to clear all previously defined variables from the workspace.
clear all; clf; syms x1 x2
y = (339-.01*x1-.003*x2)*x1+(399-.004*x1-.01*x2)*x2-(400000+195*x1+225*x2); ezsurf(y,[0 10000 0 10000]);
Matlab takes partial derivatives as follows
dydx1 = diff(y,x1); dydx2 = diff(y,x2);
This is done by solving the system of equations dydx1=0 and dydx2=0.
[x1max, x2max] = solve(dydx1,dydx2); x1max = double(x1max); x2max = double(x2max);
ymax=subs(y,[x1,x2],[x1max,x2max]);
Sensitivity Analysis for the ColorTV Problem (p. 26).
syms a
y = (339-a*x1-.003*x2)*x1+(399-.004*x1-.01*x2)*x2-(400000+195*x1+225*x2);
dydx1 = diff(y,x1);
dydx2 = diff(y,x2);
[x1maxa,x2maxa] = solve(dydx1,dydx2)
x1maxa = 1662000/(-49+40000*a) x2maxa = 48000*(-21+7250*a)/(-49+40000*a)
The following syntax allows for making subplots
figure, subplot(2,1,1); ezplot(x1maxa,[0.005,0.015]); subplot(2,1,2); ezplot(x2maxa,[0.005,0.015]);
This is the sensitivity of x1maxa to variations of a around the value a=0.01
dx1da=diff(x1maxa,a); Sx1a=dx1da*a/x1maxa; S=subs(Sx1a,a,0.01)
S = -1.1396
This is the sensitivity of x2maxa to variations of a around the value a=0.01
dx2da=diff(x2maxa,a); Sx2a=dx2da*a/x2maxa; S=subs(Sx2a,a,0.01)
S = 0.2682