Está en la página 1de 23

Matemática Superior en Matlab

1. Funciones

1.1 Tipos de funciones


Funciones lineales Funciones potencial Funciones de raíz
f(x)=mx+b f(x) = xn
𝑛
m=3; b=2 f(x)= √𝑥
f= @(x) m*x+b n=2 n=2
fplot(f,[0 5]) f= @(x) x^n f= @(x) x^(1/n)
f(5) fplot(f,[-2 2]) fplot(f,[0 5])
fzero(f,0) %raíz de f f(2) f(5)
Funciones recíprocas Función valor absoluto Función entero máximo
f(x)=1/xn f(x)=|𝑥| f(x)=‖𝑥‖
f= @(x) abs(x) f= @(x) ceil(x)
fplot(f,[-1 1]) fplot(f,[0 5])
Funciones exponenciales
syms x
f=2^x
fplot(char(f),[-10 10])

Ejemplo 5. Peso de un astronauta, Si un astronauta pesa 130 libras en la superficie de la Tierra,


entonces su peso cuando está h millas arriba de la Tierra se expresa mediante la función[1]

3960 2
𝑤(ℎ) = ( )
3960 + ℎ

a) ¿Cuál es su peso cuando está 100 millas sobre la Tierra?


syms h
w=130*(3960/(3960+h))^2
subs(w,h,100)
b) Construya una tabla de valores para función w que dé el peso a alturas de 0 a 500 millas.
¿Qué concluye de la tabla?

Por serie de datos

h=0:100:500; limites
f=eval(w); clear h
format bank syms h
[h;f]' subs(w,h,100)
plot(h,f) subs(w,h,-h)
title('w(h)=130*(3960/(3960+h))^2') limit(w,inf)
xlabel('h (millas de la Tierra)')
ylabel('w = f(h) (peso del
astronauta)')
axis([0 500 100 130])
grid on
Por serie de datos y expresión

w=@(h) 130*(3960/(3960+h))^2 w='130*(3960/(3960+h))^2'


fplot(w,[0 500],'r') fplot(w,[0 500],'r')
f=inline(subs(w,h,h)) f=inline(subs(w,'h','h'))
h=0:100:500; h=0:100:500;
hold on hold on
plot(h,f(h)) plot(h,f(h))

Por expresión de caracter

syms h syms h
w=130*(3960/(3960+h))^2 w=130*(3960/(3960+h))^2
fplot(char(w),[0 500]) ezplot(w,[0 500])
h=0:100:500; h=0:100:500;
f=eval(w); f=eval(w);
hold on hold on
plot(h,f,'r') plot(h,f,'r')

1.2. Desplazamiento de funciones

Tabular Con uso de Con uso de Con uso de cadenas


syms x caracteres cadenas syms x
f=x^2 syms x syms x f=inline(x^2)
x=-10:1:10; f=x^2 f=@(x) x.^2 x=-10:1:10;
[x' eval(f)'] x=-10:1:10; x=-10:1:10; [x' f(x)']
set(ezplot(f, [x' eval(f)'] [x' f(x)'] g=f(x)-3;
[-10 10]), plot(x,eval(f plot(x,f(x),'r h=f(x)+3;
'Color','r') )) ')
g=f-3 hold on g=f(x)-3; plot(x,f(x),x,g,'r',x,h,'
h=f+3 g=char(f-3) h=f(x)+3; k')
hold on fplot(g,[-10 hold on
ezplot(g,[-10 10],'r') plot(x,g,'b')
10]) h=char(f+3) plot(x,h,'k')
set(ezplot(h, fplot(h,[-10
[-10 10]), 10],'k')
'Color','k')

syms x syms x
f=(x-10)^2 f=inline((x-10)^2)
g=(x+10)^2 g=inline((x+10)^2)
x=-20:1:20; x=-20:1:20;
[x' eval(f)'] [x' f(x)' g(x)']
set(ezplot(f,[-20 20]), plot(x,f(x),x,g(x),'r')
'Color','r')
hold on
ezplot(g,[-20 20])
1.3 Operaciones en funciones
Despejar una variable Graficar asíntotas
syms x y syms x
solve(y-(x-2)^(1/2),y) f=(3*x^2-2*x-1)/((2*x-1)*(x+2))
solve(y-(x-2)^(1/2),x) fplot(char(f),[-20 20])
x=-20:0.3:20;
plot(x,eval(f))
Figuras compuestas en trozos Funciones pares e impares
f1= @(x) x syms x
f2= @(x) x^2 f=x^5+x
figure g=subs(f,x,-x)
fplot(f1,[-4 0]) r=f/g %Si r=-1 es impar, r=1 es
hold on par, r≠1 no es par ni impar
grid on ezplot(f,[-4 4])
fplot(f2,[0.0001 4]) hold on
title('Función compuesta') ezplot(g,[-4 4])
axis([-5 5 -5 5]) F=char(f)
G=char(g)
fplot(F,[-4 4])
hold on
fplot(G,[-4 4])

1.4 Límites
syms t
v=10000/(5+1245*exp((-.97*t)))
t=0:0.1:10;
plot(t,eval(v))
clear t
syms t
format bank
limit(v,inf)
subs(v,t,10)

2. Ajuste lineal polinomial y exponencial

2.1 Ajuste de curva lineal y polinomial


d=[2.5 4 6 8 9 9.5 12.5 15.5]; t=[0 4 8 12 16];
t=[15 24 32 56 49 76 90 89]; h=[5 3.1 1.9 0.8 0.2];
plot(t,d) plot(t,h)
e=polyfit(t,d,1) e= polyfit(t,h,2)
syms t syms x
d=poly2sym(e,t) p=poly2sym(e,x)
hold on hold on
fplot(char(d),[15 89],'r') fplot(char(p),[0 16],'r')
subs(d,t,18)
2.2 Función polinomial
Función polinomial Raíces de un polinomio
x = (0: 0.1: 2.5)' syms x syms x
y = erf(x) f=x^3 -6*x^2 -72*x -27 f=x^3 -6*x^2 -72*x -27
p = polyfit(x,y,6) p=sym2poly(f) F=char(f)
x = (0: 0.1: 5)' r = roots(p) [x]=eval(solve(f,'x'))
y = erf(x) fplot(char(f),[-6 13]) real(x)
f = polyval(p,x) grid on fplot(F,[-6 13])
plot(x,y,'o',x,f,'-') fzero(char(f),0)
axis([0 5 0 2])

T=[55 58 64 68 70 75 80 84]; A=1920:10:2000


N=[340 335 410 460 450 610 L=[54.1 59.7 62.9 68.2 69.7 70.8 73.7 75.4
735 780]; 76.9]
h=plot(T,N,'r') h=plot(A,L,'r')
set(h,'LineWidth',2); set(h,'LineWidth',2);
e1=polyfit(T,N,1) e1=polyfit(A,L,1)
e2=polyfit(T,N,2) e2=polyfit(A,L,2)
e3=polyfit(T,N,3) e3=polyfit(A,L,3)
syms x syms x
f1=poly2sym(e1,x) f1=poly2sym(e1,x)
f2=poly2sym(e2,x) f2=poly2sym(e2,x)
f3=poly2sym(e3,x) f3=poly2sym(e3,x)
hold on hold on
fplot(char(f1),[55 84],'--') fplot(char(f1),[1920 2000],'--')
hold on subs(f1,x,2004)
fplot(char(f2),[55 84],'--r') hold on
hold on fplot(char(f2),[1920 2000],'--r')
fplot(char(f2),[55 84],'+k') subs(f2,x,2004)
hold on
fplot(char(f3),[1920 2000],'k')
subs(f3,x,2004)

2.3 Ajuste exponencial


La constitución de Estados unidos requiere un censo cada 10 años los datos del censo para
1790 -2000 se dan en la tabla.
(millones)

(millones)
Población

Población

(millones)

(millones)

(millones)
Población

Población

Población

Año Año Año Año Año

1790 3.9 1840 17.1 1890 63.0 1940 132.2 1990 248.7
1800 5.3 1850 23.2 1900 76.2 1950 151.3 2000 281.4
1810 7.2 1860 31.4 1910 92.2 1960 179.3
1820 9.6 1870 38.6 1920 106.0 1970 203.3
1830 12.9 1880 50.2 1930 123.2 1980 226.5
(a) Construya un diagrama de dispersión de los datos
(b) Use la computadora para halla un modelo exponencial de los datos
(c) Use un modelo para predecir un censo en el 2010.
(d) Emplee su modelo para estimar la modelación en 1965
(e) Compare sus respuestas de los incisos a) y d) con los valores de la tabla. ¿Considera
que es apropiado un modelo exponencial para estos datos?

t=1790:10:2000;
h=[3.9 5.3 7.2 9.6 12.9 17.1 23.2 31.4 38.6 50.2 63 76.2 92.2 106 ....
123.2 132.2 151.3 179.3 203.3 226.5 248.7 281.4];
plot(t,h)
e=polyfit(t,log(h),1)
syms t
h=exp(poly2sym(e,t))
hold on
fplot(char(h),[1790 2000],'r')
subs(h,t,2010)
subs(h,t,1965)

2.4 Ajuste trigonométrico

t=[0 2 4 6 8 10 12 14]; t=[0 25 50 75 100 125 150 175 200


y=[2.1 1.1 -0.8 -2.1 -1.3 0.6 1.9 225 250 275 300 325 350];
1.5]; y=[190 175 155 125 110 95 105 120
[t' y'] 140 165 185 200 195 185 165];
plot(t,y) [t' y']
A=(max(y)-min(y))/2 plot(t,y)
B=(max(y)+min(y))/2 A=(max(y)-min(y))/2
w=2*pi/12 B=(max(y)+min(y))/2
syms c w=2*pi/250
c=solve(y(1)-A*sin(w*t(1)+c)-B,c) syms c
syms t c=solve(y(1)-A*cos(w*t(1)-c)-B,c)
y=A*sin(w*t+c)+B syms t
hold on y=A*cos(w*t-c(1))+B
fplot(char(y),[0 14],'r') hold on
fplot(char(y),[0 350],'r')

syms s Fracciones parciales


f=s^3+3*s^2+2*s syms s
Factoreo Y=(2*s^3+5*s^2+3*s+6)/(s^3+6*s^2+11*s+6)
factor(f) num=numden(Y)
Agrupar den=num/Y
collect(f) coefnum=sym2poly(num)
Simplificar coefden=sym2poly(den)
simplify(f) [r,p,k]=residue(coefnum,coefden)
n=length(r)
Expandir for i=1:n
expand(f)
Y(1,i)=r(i,1)/(s-p(i,1))
end
if k~=0
Y=[Y,k]
end
Y=sum(eval(Y))
pretty(Y)
3.- Vectores
A=[3 -1 -4];
B=[-2 4 -3];
C=[1 2 -1];
D=2*A-B+3*C;
norm(A+B+C);
dot(A,B);
cross(B,C);
dot(A,cross(B,C));
norm(cross(A,cross(B,C)));
E=[A;B;C];
det(E)

En la siguiente figura ABCD es un paralelogramo con los puntos P y Q en la mitad de los


̅̅̅̅ y 𝐶𝐷
lados 𝐵𝐶 ̅̅̅̅ pruebe que 𝐴𝑃
̅̅̅̅ y 𝐴𝑄
̅̅̅̅ dividen a la diagonal 𝐵𝐷
̅̅̅̅ en tres segmentos iguales.

syms x y z BP QD CD BC k
%x=DE,y=EF,z=FB
AB=-CD;
CD=2*QD;
DA=-BC;
BC=2*BP;
%proyección h=DA•(-CD)/|CD|
%b=-2*(BP•QD)/|QD|
%ΔOBC h^2+b^2=(2BP)^2
%h=sqrt((2BP)^2-b^2))
%ΔOBD h^2+(b+2*QD)^2=(x+y+z)^2
%x+y+z=sqrt((2BP)^2-b^2+(b+2*QD)^2)=k
f1=x+y+z-k;
%ΔADF semejante ΔBPF
f2=-2*x+y+z;
%ΔDEQ semejante ΔABE
f3=x+y-2*z;
[x y z]=solve(f1,f2,f3)

Demostrar que (A x B)·(C x D) +(B x C)·(A x D)+(C x A)·(B x D)=0

syms a1 a2 a3 b1 b2 b3 c1 c2 c3 d1 d2 d3
A=[a1 a2 a3];
B=[b1 b2 b3];
C=[c1 c2 c3];
D=[d1 d2 d3];
simplify(dot(conj(cross(A,B)),cross(C,D))+...
dot(conj(cross(B,C)),cross(A,D))+...
dot(conj(cross(C,A)),cross(B,D)))
Demostrar que las diagonales de un rombo son perpendiculares.

syms AB BC CD AC BD DA
AC=AB+BC;
BD=BC+CD;
AB=-CD;
BC=-DA;
DA=norm(CD);
eval(eval(expand(AC*BD)))

Calcular
(a) Demuestre que los vectores A=3 i + j – 2 k, B=-i + 3 j+ 4 k, C=4 i – 2 j – 6 k pueden ser
los lados de un triángulo.
(b) Encuentre la longitud de las medianas del triángulo.
A=[3 1 -2];
B=[-1 3 4];
C=[4 -2 -6];
%Si (AxB)•C=0 es un triágulo
dot(cross(A,B),C)
%∡A+∡B+∡C=180
SAT=acosd(dot(-B,-A)/(norm(-B)*norm(-A)))+...
acosd(dot(-A,-C)/(norm(-A)*norm(-C)))+...
acosd(dot(C,-B)/(norm(C)*norm(-B)))
M1=norm(C/2+A)
M2=norm(A/2+C)
M3=norm(B/2+C)

4. Diferenciales

syms t syms t
R=[exp(-t) log(t^2+1) -tan(t)] A=[t^2 -t (2*t+1)];
T=diff(R,t) B=[(2*t-3) 1 -t];
M=diff(diff(R,t),t) C=diff(B,t)
norm(T) E=cross(A,C)
norm(M) F=diff(E,t)
subs(F,t,1)

𝛿2
Si A=x2yz i - 2xz3 j + xz2 k y B=2z i + y - x2 k encontrar las derivadas 𝛿𝑥𝛿𝑦 (𝐴𝑥𝐵) en el punto
(1,0,-2)

syms x y z
A=[x^2*y*z -2*x*z^3 x*z^2];
B=[2*z y x^2];
subs(diff(diff(cross(A,B),x),y),[x y z],{1 0 -2})
4.1 Divergencia

syms x y z Divergencia con lazo for


A=[2*x^2, -3*y*z, x*z^2]; function [f,v]= divg(f,v)
divergencia=diff(A(1,1),x)+.... n=length(v);
diff(A(1,2),y)+diff(A(1,3),z) for i=1:n
Divg(1,i)=diff(f(1,i),v(1,i));
end
divg=sum(Divg)

4.2 Gradiente
syms x y z f Gradiente con lazo for
Fhi=2*x*z^4-x^2*y; function [f,v]= grad(f,v)
v=symvar(Fhi) n=length(v);
n=length(v) F=f*ones(1,n);
Grad=f*ones(1,n) for i=1:n
for i=1:n Grad(1,i)=diff(F(1,i),v(1,i));
Grad(1,i)=diff(Fhi,v(1,i)) end
end
subs(Grad,v,[2 -2 -1])

syms x y z
A=[18*z,12,3*y]
f=2*x+3*y+6*z-12
grad=[diff(f,x), diff(f,y),
diff(f,z)]
n=grad/norm(eval(grad))
dot(conj(A),n)

syms x y z f
r=[x y z];
n=length(r)
F=(norm(r))^3
Grad=f*ones(1,n)
for i=1:n
Grad(1,i)=diff(F,r(1,i))
end

Dado los puntos P(2,1,3) Q(1,2,1) R(-1,-2,-2) S(1,-4,0) encontrar la distancia más corta
̅̅̅̅ y 𝑅𝑆
entre las líneas 𝑃𝑄 ̅̅̅̅.
syms x y z c1 c2 c3
r=[x y z];
C=[c1 c2 c3];
P=[2 1 3];
Q=[1 2 1];
R=[-1 -2 -2];
S=[1 -4 0];
PQ=Q-P;
RS=S-R;
N=cross(PQ,RS)
n=N/norm(N)
ft1=dot(n,r-P)
ft2=dot(n,r-S)
g1=[diff(ft1,x) diff(ft1,y) diff(ft1,z)]
g2=[diff(ft2,x) diff(ft2,y) diff(ft2,z)]
n1=g1/sqrt(sum(g1.^2))
n2=g2/sqrt(sum(g2.^2))
C=[0.5, 0.5, 0, -1.5];
x=-1;y=-2;z=-2;
d1=abs(C(1,1)*x+C(1,2)*y+C(1,3)*z+...
C(1,4))/sqrt(sum(C(1:3).^2))

Encontrar la ecuación de la tangente al plano de la superficie xz 2+x2 y = z-1 en el punto


(1,-3,2)
syms x y z
f=x*z^2+x^2*y-z+1;
r=[x y z]
ro=[1 -3 2]
F=[diff(f,x) diff(f,y) diff(f,z)]
n=subs(F,r,ro)
dot(n,(r-ro))

Si F = (3x2y-z) i + (xz3+y4) j - 2x3z2 k encontrar el gradiente de la divergencia de F en el


punto (2,-1,0)
syms x y z
F=[(3*x^2*y-z) (x*z^3+y^4) -2*x^3*z^2];
f=diff(F(1,1),x)+diff(F(1,2),y)+diff(F(1,3),z);
gradiente=subs([diff(f,x) diff(f,y) diff(f,z)],[x,y,z],{2,-1,0})

4.3 Rotacional
syms x y z Rotacional con funcion
A=[2*x^2 -3*y*z+x*z^2]; function [f,v]= rot(f,v);
rotacio=[diff(A(1,3),y)... Rot(1,1)=diff(f(1,3),v(1,2))-...
-diff(A(1,2),z),... diff(f(1,2),v(1,3));
diff(A(1,1),z)-diff(A(1,3),x),... Rot(1,2)=diff(f(1,3),v(1,1))-...
diff(A(1,2),x)-diff(A(1,1),y)] diff(f(1,1),v(1,3));
Rot(1,3)=diff(f(1,2),v(1,1))-...
diff(f(1,1),v(1,2));
Rot

Comprobar que u=i+j-k y v=i-j son perpendiculares.

a) Determinar w, de tal manera que u, v y w formen una triada de giro positivo.


b) Determinar la matriz de transformación entre los ejes u, v y w y i, j, k

syms a1 a2 a3
w=[a1 a2 a3];
u=[1 1 -1];
v=[1 -1 0];
f1=2*a2-a3
f2=dot(u,w)
f3=dot(v,w)
a=solve(f1,f2,f3,a1,a2,a3)
W=subs([a.a1 a.a2 a.a3],'z',1)
uw=W/norm(W)
uv=v/norm(v)
uu=u/norm(u)
i=[1 0 0]
j=[0 1 0]
k=[0 0 1]
F=[ dot(uw,i) dot(uw,j) dot(uw,k);....
dot(uv,i) dot(uv,j) dot(uv,k);....
dot(uu,i) dot(uu,j) dot(uu,k)]
acosd(F)

Determinar la matriz de transformación entre los ejes 𝐮


⃑ = 𝐢 +𝐣 - 𝐤, 𝐯⃑ = 𝐢 - 𝐣 y 𝐰 =
𝟏 𝟏⁄𝟐
(𝟔) (𝐢 + 𝐣 + 𝟐𝐤) y las direcciones i,j,k.

u=[1 1 -1];
v=[1 -1 0];
w=((1/6)^2)*[1 1 2]
i=[1 0 0]
j=[0 1 0]
k=[0 0 1]
uu=u/norm(u);
uv=v/norm(v);
A=[dot(uu,i),dot(uu,j),dot(uu,k)];
B=[dot(uv,i),dot(uv,j),dot(uv,k)];
C=[dot(w,i),dot(w,j),dot(w,k)];
D=[A;B;C]
norm(D(:,1))

5. Tensores
syms h n1 n2 n3
Tik=[1 0 0;0 2 3;0 3 4]
Tki=Tik'
Sik=0.5*(Tik+Tki)
Tik=0.5*(Tik-Tki)
H=[1-h 0 0;0 2-h 3;0 3 4-h]
n=[n1 n2 n3]
F=H*conj(n)'
F=subs(F,h,'k')
f4=n1^2+n2^2+n3^2-1
f=det(H)
[h]=eval(solve(f))
j=length(h);
for i=1:j
k=h(i,1);
f(1:3,:)=eval(F);
[n1 n2 n3]=solve(f(1,:),f(3,:),f4);
syms z
disp( ' n1 n2 n3')
n=eval([n1 n2 n3])
syms n1 n2 n3
end
syms n1 n2 n3
f1=(1-h(2,1))*n1+0*n2+0*n3;
f2=0*n1+(2-h(1,1))*n2+3*n3;
f3=0*n1+3*n2+(4-h(3,1))*n3;
[n1 n2 n3]=solve(f1,f3,f4);
disp( ' n1 n2 n3')
n=eval([n1 n2 n3])

4.1 Invariantes
A=[1 3 5;2 6 9;-3 -2 -8];
S=0.5*(A+A')
[V,D]=eig(A)
det(A)
det(D)
Ad=diag(A)
sum(Ad)
(A(2,2)*A(3,3)-A(2,3)*A(3,2))...
+(A(1,1)*A(2,2)-A(2,1)*A(1,2))...
+(A(1,1)*A(3,3)-A(1,3)*A(3,1))
V=diag(D)
V(1,1)*V(2,1)+V(1,1)*V(3,1)+V(2,1)*V(3,1)

T=[5 -1 3;1 -6 -6;-3 -18 1]


[V,J]=jordan(T)
S=0.5*(T+T')
[V,D]=eig(S)

7 3 0
Determinar para el tensor simétrico Tik = (3 7 4) los valores principales y las
0 4 7
direcciones de los ejes principales.

Tik=[7 3 0;3 7 4;0 4 7]


Tki=Tik'
Sik=0.5*(Tik+Tki)
[V,D]=eig(Sik)
C=diag(D)
format bank
%Primer invariante suma de las diagonales
IS=sum(diag(Sik)) %invariante del tensor simétrico
ID=sum(C) %invariante del tensor valores propios
%Segundo invariante: determinante de los mínimos valores
IIS=det(Sik(2:3,2:3))+det(Sik(1:2,1:2))....
+det([Sik(1,1) Sik(1,3);Sik(3,1) Sik(3,3)]) %invariante del tensor
simétrico
IID=C(1,1)*C(2,1)+C(1,1)*C(3,1)+C(2,1)*C(3,1) %invariante del tensor
valores propios
%Tercer invariante:
IIIS=det(Sik) %invariante del tensor simétrico
IIID=C(1,1)*C(2,1)*C(3,1) %invariante del tensor valores propios

[V,D]=eig(Tik)
3 2 0
Hallar la raíz cuadrada del tensor Dik = (2 3 0)
0 0 9
D=[3 2 0;2 3 0;0 0 9];
sqrt(D)

6. Sistemas de ecuaciones
A=[1 -1 3 -3 3;-5 2 -5 4 -5;...
-3 -4 7 -2 7;2 3 1 -1 1]
[L,U]=lu(A)
a=[1 -1 3 -3;-5 2 -5 4;...
-3 -4 7 -2;2 3 1 -1]
b=[3 -5 7 1]
c=inv(a)
c*b'
syms w x y z
[w,x,y,z]=solve(w-x+3*y-3*z-3,...
-5*w+2*x-5*y+4*z+5,...
-3*w-4*x+7*y-2*z-7,...
3*w+3*x+y-z-1)

Resolver el siguiente sistema de ecuaciones lineales

x+2y+z+3u+v+w=2
-x+y-z+u-v+w=4
2y+2u+2w=-7
x-z+u+4v+9w=8
2x-3y+u+5v-3w=1
3x+7y+2z+u+2v+8w=3

%Matriz inversa
A=[1 2 1 3 1 1 ;-1 1 -1 1 -1 1;0 2 0 2 0 2;1 0 -1 1 4 9;...
2 -3 0 1 5 -3;3 7 2 1 2 8 ];
B=[2 4 -7 8 1 3];
%Forma 1
xi=inv(A)*B'
%Forma 2
x=A\B'
%Variables
X=mldivide(A,B)
syms x y z u v w
[x,y,z,u,v,w]=solve(x+2*y+z+3*u+v+w-2,...
-x+y-z+u-v+w-4,2*y+2*u+2*w+7,...
x-z+u+4*v+9*w-8,2*x-3*y+u+5*v-3*w-1,...
3*x+7*y+2*z+u+2*v+8*w-3);
disp( 'x y z u v w')
[x,y,z,u,v,w]
linsolve(A,B)
%Reducción de Gauss
C=[A,B'];
[L,U]=lu(C)
soluci=rref(C)
soluci=rref([A B'])
7. Integrales

Integrales simples
Integral numérica con uso de Integral numérica Integral simbólica
función encadenada transformando a función >> syms x
>> f = @(x) x.*sin(4*log(x)) encadenada >> f=x*sin(4*x)
>> quad(f,0.2,3) >> syms x >> F=int(f,x)
>> f=x*sin(4*log(x)) >> y=char(f)
>> F=inline(f) >> Y=char(F)
>> quad(F,0.2,3) >> fplot(y,[0 10])
>> hold on
>> fplot(Y,[0 10])

Integrales dobles
Integral numérica doble con Integral numérica Integral doble simbólica
uso de función encadenada transformando a función >> syms x y
>> f = @(x,y) 1./(1+x.^2+y^2) encadenada >> f = (1+x^2+y^2)
>> dblquad(f,-1,1,0,1) >> syms x y >> F=int(int(f,y),x)
>> f = 1/(1+x^2+y^2) >> t=char(f)
>> F=inline(f) >> T=char(F)
>> dblquad(F,-1,1,0,1) >> ezsurf(t)
>> hold on
>> ezsurf(T)

Integrales triples
Integral numérica triple con Integral numérica Integral triple simbólica
uso de función encadenada transformando a función >> syms x y z
>> f=@(x,y,z) encadenada >> f = (1+x^2+y^2+z^2)
x.*sin(x)+z*cos(y)*cos(x) >> syms x y z >> F=int(int(int(f,z),y),x)
>> triplequad(f,0,1,0,1,0,1) >> f=x*sin(x)+z*cos(y)*cos(x) >> t=solve(f,z)
>> F=inline(f) >> T=solve(F,z)
>> triplequad(F,0,1,0,1,0,1) >> u=char(t)
>> U=char(T)
>> ezsurf(u(1,1))
>> hold on
>> ezsurf(U(1,2))

syms a b c x y z
A=[a*x b*y c*z];
V=x*y*z;
div=diff(A(1,1),x)+diff(A(1,2))+diff(A(1,3));
F=int(int(int(div,x),y),z)
subs(F,x*y*z,V)
syms u syms t
A=[3*sin(u) 2*cos(u) 0] A=[t -t^2 (t-1)];
n=length(A) B=[2*t^2 0 6*t];
for i=1:n n=length(A)
if A(1,i)~=0 C=cross(A,B)
f=inline(A(1,i)) for i=1:n
R(1,i)=quad(f,0,pi/2) if C(1,i)~=0
else f=inline(C(1,i))
R(1,i)=0 R(1,i)=quad(f,0,2)
end else
end R(1,i)=0
end
end
S=int(C,0,2)
S=eval(S)

syms u syms t
A=[3*sin(u) 2*cos(u) 0] A=[t -t^2 (t-1)];
n=length(A) B=[2*t^2 0 6*t];
for i=1:n n=length(A)
if A(1,i)~=0 C=cross(A,B)
f=inline(A(1,i)) for i=1:n
R(1,i)=quad(f,0,pi/2) if C(1,i)~=0
else f=inline(C(1,i))
R(1,i)=0 R(1,i)=quad(f,0,2)
end else
end R(1,i)=0
end
end
S=int(C,0,2)
S=eval(S)

syms t x y z dx dy dz
A=[(2*y+3) x*z (y*z-x)]
x=2*t^2;y=t;z=t^3;
dx=diff(x,t);dy=diff(y,t);dz=diff(z,t);
dr=[dx dy dz]
fhi=expand(dot(conj(A),dr))
format bank
Fr=int(fhi,t)
R=int(fhi,0,1)
R=subs(Fr,t,1)-subs(Fr,t,0)

Calcule

a) ∬𝑆 (∇𝑥𝐹) ∙ 𝒏 𝑑𝑠
b) ∬𝑆 ∅ 𝐧 ds

Si F = (x+2y) i - 3z j + x k, ø = 4x + 3y - 2z y S es la superficie de 2x + y + 2z = 6 limitada por


x=0, x=1, y=0, y=2.
syms x y z
F=[(x+2*y),-3*z,x];
fp=2*x+y+2*z-6;
Fr=[diff(F(1,3),y)-diff(F(1,2),z),...
diff(F(1,1),z)-diff(F(1,3),x),...
diff(F(1,2),x)-diff(F(1,1),y)]
gradp=eval([diff(fp,x),diff(fp,y),diff(fp,z)])
n=gradp/norm(gradp)
f=(dot(Fr,n));
k=[0 0 1];
fkn=dot(k,n);
Solu1=int(int(f/fkn,x,0,1),y,0,2)
z=(6-y-2*x)/2;
fi=4*x+3*y-2*z;
fi=eval(fi)
fn=simple(fi*n)
Solu2=int(int(fn/fkn,x,0,1),y,0,2)

Si A=2yzi-(x+3y-2)j+(x2+z)k. Calcular ∬𝑆 (∇𝑥𝐴) ∙ 𝒏 𝑑𝑠 sobre la superficie de


intersección de los cilindros x2 + y2 = a2 y x2 + z2 = a2 en el primer octante.
syms x y z a
A=[2*y*z -(x+3*y-2) (x^2+z)]
fp=y-z;
Ar=[diff(A(1,3),y)-diff(A(1,2),z),...
diff(A(1,1),z)-diff(A(1,3),x),...
diff(A(1,2),x)-diff(A(1,1),y)]
gradp=eval([diff(fp,x),diff(fp,y),diff(fp,z)])
z=y;
un=gradp/sqrt(sum((gradp.^2)))%vector unitario de la normal
f=eval(dot(conj(Ar),un))
Solu=int(int(f/cosd(45),x,0,sqrt(a^2-y^2)),y,0,a)
n=[0 1 -1];
k=[0 0 1];
nk=dot(n,k)/(norm(n)*norm(k)) %nk=cos(alfa)
Solu=int(int(f/nk,x,0,sqrt(a^2-y^2)),y,0,a)

Ecuaciones diferenciales de primer orden f=D2y+4*Dy+5*y;f=D2y+y-(x-2)*exp(2*x);


y*D2y-(Dy)^2; f=2*x*(Dy)^2-D2y

a) simple(dsolve('Dy=x*(1+y^2)/(y*(1+x^2))','x'))
dsolve('x*(1+y^2)-y*(1+x^2)*Dy','x')

b) dsolve('Dy=y/x','x')

c) simple(dsolve('x*(1+y^2)-y*(1+x^2)*Dy','x'))

d) f=dsolve('Dx=4*t*sqrt(x)','x(1)=1','t')
fplot(char(f(1,1)),[-10 10])
hold on
fplot(char(f(2,1)),[-10 10])

e) f=dsolve('Dy=2*x+y','y(0)=4','x')
f=@(x,y) x*y^3+x^2; p=dsolve('Dy=x+y^2','y( f=@(x,y) x*y^3+x^2;
[x,y]=ode45(f,[0:0.1 0)=0','x') p=dsolve('Dy=x*y^3+x^2','y
:1],[0]) fplot(char(p),[0 1]) (0)=0','x')
plot(x,y,'r') hold on [x,y]=ode45(f,[0:0.1:1],[0
r=polyfit(x,y(:,1),2 f=@(x,y) x+y^2 ])
) [x,y]=ode45(f,[0:0.1:1] plot(x,y)
syms t ,[0]) r=polyfit(x,y(:,1),2)
h=poly2sym(r,t) plot(x,y,'r') syms t
hold on h=poly2sym(r,t)
fplot(char(h),[0 1]) hold on
fplot(char(h),[0 1])

Ecuacion ;y=2*x*y’-(y’^3)
clear;clc;clf
syms x y Dy Y y1 y2 p %Definición de variables
f=2*x*Dy-Dy^3-y %Ecuación Diferencial
%%
%Solución Analítica por matlab dsolve
f1=dsolve(f,x);
C=symvar(f1);C1=1;xo=1.8;xmax=3;
f2=subs(f1,C(1,1),C1)
yo=subs(f2,'x',xo)
hold on %Mantener activo la ventana grafica
set(ezplot(f2(2,1)),'Color','k') %Graficar la expresión f1(3,1)
axis([xo xmax 0 10]) %Fijar rangos de graficos en X y Y
%%
%Solución Analítica manual
fp=C1/p^2+(3*p^2/4)-x;
y=(2*x*p)-p^3;
p=solve(fp,'p')
y=subs(y,{'p'},{p(3,1)});
fplot(char(y),[xo xmax],'--g')
pretty(y)
%%
dy=solve(f,'Dy') %Despejar Dy
Dy1=inline(dy(1,1))
h=0.2;
x=xo:h:xmax;
%Método de Runge Kutta
[x,y]=ode45(Dy1,x,[yo(2,1)])
plot(x,y,'or')
%%
n=length(x);
y=Y*ones(1,n);
x(1)=xo;
y(1)=yo(2,1);
Dy=(y2-y1)/h
f3=subs(f,'Dy',Dy)
f4=solve(f3,'y2')
%Diferencias Finitas
for i=1:n-1
f5=subs(f4(1,1),{y1,y2,'x','y'},{y(i),y(i+1),x(i),y(i)});
y(i+1)=eval(f5);
end
plot(x,eval(y),':')
Tanque de almacenamiento
Q=500;%m^3/s
A=1200;%m^2
a=300;
%Por Runge Kutta
F=@(t,y) 3*Q*((sin(t))^2)/A-a*((1+y)^(1.5))/A
[t,y]=ode45(F,[0:0.1:10],[0])
plot(t,y,'r')
syms Y
dt=0.1
t=0:dt:10;
n=length(t)
y=Y*ones(1,n)
y(1)=0
%Por diferencias finitas
for i=1:n-1
f(i+1)=eval((3*Q*((sin(t(i)))^2)/A-a*((1+y(i))^(1.5))/A)*dt+y(i))
y(i+1)=f(i+1)
end
y=eval(y)
hold on
plot(t,y)

Ecuaciones diferenciales de segundo orden


syms x F=@(x,y) [y(2);y(1)];
p=dsolve('D2y- f=dsolve('D2y-y=0','y(0)=0','y(1)=-4','x')
6*Dy+5*y=0','y(0)=1','y(2)=1' fplot(char(f),[0 1])
,'x') hold on
fplot(char(p),[0 2]) [x,y]=ode45(F,[0:0.1:1],[0 -4])
plot(x,y(:,1),'r')

Ecuacion ;y=x*y’-y’’
%y=x*y’-y’’
%Por Runge Kutta
F=@(x,z) [(-x+sqrt(x.^2+4*z(1)))/2;(-x-sqrt(x.^2+4*z(1)))/2]
[X Y]=ode45(F,[2:0.1:3],[-1 -1]);
fprintf(' x y1 y2');
[X Y]
plot(X,Y(:,1),'--k',X,Y(:,2),'--k')
%Por diferencias finitas
syms Y z
h=0.2;
x=2:0.2:3;
n=length(x);
y=Y*ones(2,n);
for k=1:n-1
for i=1:2
y(i,1)=-1;
f(i,k)=x(k)*(y(i,k+1)-y(i,k))/h+((y(i,k+1)-y(i,k))/h)^2-y(i,k);
resul=eval(solve(f(i,k)));
y(i,k+1)=resul(i,1);
end
end
fprintf(' x y1 y2');
solucion=[x' eval(y)']
hold on
plot(x,y(1,:),'+',x,y(2,:),'-o')
F1=-z+1
F2=-z^2/4
hold on
fplot(char(F1),[2 3],'+g')
hold on
fplot(char(F2),[2 3],'+g')
p1=eval(polyfit(x,y(1,:),1))
p2=eval(polyfit(x,y(2,:),2))
syms x
f1=poly2sym(p1,x)
f2=poly2sym(p2,x)

Ecuacion ;y= x*y’-x*y’’


clear;clc;figure(close)
syms x y Dy D2y Y y1 y2 y3 %Definición de variables
f=x*D2y-x*Dy+y %Ecuación Diferencial
%%
%Solución Analítica por matlab dsolve
f1=dsolve(f,'y(1)=2','y(2)=6',x);
f2=subs(f1,{'Ei(1)','Ei(2)','Ei(1, -x)'},{0,0,0});
digits(3);
f3=vpa(f2);
hold on %Mantener activo la ventana grafica
fplot(char(f3),[1 2],'--b')
%%
%Método de Runge Kutta
%Cambio de variables reduciendo a primer orden
%[y(1)]=[y] [Dy(1)]=[y(2)]
%[y(2)]=[Dy] [Dy(2)]=[D2y]=[(x*Dy-y)/x]
f4=solve(f,D2y)
f5=subs(f4,{'y','Dy'},{'y(1)','y(2)'})
f6(x,y)=['y(2)';f5]
Dy=matlabFunction(f6)
h=0.1;
x=1:h:2;
[x,y]=ode45(Dy,x,[2 6])
plot(x,y(:,1),'or');
%%
%Diferencias Finitas
n=length(x);
y = sym('Y', [1 n]);
D2y=(y3-2*y2+y1)/h^2;
Dy=(y2-y1)/h;
f2=subs(f,{'Dy','D2y'},{Dy,D2y});
x(1)=1;
x(n)=2;
y(1)=2;
y(n)=6;
for i=1:n-2
f4(i,1)=subs(f2,{y1,y2,y3,'x','y'},{y(i),y(i+1),y(i+2),x(i),y(i)});
end
Rs=symvar(f4);
[ Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10]=solve(f4);
digits(3)
y=vpa(eval(y));
plot(x,y,'--r')

Ecuacion ;y= x’+y’+x-3, x= x’-y’-y+3


clear;clc;clf
syms Dx Dy x y x1 x2 y1 y2 real
f1=Dx+Dy+x-y-3;
f2=Dx-Dy-x-y+3;
[x,y]=dsolve(f1,f2)
C=symvar(x);
x=subs(x,C,[1,1]);
y=subs(y,C,[1,1]);
to=0;tf=10;
hold on
fplot(char(x),[to tf])
fplot(char(y),[to tf],'r')
h=0.2;
t=to:h:tf;
n=length(t);
x(1,[1,n])=subs(x,'t',[to tf]);
y(1,[1,n])=subs(y,'t',[to tf]);
x=vpa(x);y=vpa(y);
X=sym('X',[1 n]);Y=sym('Y',[1 n]);
vx=find(x==0);vy=find(y==0);
x(:,vx)=X(:,vx);y(:,vy)=Y(:,vy);
Dy=(sym('y(i+1)')-sym('y(i)'))/h;
Dx=(sym('x(i+1)')-sym('x(i)'))/h;
f3=subs(f1,{'Dx','Dy'},{Dx,Dy});
f4=subs(f2,{'Dx','Dy'},{Dx,Dy});
m=length(symvar(x));
for i=1:m
f5(i,1)=subs(f3,{'x','x(i)','x(i+1)','y','y(i)','y(i+1)'}....
,{x(i),x(i),x(i+1),y(i),y(i),y(i+1)});
f6(i,1)=subs(f4,{'x','x(i)','x(i+1)','y','y(i)','y(i+1)'}....
,{x(i),x(i),x(i+1),y(i),y(i),y(i+1)});
end
R=symvar([f5,f6]);
Solucion=solve(f5,f6);
Rs=cell2num(struct2cell(Solucion));
x=subs(x,R,Rs')
y=subs(y,R,Rs')
plot(t,eval(x),'--')
plot(t,eval(y),'--r')

Encontrar la distribución de temperaturas de una placa rectangular de


acero, si los extremos están a las temperaturas T0, T1 , T2, T3
To 0 °C
T1 0 °C
T2 0 °C
T3 300 °C

clear;clc;
syms To n w L k x y
w=L
x=3*L/4;y=3*L/4;
To=100;
T=(4*To/pi)*sin((2*k+1)*pi*x/L)*sinh((2*k+1)*pi*y/L)/((2*k+1)*sinh((2*k+1
)*pi*w/(L)))
digits(5)
Temp=vpa(symsum(T,k,0,Inf))

clear;clc;
syms D2Ux D2Uy
f=D2Ux+D2Uy;
n=4; %Divisiones en la placa
dx=1/n;
dy=dx;
D2Ux=(sym('U(i+1,j)')-2*sym('U(i,j)')+sym('U(i-1,j)'))/dx^2;
D2Uy=(sym('U(i,j+1)')-2*sym('U(i,j)')+sym('U(i,j-1)'))/dy^2;
f=subs(f,{'D2Ux','D2Uy'},{D2Ux,D2Uy});
U = sym('T', [n+1 n+1]); %n+1 número de nodos
U(:,[1 n+1])=0;
U(1,:)=100;
U(n+1,:)=0;
for i=2:n
for j=2:n
F(i,j)=subs(f,{'U(i,j)','U(i+1,j)','U(i,j+1)','U(i-1,j)','U(i,j-
1)'},{U(i,j),U(i+1,j),U(i,j+1),U(i-1,j),U(i,j-1)});
end
end
F(1,:)=[];
F(:,1)=[];
S=findsym(F)
T=symvar(F);
R=vpa(cell2num(struct2cell(solve(F))),5);
U=subs(U,T,R)
Encontrar la distribución de temperaturas de una placa rectangular de acero si en
uno de sus extremos tenemos un flujo qo de entrada y si los extremos están a las
temperaturas T0, T1 , T2.

To -100 °C
T1 0 °C
Qo -100W
T2 100°C

syms T
format compact
Q=-100;
qo=Q/3;
h=0.25;
k=60.5;
n=5;
T=T*ones(n+1,n+1)
T = sym('T', [n+1 n+1])
T(:,1)=-100;
T(:,5)=100;
T(5,:)=0
for i=2:n
f(i,1)=3*T(1,i)-4*T(2,i)+T(3,i)-2*h*qo/(3*k)
end
for i=2:n
for j=2:n
F(i,j)=T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1)-4*T(i,j)
end
end
F(n,:)=[]
F(:,n)=[]
H=symvar(F);
[T1_2 T1_3 T1_4 T2_2 T2_3 T2_4 T3_2 T3_3 T3_4 T4_2 T4_3
T4_4]=solve(f(2,1),f(3,1),f(4,1),F(2,2),F(2,3),F(2,4),F(3,2),F(3,3),F(3,4
),F(4,2),F(4,3),F(4,4))
[conj(H)' eval(H')]

Análisis transitorio del telegrafo


n=4
a=5e-6;%m/s
c=0.0046
dx=1/3;
dt=dx/(2*c)
U = sym('U', [n n])
U(:,1)=0;
U(1,:)=0;
U(4,:)=0
for i=2:3
for j=2:3
f(i,j)=2*dt^2*c^2*(U(i+1,j)-2*U(i,j)+U(i-1,j))-........
2*dx^2*(U(i,j+1)-2*U(i,j)+U(i,j-1))-....
dx^2*dt*(U(i,j+1)-U(i,j-1))-.....
2*dx^2*dt^2*U(i,j)
end
end
f1=U(2,4)-U(2,3);
f2=(U(3,4)-U(3,3))/dt-0.25;
V=symvar(f)
[U2_2 U2_3 U2_4 U3_2 U3_3 U3_4]=solve(f(2,2),f(2,3),f(3,2),f(3,3),f1,f2);
format short
eval([U2_2 U2_3 U2_4 U3_2 U3_3 U3_4]')

Transformada de Laplace
syms t Y1
k=1000; %N/m
c=2;%Ns/m
m=10;%kg
v=1;%m/s
h=0.4;%m
L=2;%m
y1=sym('y1(t)');
y2=sym('y2(t)');
dy1=sym('diff(y1(t),t)');
dy2=sym('diff(y2(t),t)');
d2y1=diff(dy1,t);
f1=-k*(y1-y2)-c*(dy1-dy2)-m*d2y1;
t1=(L/v);
y2=(h/t1)*t-(h/t1)*heaviside(t - t1)*(t - t1)
dy2=diff(y2,t);
Ly2=laplace(y2)
Lf1=laplace(f1)
Fs=subs({Lf1},{'y1(0)','y2(0)','D(y1)(0)','laplace(y1(t), t,
s)','laplace(y2(t), t, s)'},{0,0,0,'Y1',Ly2})
f1=solve(Fs,Y1)
iLf1=ilaplace(f1)
fplot(char(iLf1),[0 10])
hold on
fplot(char(y2),[0 10],'r')

También podría gustarte