===
13.1 Functions of Several Variables
13.2 Limits and Continuuity
13.3 Partial Differentiation
13.4 Chain Rule
13.5 Tangent Plane
13.6 Relative Extrema
13.7 Lagrange Multiplier
13.8 Method of Least Squares
Vissualization
Functions can be specified with more than two independent variables. For example, the Cobb-Douglas production function, $$ f (K, L) = \lambda K^{\alpha} L^{1 - \alpha} \text{ where } 0 < \alpha < 1$$
is a model used to study the relationship between levels of labor, $L$, and capital goods, $K$.
Especially, $f(x,y)$ is called a function of two variables and Graphs of Functions of Two variables, $z = f (x, y)$, is the set $$ S=\{(x,y,z)| z=f(x,y) \text{ for }(x,y)\in D\},$$
which can be represented as the three-dimension Cartesian coordinate system or the level curve on the plane.
To Describe the property for simplicity, we also observe the following way:
The level curves of a function of two variables are the curves on $X-Y$ plane with $f(x,y)=k$, where $k\in$ Range($f$).
%matplotlib inline
#rcParams['figure.figsize'] = (10,3) #wide graphs by default
import scipy
import numpy as np
import time
from mpl_toolkits.mplot3d import Axes3D
from IPython.display import clear_output,display
import matplotlib.pylab as plt
Sketch grapg and contour of $z = f (x, y) ={y^2 - x^2 }$.
from matplotlib import cm
fig = plt.figure(figsize=(12,6))
ax = fig.gca(projection='3d')
X = np.arange(-2, 2, 0.04)
Y = np.arange(-2, 2, 0.04)
X, Y = np.meshgrid(X, Y)
f= Y*Y-X*X
ax.plot_surface(X, Y, f,rstride=8, cstride=8, alpha=0.3)
ax.contour(X, Y, f, zdir='z', offset=-6, cmap=cm.coolwarm)
ax.contour(X, Y, f, zdir='x', offset=-2.5, cmap=cm.coolwarm)
ax.contour(X, Y, f, zdir='y', offset=2.5, cmap=cm.coolwarm)
ax.set_zlim(-6,4);
ax.set_title("$f=y^2-x^2$")
<matplotlib.text.Text at 0x1147cbe80>
$z = f (x, y) = \sqrt{16 - x^2 - y^2}$. Here domain is $\{(x, y) |x^2 + y^2 \le 16\}$ and the range is $[0, 4]$.
Consider the function $z = \frac{6}{2 - x - y}$.
Domain=$\{(x, y) \in \mathbb{R}^2 | 2 - x - y \neq 0\}$ and Range=$\{z \in \mathbb{R}| z \neq 0\}$ since $2 - x- y$ can approach $\pm \infty$ and $2^{\pm}$.
Since the domain for $\ln \cdot$ is $\{ x > 0 \}$, then the domain for $\ln x y$ is
$$\{x y > 0 \} = \{ (x, y) | x, y > 0\text{ or } x, y < 0 \} $$It is obvious that the graphs of functions can help us to recognize the behavior of function, for example: the domain, the range and the extrema at which they occur. With the help of matplotlib, we can easily generate the graphs of functions not only 2D but 3D graphs with many useful features.
fig = plt.figure(figsize=(12,6))
ax = fig.gca(projection='3d')
X = np.arange(-2, 2, 0.04)
Y = np.arange(-2, 2, 0.04)
X, Y = np.meshgrid(X, Y)
f= X*X*Y/(X*X+Y*Y)
ax.plot_surface(X, Y, f);
Suppose that $N$ is a region in $\mathbb{R}^2$ containing $(a, b)$, called neighborhooh of $(a, b)$.
$f (x, y)$ is called to have a limit, $L$, at $(a, b)$ if the value of $f (x, y)$ can approach $L$ arbitrarily while $(x, y)$ is near $(a, b)$ enough. This means:
$\forall \varepsilon > 0, \exists \delta > 0$ such that $|f (x, y) - f (a, b) | < \varepsilon$ if $\|(x, y) - (a, b)\| < \delta$
where $\|(x, y) - (a, b)\| = \sqrt{(x - a)^2 + (y - b)^2}$ i.e. the distance between $(x, y)$ and $(a, b)$.
Evaluate the following limit: $$ \lim_{(x, y) \rightarrow (0, 0)} \frac{x - y}{x + y} $$
1. Approach $(0, 0)$ along $X$-axis, we have
\begin{eqnarray*} \lim_{(x, y) \rightarrow (0, 0)} \frac{x - y}{x + y} & = & \lim_{y = 0, x \rightarrow 0} \frac{x - y}{x + y} = 1 \end{eqnarray*}2. Approach $(0, 0)$ along $Y$-axis, we have
\begin{eqnarray*} \lim_{(x, y) \rightarrow (0, 0)} \frac{x - y}{x + y} & = & \lim_{x = 0, y \rightarrow 0} \frac{x - y}{x + y} = - 1 \end{eqnarray*}The limit fails to exist since the limits in (a) and (b) are not equal.
Evaluate the following limit: $$ \lim_{(x, y) \rightarrow (0, 0)} \frac{x^2 - y^2}{x^2 + y^2} $$
1. Approach $(0, 0)$ along $X$-axis, we have
\begin{eqnarray*} \lim_{(x, y) \rightarrow (0, 0)}\frac{x^2 - y^2}{x^2 + y^2} & = & \lim_{y = 0, x \rightarrow 0} \frac{x^2 - y^2}{x^2 + y^2} = 1 \end{eqnarray*}2. Approach $(0, 0)$ along $Y$-axis, we have
\begin{eqnarray*} \lim_{(x, y) \rightarrow (0, 0)} \frac{x^2 - y^2}{x^2 + y^2} & = & \lim_{x = 0, y \rightarrow 0} \frac{x^2 - y^2}{x^2 + y^2} = - 1 \end{eqnarray*}The limit fails to exist since the limits in (a) and (b) are not equal.
from matplotlib import cm
fig = plt.figure(figsize=(12,6))
ax = fig.gca(projection='3d')
X = np.arange(-1, 1, 0.04)
Y = np.arange(-1, 1, 0.04)
t = np.arange(-1, 1, 0.04)
X, Y = np.meshgrid(X, Y)
f= (Y*Y-X*X)/(X*X + Y*Y)
ax.plot_surface(X, Y, f,alpha=0.5)
#ax.contour(X, Y, f, zdir='z', offset=-6, cmap=cm.coolwarm)
ax.plot(t,0*t,-1,color="red")
ax.plot(0*t,t,1,color="blue")
ax.set_zlim(-1.1,1.1);
ax.set_title("$f=(y^2-x^2)/(x^2+y^2)$");
Evaluate the following limit: $$ \lim_{(x, y) \rightarrow (0, 0)} \frac{x y}{x^2 + y^2} $$
The limit fails to exist.
from matplotlib import cm
fig = plt.figure(figsize=(12,6))
ax = fig.gca(projection='3d')
X = np.arange(-1, 1, 0.02)
Y = np.arange(-1, 1, 0.02)
t = np.arange(-1, 1, 0.1)
X, Y = np.meshgrid(X, Y)
f= (Y*X)/(X*X + Y*Y)
ax.plot_surface(X, Y, f,alpha=0.5)
#ax.contour(X, Y, f, zdir='z', offset=-6, cmap=cm.coolwarm)
ax.plot(t,0*t,0,color="orange")
ax.plot(0*t,t,0,color="blue")
ax.plot(t,t,1/2,color="red")
ax.set_zlim(-1.1,1.1);
ax.set_title("$f=(y^2-x^2)/(x^2+y^2)$");
$f (x, y)$ is called continuous at $(a, b)$ if $$ \lim_{(x, y) \rightarrow (a, b)} f (x, y) = f (a, b) $$
Suppose that $$ f (x, y) = \left\{ \begin{array}{ll} \frac{2x^2 y}{x^2 + y^2} & \text{ if } (x, y) \neq (0.0) \\ 0 & \text{ if } (x, y) = (0.0) \end{array} \right. $$
Since the limit of $f (x, y)$ at $(0, 0)$ is equal to $0$ ( = $f (0, 0)$ ): $$|f(x,y)|\le\frac{(x^2 + y^2)^{3/2}}{x^2 + y^2}=2\sqrt{x^2 + y^2}\to 0$$
$f(x, y)$ is continuous at $(0, 0)$.
Suppose that $f,g$ continuous on $D\subset \mathbb{R}^n$.
Evaluate the following limit:
3. Consider
\begin{eqnarray*} g : (x, y) & \rightarrow & x + y\\ f : t & \rightarrow & \frac{\sin (t)}{t} \end{eqnarray*}4. Since the limits of $g (x, y)$ and $f (t)$ exists, the composition of $f (g(x, y))$ also has limit and is equal to 1.
\begin{eqnarray*} x & = & r (\theta) \cos (\theta)\\ y & = & r (\theta) \sin (\theta)\\ & \Downarrow & \\ \frac{\sin (x^2 + y^2)}{x^2 + y^2} & = & \frac{\sin r^2}{r^2}\\ & \overset{r \rightarrow 0}{\longrightarrow} & 1 \end{eqnarray*}4. $\lim\limits_{(x,y)\to(0,0)}\frac{\sin x y}{x^2 + y^2}$ fails to exist since
28. $$\lim\limits_{(x,y)\to(0,0)}\frac{\sin 2x^2+2 y^2}{x^2 + y^2}=\lim\limits_{r\to0}\frac{\sin 2r^2}{r^2 }=2$$
40. $F(x,y,z)=x\tan\frac{y}{z}$ is continuous if $y/z\ne n\pi\pm\pi/2,n\in \mathbb N$.
42. Let
$$f(x,y) =\begin{cases} \frac{x}{\sin x}+y & \text{ if } x\ne0\\ 1+y & \text{ if } x=0 \end{cases} $$** a). ** $f(x)$ is continuous if $x\ne n\pi, n=\pm1,\pm2,\cdots$
** b). ** From the following picture, the surface would increase to infinte $x\to \pi$:
51. $$\lim{(x,y)\to(0,0)}\frac{3xy^3}{x^2 + y^2}=0$$ since
** a).** for any $\varepsilon>0$, there exists a $\delta=\sqrt{\varepsilon/3}$,
** b).** $\sqrt{x^2+y^2}<\delta=\sqrt{\varepsilon/3}$, we have
$$\mathbf{\left| \frac{3xy^3}{x^2 + y^2} \right|\le\frac{3\sqrt{x^2+y^2}(x^2+y^2)^{3/2}}{x^2 + y^2}=3(x^2+y^2)<\varepsilon}$$
with the fact:
$$ |x|,|y|\le\sqrt{x^2+y^2}.$$
from numpy import sin,pi
fig = plt.figure(figsize=(12,6))
ax = fig.gca(projection='3d')
X = np.arange(-0.95*pi, 0.95*pi, 0.01)
Y = np.arange(-1.1, 1.1, 0.001)
X, Y = np.meshgrid(X, Y)
#f= X/sin(X)+Y
f=X/sin(X)+Y
ax.plot_surface(X, Y, f,alpha=0.5)
ax.set_zlim(-5,5)
#ax.set_title("$f=(y^2-x^2)/(x^2+y^2)$");
(-5, 5)
A little bothering...
import json
import numpy as np
from IPython.display import HTML, Javascript, display
def json_numpy_serialzer(o):
'''Helper function to serialize NumPy arrays.'''
if isinstance(o, np.ndarray):
return o.tolist()
raise TypeError("{} of type {} is not JSON serializable".format(repr(o), type(o)))
def jsglobal(**params):
'''Populate JS global namespace with provided Python obejcts.'''
code = [];
for name, value in params.items():
jsdata = json.dumps(value, default=json_numpy_serialzer)
code.append("window.{} = {};".format(name, jsdata))
display(Javascript("\n".join(code)))
%%javascript
// Loading the compiled MathBox bundle.
require.config({
paths: {
// mathBox: '//cdn.rawgit.com/unconed/mathbox/eaeb8e15/build/mathbox-bundle'
//mathBox: 'https://github.com/unconed/mathbox/blob/master/build/mathbox-bundle'
mathBox: 'http://127.0.0.1:8000/mathbox/mathbox-bundle'
}
});
// Helper function that setups WebGL context and initializes MathBox.
window.with_mathbox = function(element, func) {
require(['mathBox'], function(){
var mathbox = mathBox({
plugins: ['core', 'controls', 'cursor', 'mathbox'],
controls: { klass: THREE.OrbitControls },
mathbox: {inspect: false},
element: element[0],
loop: {start: false},
});
var three = mathbox.three;
three.renderer.setClearColor(new THREE.Color(0xFFFFFF), 1.0);
three.camera.position.set(-1, 1, 2);
three.controls.noKeys = true;
three.element.style.height = "400px";
three.element.style.width = "100%";
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
var w = window.innerWidth || html.clientWidth;
var h = window.innerHeight || html.clientHeight;
return rect.top < h && rect.left < w && rect.bottom > 0 && rect.right > 0;
}
// Running update/render loop only for visible plots.
var intervalId = setInterval(function(){
if (three.element.offsetParent === null) {
clearInterval(intervalId);
three.destroy();
return;
}
var visible = isInViewport(three.canvas);
if (three.Loop.running != visible) {
visible? three.Loop.start() : three.Loop.stop();
}
}, 100);
func(mathbox);
window.dispatchEvent(new Event('resize'));
})
}
%%javascript
with_mathbox(element, function(mathbox) {
mathbox.cartesian({},{rotation:(t)=>[0, t*0.1, 0]}) // Setup rotating the coordinate frame.
.grid({axes: [1, 3]}) // Add a grid to it.
.area({width:50, height:50, // This defines 2D data source, sampled from JS callback
expr: function(emit, x, y, i, j, t){
//var r = Math.sqrt(x*x+y*y);
var z =(y*y-x*x)/(x*x+y*y);
emit(x, z, y);
}})
.surface({color:'#AAA', shaded:true}) // Adding surface primitives, that draw data provided by
.surface({color:'#55A', lineX:true, lineY:true, fill:false, zBias:1}); // the last defined datasource.
})
from JSAnimation.IPython_display import display_animation
from matplotlib import animation
Another HTML binding display, installed by native Python installation way.
fig = plt.figure(figsize=(4,4))
ax = fig.gca(projection='3d')
X = np.arange(-1, 1, 0.02)
Y = np.arange(-1, 1, 0.02)
t = np.arange(-1, 1, 0.1)
X, Y = np.meshgrid(X, Y)
f= (Y*X)/(X*X + Y*Y)
ax.plot(t,0*t,0,color="red")
ax.plot(0*t,t,0,color="red")
ax.plot(t,t,1/2,color="blue")
ax.plot_surface(X, Y, f,alpha=0.5)
def animate(nframe):
# change the azim angle
angle = 20*nframe
ax.view_init(30, angle)
anim = animation.FuncAnimation(fig, animate, frames=18, interval=200)
display_animation(anim, default_mode='once')
import plotly.graph_objs as go
import numpy as np
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode()
X = np.arange(-1, 1, 0.02)
Y = np.arange(-1, 1, 0.02)
t = np.arange(-1, 1, 0.02)
X,Y = np.meshgrid(X,Y)
f= (Y*X)/(X*X + Y*Y)
surface = go.Surface(x=X, y=Y, z=f)
Line1 = go.Scatter3d(x=t, y=0*t, z=0*t)
Line2 = go.Scatter3d(x=0*t, y=t, z=0*t)
Line3 = go.Scatter3d(x=t, y=t, z=np.ones(len(t))/2)
Line4 = go.Scatter3d(x=t, y=-t, z=-np.ones(len(t))/2)
data = [surface,Line1,Line2,Line3,Line4]
fig = go.Figure(data=data)
iplot(fig)
from numpy import pi,sin
X = np.arange(-pi, pi, 0.08)
Y = np.arange(-pi, pi, 0.08)
t = np.arange(-pi, pi, 0.08)
X,Y = np.meshgrid(X,Y)
f= np.sin(Y*X)/(X*X + Y*Y)
surface = go.Surface(x=X, y=Y, z=f)
Line1 = go.Scatter3d(x=t, y=0*t, z=0*t)
Line2 = go.Scatter3d(x=0*t, y=t, z=0*t)
#Line3 = go.Scatter3d(x=t, y=t, z=np.ones(len(t))/2)
#Line4 = go.Scatter3d(x=t, y=-t, z=-np.ones(len(t))/2)
data = [surface,Line1,Line2]
fig = go.Figure(data=data)
iplot(fig)
!jupyter nbconvert --to html 6*Differentiation-1.ipynb
[NbConvertApp] Converting notebook 6 Multi-variable Calculus-Differentiation-1.ipynb to html [NbConvertApp] Writing 4990514 bytes to 6 Multi-variable Calculus-Differentiation-1.html