# Cálculo diferencial en varias variables

## Mini intro

2+2; 3-3; 2*3; 5/10; 3^3;

e;

float(e);

float(2);

 %e;

float(%e);

(2+3^2)^3*(5+2^2);

 x:123; y:321; 

z=2;

z;

x; y;

x*y;

x+z;

x+y;

%*10;

 f(x):= x^2 -x + 1;

f(x);

f(z);

f(%pi);

 float(f(%pi));

??float;

??renato;

/* MANUAL ONLINE */;

 wxplot2d([f(x)], [x,-5,5]);

x;

wxplot2d([f(s)], [s,-5,5]);

kill(x);

wxplot2d([f(x)], [x,-5,5]);

plot2d( [ f(x) , 2*sin(x) , atan(x) ] , [x,-2,2])$

log(10);

float(%);

log(%e);

 15!;  
factor(%);

## Resolviendo ecuaciones

kill(all)$

solve( x^2-a=4 ,x);

solve(x^2-a-4=0,x);

solve(x^2-a-4,a);

 solve(x^2=-1);

 solve(x^5=1,x);

 solve(x^n=1,x);

kk:7$ /* probar con 4,5,6,7, ....*/
solve(x^kk=1,x); 

polarform(%);

## Límites de una variable

sin(a*x)/x;

limit(sin(a*x)/x,x,0);

limit(exp(1/(1-x)),x,1);

??und;

exp(1/(1-x));

 limit(exp(1/(1-x)),x,1,plus);

 limit(exp(1/(1-x)),x,1,minus);

 limit(log(x),x,0);

f(x,y):=(x*y)/(x^2+y^2);

limit(f(x,y),x,0); 
limit(f(x,y),y,0);

limit(f(x,m*x),x,0); 

f(x,y):=(x^2*y)/(x^2+y^2);

limit(f(x,m*x),x,0); 

limit(f(x,m*x^4),x,0); 

limit(f(x,sqrt(x)),x,0); 

## Derivadas

diff( sin(x^2+2) , x ,3 );

diff(x^x, x , 3);

ratsimp(%);

factor(%);

f(x,y);

diff(f(x,y), x);

ratsimp(%);

factor(%);

diff(f(x,y), y);

factor(%);

diff(f(x,y));

## Dibujando en 3D

kill(f,x,y)$
f(x,y):= sin(x) + cos(y);
wxplot3d( f(x,y) , [x,-5,5] , [y,-5,5] )$

plot3d(f(x,y), [x,-5,5], [y,-5,5])$

load(draw)$

wxdraw3d( proportional_axes = 'xyz, color=blue, xu_grid = 50,  
explicit(f(x,y), x,-5,5,y,-5,5) )$

draw3d( proportional_axes = 'xyz, color=red, xu_grid = 10,  
explicit(f(x,y), x,-5,5,y,-5,5) )$

draw3d( proportional_axes = 'xyz, color=cyan, xu_grid =50,  
explicit(f(x,y), x,-5,5,y,-5,5), 
point_type=filled_circle, point_size =2,color = blue, 
points([[2,1,f(2,1)]]))$

## Límites, continuidad y diferenciabilidad

### Ejemplo 1

kill(f)$
f(x,y):=if x^2+y^2=0 then 0 else x*y/(y^2+x^2);

f(2,1);f(0,0);

/* Dibujamos la función */
draw3d(enhanced3d = false, xu_grid = 100, color = gray50,
explicit(f(x,y), x,-.1,.1,y,-.1,.1),
point_type=filled_circle, point_size =2,color = black,
points([[0,0,0]]) )$

plot3d(f(x,y), [x,-.5,.5], [y,-.5,.5], [grid,80,80],[gnuplot_pm3d,true])$

wxplot3d (5*f(x,y), [x,-.5,+.5], [y,-.5,+.5], [zlabel,""],
[mesh_lines_color,false], [elevation,0], [azimuth,0],
color_bar, [grid,80,80], [ztics,false], [color_bar_tics,1])$

f(x,m*x);
ratsimp(%);

limit(f(x,m*x),x,0); 

/* Calculamos las derivadas parciales */
diff(f(x,y),x);

ratsimp(%);

factor(%);

ratsimp(diff(f(x,y),x)),factor;
ratsimp(diff(f(x,y),y)),factor;

ratsimp(f(x,0)/x);
ratsimp(f(0,y)/x);

(f(x,0)-f(0,0))/x;

### Ejemplo 2

kill(f)$
f(x,y):=if x^2+y^2=0 then 0 else x^2*y^2/(x^2+y^2) ;

/* Dibujamos la función */
draw3d ( enhanced3d = false, xu_grid = 50, color =grey50,
explicit(f(x,y), x,-1,1,y,-1,1),
point_type=filled_circle, point_size = 2,color = black,
points([[0,0,0]]) )$

f(x,m*x);
ratsimp(%);

limit(f(x,m*x),x,0); 

f(x,m*x^2), ratsimp;

 limit(f(x,m*x),x,0); 

f(x,m*x^(1/2)), ratsimp;
limit(f(x,m*x),x,0); 

/* Calculamos las derivadas parciales */
ratsimp(diff(f(x,y),x));
ratsimp(diff(f(x,y),y));

factor(%);

/* Derivadas parciales el (0,0) */
ratsimp(f(x,0)/x); ratsimp(f(0,y)/x);

f(x,y)/sqrt(x^2+y^2);

/* Diferenciabilidad */
	draw3d ( enhanced3d = false, xu_grid = 50,
	color = red, explicit(f(x,y)/sqrt(x^2+y^2), x,-0.1,0.1,y,-0.1,0.1),
	point_type=filled_circle, point_size = 2,color = black,
	points([[0,0,0]])
	)$

g(x,y):=f(x,y)/sqrt(x^2+y^2);

g(x,m*x);

ratsimp(%);

limit(g(x,m*x),x,0);

g(x,m*x^2);

ratsimp(%);

radcan(%);

limit(g(x,m*x^2),x,0);

gra:ratsimp( jacobian([f(x,y)],[x,y]) );

### Ejemplo 3

kill(g)$
g(x,y):=if x^2+y^2=0 then 0 else atan((x^4+y^4)/(x^2+y^2));

g(1,1);g(0,0);

a:0$ b:0$

g(x,y);

g(x,m*x);

ratsimp(%);

limit(g(x,m*x),x,0);

g(x,m*x^2), ratsimp;

limit(g(x,m*x^2),x,0);

g(x,m*x^(1/2)), ratsimp;
limit(%,x,0);

draw3d( enhanced3d = false, xu_grid = 50, color = cyan,
explicit(g(x,y), x,-1,1,y,-1,1), 
point_type=filled_circle, point_size = 2,color = blue, points([[a,b,0]]) )$

diff(g(x,y),x)$ ratsimp(%);

diff(g(x,y),y)$ ratsimp(%);

factor(%);

g(x,0); g(0,y);

/* Derivadas parciales el (0,0) */
limit(g(x,0)/x,x,0);
limit(g(0,y)/y,y,0);

/* Dibujamos la función (Diferenciabilidad) */
draw3d( enhanced3d = false, xu_grid = 50, color = red,
explicit(g(x,y)/sqrt(x^2+y^2), x,-1,1,y,-1,1), 
point_type=filled_circle, point_size = 2,color = black, points([[a,b,0]]) )$

 /* Dibujamos la función */
	draw3d (enhanced3d = false, xu_grid = 50,
	color = red, explicit(g(x,y)/sqrt(x^2+y^2), x,-.1,.1,y,-.1,.1),
	point_type=filled_circle, point_size = 1,color = black,
	points([[0,0,0]]) )$

gd(x,y):=g(x,y)/sqrt(x^2+y^2);

gd(x,y);

gd(x,m*x),ratsimp;

limit(gd(x,m*x),x,0);

gd(x,m*x^2),ratsimp;

ratsimp(%);

radcan(%);

limit(gd(x,m*x^2),x,0);

gd(x,m*sqrt(x) ),ratsimp;

limit( gd(x, m*sqrt(x) ) , x, 0);

### Ejercicio 

kill(g)$
g(x,y):=if x^2+y^2=0 then 0 else (x^2+y^2)*sin(1/sqrt(x^2+y^2));

g(1,1);g(0,0);

a:0$ b:0$

g(x,y);

g(x,m*x),ratsimp;

limit(g(x,m*x),x,0);

g(x,m*x^2), ratsimp;

limit(g(x,m*x^2),x,0);

g(x,m*x^(1/2)),ratsimp;
limit(%,x,0);

draw3d( enhanced3d = false, xu_grid = 50, color =dark_salmon,
explicit(g(x,y), x,a-1/2,a+1/2,y,b-1/2,b+1/2), 
point_type=filled_circle, point_size =2,color = black, points([[a,b,0]]) )$

draw3d( enhanced3d = false, xu_grid = 50, color = dark_salmon,
explicit(g(x,y), x,a-.2,a+.2,y,b-.2,b+.2), 
point_type=filled_circle, point_size =2,color = black, points([[a,b,0]]) )$

draw3d( enhanced3d = false, xu_grid = 50, color = dark_salmon,
explicit(g(x,y), x,a-.1,a+.1,y,b-.1,b+.1), 
point_type=filled_circle, point_size =2,color = black, points([[a,b,0]]) )$

diff(g(x,y),x)$ 
ratsimp(%);

expand(%);

diff(g(x,y),y)$ ratsimp(%);

expand(%);

g(x,0);
g(0,y);

limit(g(x,0)/x,x,0);
limit(g(0,y)/y,y,0);

 g(x,y)/sqrt(x^2+y^2);

/* Dibujamos la función (Diferenciabilidad) */
draw3d( enhanced3d = false, xu_grid = 50, color = dark_salmon,
explicit(g(x,y)/sqrt(x^2+y^2), x,a-2,a+2,y,b-2,b+2), 
point_type=filled_circle, point_size = 2,color = blue, points([[a,b,0]]) )$

/* Dibujamos la función (Diferenciabilidad) */
draw3d( enhanced3d = false, xu_grid = 50, color = dark_salmon,
explicit(g(x,y)/sqrt(x^2+y^2), x,a-.2,a+.2,y,b-.2,b+.2), 
point_type=filled_circle, point_size =1,color = blue, points([[a,b,0]]) )$

wxplot3d (50*g(x,y), [x,a-.1,a+.1], [y,a-.1,a+.1], [zlabel,""],
[mesh_lines_color,false], [elevation,0], [azimuth,0],
color_bar, [grid,80,80], [ztics,false], [color_bar_tics,1])$

wxplot3d (10*g(x,y)/sqrt(x^2+y^2), [x,a-.1,a+.1], [y,a-.1,a+.1], [zlabel,""],
[mesh_lines_color,false], [elevation,0], [azimuth,0],
color_bar, [grid,80,80], [ztics,false], [color_bar_tics,1])$

## Matrices Jacobianas

### Ejemplo

kill(f1,f2)$
f1(x,y):= atan( (x+y)/(1-x*y) );
f2(x,y):= tan(x^2/y);

jacobian([f1(x,y),f2(x,y)],[x,y]);

define(jac(x,y),ratsimp(%));

jac(x,y);

jac(%pi^(1/2),1);

### Ejercicio

kill(f1,f2)$
f1(x,y,z):= log(1+x^2+y^2+2*z^4);
f2(x,y,z):= tanh(x^2-y*z);

jacobian([f1(x,y,z),f2(x,y,z)],[x,y,z]);

define(jac(x,y,z),ratsimp(%));

jac(1,0,-1);

float(%);

jac(1,1,1);

## Calculando derivadas direccionales 

kill(all)$

/* Definimos la norma en R^2 y R^3 */
define(norm2(vv),sqrt(sum(vv[k]^2,k,1,2)));
define(norm3(vv),sqrt(sum(vv[k]^2,k,1,3)));

### Ejemplo 1

/* Definimos la funcion */  
kill(f,a,b,c,v1,v2)$
define(f(x,y),x^2*y^3);

/* Calculamos las derivadas parciales */
diff(f(x,y),x);
diff(f(x,y),y);

/* Calculamos el Jacobiano de la función */
gra:jacobian([f(x,y)],[x,y]);

/* Definimos el vector normalizado */
v1:2$ v2:-1$ v:[v1,v2]$ 
vec:v/norm2(v);

/* Calculamos la derivada direccional de f segun v y la evaluamos en (a,b) */
a:1$ b:2$ c:f(a,b)$
Du:gra.vec;  /* Multiplicación de matrices */
ev(Du,x=a,y=b);

gra.vec;

f(a,b); f(a+0.001*v1,b+0.001*v2);

gra*vec;

gra;

vec;

vec*vec;

/* Dibujamos la función */
draw3d( enhanced3d = false, xu_grid = 50, color = sea_green,
              explicit(f(x,y), x,a-2,a+2,y,b-2,b+2),
point_type=filled_circle, point_size = 2,color = midnight_blue, points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],[v1,v2,0])  )$

### Ejercicio 2

/* EJEMPLO 3: Definimos la funcion */  
kill(f,a,b,c,v1,v2)$
define(f(x,y),sin( (x^2+y^2)/(x^2+y^2+1)));

/* Calculamos las derivadas parciales */
diff(f(x,y),x), ratsimp;
diff(f(x,y),y), ratsimp;

factor(%);

/* Calculamos el Jacobiano de la función */
gra:jacobian([f(x,y)],[x,y]),ratsimp;

/* Definimos el vector normalizado */
v1:-4$ v2:3$ v:[v1,v2]$ 
vec:v/norm2(v);

/* Calculamos la derivada direccional de f segun v y la evaluamos en (a,b) */
a:-1$ b:1$ c:f(a,b)$
Du:gra.vec;
ev(Du,x=a,y=b);

float(%);

/* Dibujamos la función */
draw3d( enhanced3d = false, xu_grid = 50, color = spring_green,
explicit(f(x,y), x,a-2,a+2,y,b-2,b+2),
point_type=filled_circle, point_size = 2,color = forest_green, points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1, vector([a,b,c],[v1,v2,0]) )$

### Ejercicio 3

/* Definimos la funcion  */
kill(f,a,b,c)$
define(f(x,y,z),(x/y)^z);

gra:jacobian([f(x,y,z)],[x,y,z]);

v:[2,1,-1]$ 
vec:v/norm3(v);

a:%pi$ b:4$ c:2$ 
Du:gra.vec;
ev(Du,x=a,y=b,z=c);

float(%);

### Ejercicio 4

/*   Definimos la función */
kill(f,a,b,c)$
define(f(x,y),(x^2+y^2)^(x));

gra:jacobian([f(x,y)],[x,y]);

v1:1$ v2:-1$ v:[v1,v2]$ 
vec:v/norm2(v);

a:%e$ b:0$  c:f(a,b)$
Du:gra.vec;
ev(Du,x=a,y=b);

/* Dibujamos la función */
draw3d( enhanced3d = false, xu_grid = 50, color = sea_green,  
             explicit(f(x,y), x,a-1,a+1,y,b-1,b+1),
point_type=filled_circle, point_size = 2,color = midnight_blue, points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1, vector([a,b,c],[v1,v2,0]) )$

## Planos tangentes

### Ejemplo 1

kill(all)$
es:1/5$
define(f(x,y),es*(1-(x^2+y^2)));

define(dxf(x,y),diff(f(x,y),x));
define(dyf(x,y),diff(f(x,y),y));

/* Ecuacion del plano */
a:-1$ b:1$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(-1);
-z+f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b)=0;
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d(  color=blue, xu_grid = 50,   proportional_axes = 'xyz,  
explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1), color=cyan, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =2,color = black, 
points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],vn) )$

### Ejercicio 1

kill(all)$
es:1/2$
define(f(x,y),es*(  x^2*y^2/(x^2+y^2)  ));

define(dxf(x,y),diff(f(x,y),x));
define(dyf(x,y),diff(f(x,y),y));

/* Ecuacion del plano */
a:-2$ b:1$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(1);
z=f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b);
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d(  color=blue, xu_grid = 50,   
 explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1), color=cyan, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =1,color = black, 
points([[a,b,f(a,b)]]), head_angle  = 20,head_length = 0.1,
vector([a,b,c],vn)  )$

### Ejercicio 2

kill(all)$
es:1$
define(f(x,y),es*( atan(x^2+y^2) ));

define(dxf(x,y),diff(f(x,y),x));
define(dyf(x,y),diff(f(x,y),y));

/* Ecuacion del plano */
a:0$ b:1$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(1);
z=f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b);
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d(  color=blue, xu_grid = 100,  
explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1),
color=cyan, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =1,color = black, 
points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],vn)
)$

### Ejercicio 3

kill(all)$
es:1/5$
define(f(x,y),es*( (x^2+y^2)*sin((x^2+y^2))  ));

define(dxf(x,y),diff(f(x,y),x));
define(dyf(x,y),diff(f(x,y),y));

/* Ecuacion del plano */
a:0$ b:0$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(-1);
z=f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b);
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d( proportional_axes = 'xyz, color=blue, xu_grid = 50,  
explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1),
color=red, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =1,color = black, 
points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],vn)
)$

a:1$ b:0$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(-1);
z=f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b);
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d( proportional_axes = 'xyz, color=blue, xu_grid = 50,  
explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1),
color=red, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =1,color = black, 
points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],vn)
)$

### Ejercicio 4

kill(all)$
es:2$
define(f(x,y),es*(  exp(-x^2-y^2)  ));

define(dxf(x,y),diff(f(x,y),x));
define(dyf(x,y),diff(f(x,y),y));

/* Ecuacion del plano */
a:0$ b:0$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(-1);
z=f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b);
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d( proportional_axes = 'xyz, color=blue, xu_grid = 50,  
explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1),
color=cyan, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =1,color = black, 
points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],vn)
)$

a:1/2$ b:-1/2$ c:f(a,b)$  xmin:a-1$ xmax:a+1$ ymin:b-1$ ymax:b+1$
vn:[dxf(a,b),dyf(a,b),-1]*(-1);
z=f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b);
define(plano(x,y), f(a,b)+dxf(a,b)*(x-a)+dyf(a,b)*(y-b));

draw3d( proportional_axes = 'xyz, color=blue, xu_grid = 50,  
explicit(f(x,y),x,xmin-1,xmax+1,y,ymin-1,ymax+1),
color=red, 
parametric_surface(x,y,plano(x,y),x,xmin,xmax,y,ymin,ymax),
point_type=filled_circle, point_size =1,color = black, 
points([[a,b,f(a,b)]]),
head_angle  = 20,head_length = 0.1,vector([a,b,c],vn) )$