MATH 448/548 - Example 2.1. The Color TV (p.21-32)

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).

Contents

Introduce the symbolic (independent) variables

It is generally recommended to clear all previously defined variables from the workspace.

clear all; clf;
syms x1 x2

Define and plot in 3d the function (dependent variable)

y = (339-.01*x1-.003*x2)*x1+(399-.004*x1-.01*x2)*x2-(400000+195*x1+225*x2);
ezsurf(y,[0 10000 0 10000]);

Differentiate symbolic expressions

Matlab takes partial derivatives as follows

dydx1 = diff(y,x1);
dydx2 = diff(y,x2);

Find the critical points of y=y(x),

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);

Compute the numerical value ymax=y(x1max,x2max)

ymax=subs(y,[x1,x2],[x1max,x2max]);

Sensitivity analysis

Sensitivity Analysis for the ColorTV Problem (p. 26).

Introduce variable price elasticity *a* and compute the critical point(s)

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)
 
 

Plot of the optimal quatities (x1maxa and x2maxa) vs 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]);

Evaluate sensitivity of x1 to a

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

Evaluate sensitivity of x2 to a

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