Sketch the Level curve of the following function. Can anyone help? How do I sketch the level curves of the following function?
$$f (x_1,x_2)= \ln(x_1 +x_2)+e^{x_1x_2} +x_2$$
.
Can anyone help?
 A: Some ideas... The level curves for big negative values of $f$ are dominated by the $\ln\left(x_1+x_2\right)$ term so they run almost parallel to and close to to line $x_1+x_2=0$. The level curves for big positive values of $f$ are dominated by the $e^{x_1x_2}$ term so they are near hyperbolas $x_1x_2=constant$.  
If you want to make a contour plot you may be better off working in a coordinate system
$$\begin{align}y_1&=\frac1{\sqrt2}\left(x_1+x_2\right)\\
y_2&=\frac1{\sqrt2}\left(-x_1+x_2\right)\end{align}$$
As in the original coordinate system $\ln\left(x_1+x_2\right)$ is computed by subtracting $2$ nearly equal values in the region where it is dominant. The function now reads
$$f\left(x_1,x_2\right)=g\left(y_1,y_2\right)=\ln y_1-\frac12\ln2+e^{\frac12y_1^2-\frac12y_2^2}+\frac1{\sqrt2}\left(y_1+y_2\right)$$
We can recover the original coordinates by rotating back:
$$\begin{align}x_1&=\frac1{\sqrt2}\left(y_1-y_2\right)\\
x_2&=\frac1{\sqrt2}\left(y_1+y_2\right)\end{align}$$
Some Matlab code:
% level.m

zmax = 10;
npts = 50;
y1 = [logspace(-zmax/log(10),0,floor(npts/2)) ...
    linspace(1,sqrt(2*log(zmax)),floor(npts/2))];
y2 = linspace(-y1(end),y1(end),2*npts);
[Y1,Y2] = meshgrid(y1,y2);
X1 = (Y1-Y2)/sqrt(2);
X2 = (Y1+Y2)/sqrt(2);
F = log(Y1)-1/2*log(2)+exp((Y1.^2-Y2.^2)/2)+(Y1+Y2)/sqrt(2);
C = contour(X1,X2,F,20);
axis(y1(end)/sqrt(2)*[-1 1 -1 1]);
axis square;
clabel(C);
title('Contour Plot for $f(x_1,x_2)=\ln(x_1+x_2)+e^{x_1x_2}+x_2$', ...
    'Interpreter','latex');
xlabel('x_1');
ylabel('x_2');

And the resulting contour plot:

As can be seen Matlab isn't always so smart about where it puts its contour labels. Oh well...
