Está en la página 1de 15

p1

E.T.S. DE INGENIEROS DE CAMINOS, C. Y P. UNIVERSIDAD DE CANTABRIA

AMPLIACIN DE MATEMTICAS, 2 CURSO DE ITOP


PRCTICAS DE LABORATORIO DE EDOs
Ej.: Resolver la ecuacin diferencial 1+exp(x)*cos(y)+exp(x)*sin(y)*y=0 .
Dibujar algunas curvas solucin.(KKM 16)
syms x y
y=dsolve('1+exp(x)*cos(y)+exp(x)*sin(y)*Dy=0','x')
y = pi-acos(1/2*(-2*C1+exp(-2*x))*exp(x))
figure,for C1=1:3,ezplot(eval(y)),...
3
hold on, grid on, end

-acos((-3+1/2 exp(-2 x)) exp(x))

2.5

1.5
1

0.5
0
-1.2

-1.1

-1

-0.9
x

-0.8

-0.7

-0.6

-0.5

Ej.: Resolver la ecuacin diferencial 1+exp(x)*cos(y)+exp(x)*sin(y)*y=0 ,


con y(0)=2
Dibujar la curva solucin y evaluarla para x=0.8, -1, x=2, x=4 y evaluar su
derivada para x=2
syms x y
y=dsolve('1+exp(x)*cos(y)+exp(x)*sin(y)*Dy=0','y(0)=2','x')
y = pi-acos(1/2*(-1-2*cos(2)+exp(-2*x))*exp(x)))
-acos(1/2 (-1-2 cos(2)+exp(-2 x)) exp(x))
figure,ezplot(y,[-0.8,2.8]),grid on
x=0.8,eval(y),x=-1,eval(y)
3
x = 0.8000
ans = 1.6089
2.5
x = -1
2
ans = 3.1416 - 0.7896i
x=2,eval(y),x=4,eval(y)
x = 2
ans = 0.9861
x = 4
ans = 0 + 2.2003i
Der1_y=diff(y,'x',1)

1.5

0.5
0
-0.5

0.5

1
x

1.5

Der1_y = 2*(-exp(-2*x)*exp(x)+1/2*(-1-2*cos(2)+exp(-2*x))*exp(x))/
(4-(-1-2*cos(2)+exp(-2*x))^2*exp(x)^2)^(1/2)
x=2;eval(Der1_y)
ans = -0.8242

2.5

p2

% * EJEMPLO DE TRAYECTORIAS ORTOGONALES


>> syms x y k;y=k*x^2

5/4 x 2
12

y =
k*x^2
>> yprima=diff('k*x^2','x')

10

yprima =
2*k*x
>> k=solve('yprima=2*k*x','k')

k =

1/2*yprima/x

>> edif=subs('y-k*x^2=0','k',k)
edif =

y-1/2*yprima*x = 0
>> edif_ortog=subs(edif,'yprima','-1/Dy')

-2

0
x

edif_ortog =
y-1/2*(-1/Dy)*x = 0
>> Dy=solve(edif_ortog,'Dy')
Dy =
-1/2/y*x
>> y_ortog=dsolve('Dy =-1/2/y*x','x')
y_ortog =
[ 1/2*(-2*x^2+4*C1)^(1/2)]
[ -1/2*(-2*x^2+4*C1)^(1/2)]
>> figure,for C1=1:6,ezplot(eval(y_ortog(1)),[-3,3]),axis square,
axis equal,hold on, grid on,end
>> for k=0.25:0.25:1.25,ezplot(eval(y),[-3,3]),hold on, grid on,end

p3

Ejemplos con Matlab, clase Mtodos Numricos:


______________________
Ej 22 hojas clase
>> dsolve('D2y*y=Dy^2+6*x*y^2','y(0)=1','Dy(0)=0','x')
ans = exp(x^3)
>> dsolve('D2y=Dy','y(0)=0','Dy(1)=1','x')
ans = -1/exp(1)+1/exp(1)*exp(x)
>> sol=simplify(ans)
sol = -exp(-1)+exp(x-1)
Ej libro Ex FinFeb 96
>> dsolve('D2y+(2/x)*Dy=0','y(1)=0','Dy(2)=1','x')
ans = 4-4/x
____________________
Exam Final MN Feb 02
>> misol=dsolve('x*D2y+(2*x-1)*Dy=-4*x^2','y(0)=0','Dy(1)=0','x')
misol = -x^2+1/2/exp(-2)-1/2/exp(-2)*(2*exp(-2*x)*x+exp(-2*x))
>> misol=simple(misol)
misol = -x^2+1/2*exp(2)-exp(2-2*x)*x-1/2*exp(2-2*x)
RESUELTO COMO SISTEMA
>> misol=dsolve('Dy1=y2','Dy2=-(2*x-1)*y2/x-4*x','y1(0)=0','y2(1)=0','x')
misol =
y1: [1x1 sym]
y2: [1x1 sym]
>> x=0.5; y0_5=eval(misol.y1), yprima_0_5=eval(misol.y2)
y0_5 = 0.7262
yprima_0_5 = 1.7183
>> simplify(misol.y1)
ans = -x^2-x*exp(2-2*x)+1/2*exp(2)-1/2*exp(2-2*x)
>> misol1=simplify(misol.y1)
misol1 = -x^2-x*exp(2-2*x)+1/2*exp(2)-1/2*exp(2-2*x)
>> misol.y1
ans = -x^2-1/exp(-2)*exp(-2*x)*x+1/2/exp(-2)-1/2/exp(-2)*exp(-2*x)
>> diff(misol1,'x')
ans = -2*x+2*x*exp(2-2*x)
>> simplify(misol.y2)
ans = 2*x*(-1+exp(2-2*x))

p4

Ex Sep 96, Feb 87, Hojas clase, Blasius


>> dsolve('z*D2z+2*D3z=0','z(0)=0','Dz(0)=0','D2z(0)=1/2','x')
Warning: Explicit solution could not be found.
> In C:\MATLAB6p5_Pablo030506\toolbox\symbolic\dsolve.m at line 326
ans =
[ empty sym ]
>>

Valor inicial, Sep 99


y''+9y=36exp(3x), y(0)=2, y'(0)=6, y exacta= 2exp(3x)
Directamente:
>> sol=dsolve('D2y+9*y=36*exp(3*x)','y(0)=2','Dy(0)=6','x')
sol =
(2*cos(3*x)*exp(3*x)+2*sin(3*x)*exp(3*x))*sin(3*x)+(2*cos(3*x)*exp(3*x)2*sin(3*x)*exp(3*x))*cos(3*x)
>> sol=simplify(sol)
sol = 2*exp(3*x)
COMO SISTEMA:
>> misol=dsolve('Dy1=y2','Dy2=-9*y1+36*exp(3*x)','y1(0)=2','y2(0)=6','x')
misol =
y1: [1x1 sym]
y2: [1x1 sym]
>> misol_1=simplify(misol.y1)
misol_1 = 2*exp(3*x)
>> misol_2=simplify(misol.y2)
misol_2 = 6*exp(3*x)
>> diff(misol_1,'x')
ans = 6*exp(3*x)
>>

p5

EDO , problema de valor inicial (Problema de Cauchy)


EDO 1er orden, explcita:
y= f(x,y), x [a,b], y(a)=
Obsrvese que la EDO nos da las derivadas sucesivas de y
respecto de x: y(x)= f(x,y(x)),
y(x)= fx(x,y(x)) + fy(x,y(x))*dy/dx =
y(x)= fx(x,y(x)) + fy(x,y(x))* f(x,y(x))
y(x)= fxx+fxy*dy/dx+fyx*f +fyy*dy/dx*f+fy*fx+fy*fy*dy/dx =
y(x)= fxx+fxy*f + fyx*f +fyy*f*f+fy*fx+fy*fy*f =
y(x)= fxx + 2*fxy*f + fyy*f2 + fy*fx + fy2*f
etc.
Resolucin numrica PASO a PASO (mtodos de Taylor, 1 paso)
y(c+h)= y(c)+ y(c)*h/1! + y(c)*h2/2! + y(c)*h3/3! +
+ yiv(c)*h4/4! +...
y(c+h)= y(c)+ y(c)*h/1! + y(c)*h2/2! + y(c)*h3/3! +
+ yiv(c)*h4/4! + (h5)
ERROR DE TRUNCATURA LOCAL:
h
x0=a

h
x1

(h5)

h
x2

...
...

xi

xi+1

...

Mtodo de Taylor de orden 1 (Euler)


yi+1= yi+ yi*h/1!
yi+1= yi+ f(xi,yi)*h
y0 =

De la EDO,

yi= f(xi,yi)

, i=0,1,2,...
yi aproxima a y(xi)
Error Trunc Local: (h2)

Mtodo de Taylor de orden 2


yi+1= yi+ yi*h/1! + yi*h2/2!
De la EDO:
yi= f(xi,yi),
yi= fx(xi,yi)+ fy(xi,yi)* f(xi,yi)
y0 =

i=0,1,2,... Error Trunc Local:

(h3)

p6

EDO , problema de valor inicial (Problema de Cauchy)


EDO 1er orden, explcita:
y= f(x,y), x en [a,b], y(a)=
Para evitar el clculo de derivadas sucesivas de los mtodos de
Taylor: Mtodos paso a paso (de 1 paso) de Runge-Kutta.

Algunos mtodos de RungeKutta:


Orden 2 (Error de Truncatura Local:

(h3))

Mtodo de la tangente media o Mtodo de Euler mejorado:


yi+1= yi+ [f(xi,yi)+f(xi+1,yi+h*f(xi,yi))]*h/2
y0 =
i=0,1,2,...
Mtodo de la tangente en el punto medio o Mtodo de Euler
modificado:
yi+1= yi+ h*[f(xi+h/2,yi+(h/2)*f(xi,yi))]
y0 =
i=0,1,2,...

Orden 4 (Error de Truncatura Local:

(h5))

Mtodo de Runge Kutta Clsico de orden 4:


yi+1= yi+ (h/6)*(K1+2*K2+2*K3+K4)
siendo:
K1
K2
K3
K4

=
=
=
=

f(xi,yi)
f(xi+(h/2),yi+(h/2)*K1)
f(xi+(h/2),yi+(h/2)*K2)
f(xi+h,yi+h*K3)

y0 =

i=0,1,2,...

p7

Sistema de EDO:
y1 = f1(x,y1,y2)
y2 = f2(x,y1,y2)

Y=F(x,Y),

Y=[y1,y2],
F=[f1(x,Y),f2(x,Y)]

Var indep: x [a,b],


h

y1(a)=1
y2(a)=2
x0=a

h
x2

x1

...
...

xi

xi+1

...

Taylor orden 1 (Euler)


y1i+1= y1i+ y1i*h/1!
y2i+1= y2i+ y2i*h/1!

Yi+1= Yi + F(x,Y)*h/1!

y1i+1= y1i+ f1(xi,y1i,y2i)*h ,


y2i+1= y2i+ f2(xi,y1i,y2i)*h ,

i=0,1,2,...

y0 = ,

y1i , y2i aproximan a y1(xi), y2(xi)


y10= 1 , y20= 2

Taylor orden 2

Yi+1= Yi + F(x,Y)*h/1! + F(x,Y)*h2/2!

y1i+1= y1i+ y1i*h/1! + y1i*h2/2!


y2i+1= y2i+ y2i*h/1! + y2i*h2/2!
siendo
y1i= f1(xi,y1i,y2i)
y1i= f1x(xi,y1i,y2i)+f1y1(xi,y1i,y2i)*f1(xi,y1i,y2i)+
+f1y2(xi,y1i,y2i)*f2(xi,y1i,y2i)
y2i= f2(xi,y1i,y2i)
y2i= f2x(xi,y1i,y2i)+f2y1(xi,y1i,y2i)*f1(xi,y1i,y2i)+
+f2y2(xi,y1i,y2i)*f2(xi,y1i,y2i)
i=0,1,2,...
y10 = y1(a)= 1
y20 = y2(a)= 2

(Error Truncatura Local en y1 e y2:

(h3))

p8

EDO explcita de orden p, Problema de Cauchy:


y(p = f(x,y,y,y,...,y(p-1)
Var indep: x en [a,b],
y condic inic.: y(a)=1, y(a)=2, y(a)=3,..., y(p-1(a)=p
Cambio de variable dependiente:
y1(x)=y(x), y2(x)=y(x), y3(x)=y(x),... yp(x)=y(p-1(x)
Resulta el sistema de EDOs, con Variable indep: x en [a,b]:
y1= y2 ,

Cond iniciales:

y1(a)=1

y2= y3 ,

y2(a)=2

y3= y4 ,

y3(a)=3

...

...

yp= f(x,y1,y2,...,yp),

yp(a)=p

Ejemplo: Taylor orden 2 para y=f(x,y,y), x [a,b]


y(a)=1
y(a)=2
SISTEMA:

y1=y2,
y2=f(x,y1,y2)
{

y1=y2, y1=y2= f(x,y1,y2)


y2=f(x,y1,y2),

y2= fx(x,y1,y2)+fy1(x,y1,y2)*y2+ fy2(x,y1,y2)*f(x,y1,y2)


h
x0=a

h
x1

h
x2

..
.

xi

xi+1

..
.. .
.

y1i+1= y1i+y1i*h+y1i*h2/2
y2i+1= y2i+y2i*h+ y2i*h2/2
y1i=y2i

tomando:

y2i =f(xi,y1i,y2i)

y1i=f(xi,y1i,y2i)

y2i=fx(xi,y1i,y2i)+fy1(xi,y1i,y2i)*y2i+fy2(xi,y1i,y2i)*f(xi,y1i,y2i)
para i=0,1,2,...
y10 = y1(a)= 1
y20 = y2(a)= 2

(Error Truncatura Local en y1 e y2:

(h3))

p9

p 10

% EjLab1basicoTaylor1, (Euler) paso a paso, basico


% yi+1=yi+h*y'i
% y'=x-y , x en [0,1.2], y(0)=1
clear all,close all
yexacta=inline('2*exp(-x)+x-1','x');
yp=inline('x-y','x','y')
x(1)=0;yaprox(1)=1;error(1)=0;
h=0.1
npasos=round(1.2/h);
for i=1:npasos
x(i+1)=x(i)+h;
yaprox(i+1)=yaprox(i)+h*yp(x(i),yaprox(i));
end
yex=yexacta(x);error=yex-yaprox;
[x',yaprox',yex',error']
figure,plot(x,yaprox,'.r',x,yex,'bo'),grid on
RESULTADO:
yp =
Inline function:
yp(x,y) = x-y
h =
ans =

1
0.95

0.1000

0
0.1000
0.2000
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
1.1000
1.2000

1.0000
0.9000
0.8200
0.7580
0.7122
0.6810
0.6629
0.6566
0.6609
0.6748
0.6974
0.7276
0.7649

1.0000
0.9097
0.8375
0.7816
0.7406
0.7131
0.6976
0.6932
0.6987
0.7131
0.7358
0.7657
0.8024

0
0.0097
0.0175
0.0236
0.0284
0.0321
0.0347
0.0366
0.0377
0.0383
0.0384
0.0381
0.0375

% EjLab2basicoTaylor2, paso a paso


% yi+1=yi+h*y'i+(h^2/2)*y''i
% y'=x-y , x en [0,1.2], y(0)=1

0.9
0.85
0.8
0.75
0.7
0.65

0.2

0.4

0.6

0.8

1.2

1.4

0.95
0.9

clear all,close all


yexacta=inline('2*exp(-x)+x-1','x');0.85
yp=inline('x-y','x','y')
ypp=inline('1-x+y','x','y')

0.8
0.75

x(1)=0;yaprox(1)=1;error(1)=0;
0.7
h=0.1
npasos=round(1.2/h);
0.65
for i=1:npasos
0
0.2
0.4
0.6
0.8
1
1.2
1.4
x(i+1)=x(i)+h;
yaprox(i+1)=yaprox(i)+h*yp(x(i),yaprox(i))+h^2/2*ypp(x(i),yaprox(i));
end
yex=yexacta(x);error=yex-yaprox;
[x',yaprox',yex',error']
figure,plot(x,yaprox,'.r',x,yex,'bo'),grid on

p 11

HAY 3 ARCHIVOS IMPLICADOS

1) Programa principal -------------------% prEj1Sis2RK2, Integra Ej sist EDO val inicial RK2 tg p medio
% Mtodo de la tangente en punto medio
% yi+1= yi+ h*[f(xi+h/2,yi+(h/2)*f(xi,yi))]
% y0 = ?
i=0,1,2,...
% ec. dif: y''+9y=36exp(3x), y(0)=2, y'(0)=6, y exacta= 2exp(3x)
yaprox +, yexac o
% despejando y'': y''=-9y+36exp(3x)
45
140
% Como sistema:y1'=y2, y2'=-9y1+36exp(3x)
40
% y1(0)=2, y2(0)=6
120
clear all;close all
35
% condiciones iniciales:
100
xini=0;xfin=1;y10=2;y20=6; %(seg,m)
30
h=0.1 % paso
80
25
npasos=round((xfin-xini)/h);
yini=[y10;y20];% vector columna
20
60
xim1=xini;yim1=yini;ytotal=yini;xtotal=xini;
15
for i=1:npasos
40
[yim1,xim1]=RK2_TgMedia1paso(xim1,yim1,h);
10
% ytotal: mat 2 filas, xtotal: vec fila
20
ytotal=[ytotal,yim1];xtotal=[xtotal,xim1]; 5
end
0
0
yexact=2*exp(3*xtotal); ypexact=6*exp(3*xtotal);
0
0.5
1
0
Eje X
figure
subplot(1,2,1),plot(xtotal,ytotal(1,:),'r+',...
xtotal,yexact(1,:),'bo'),title('yaprox +, yexac o'),...
grid on,xlabel('Eje X')
subplot(1,2,2),plot(xtotal,ytotal(2,:),'r+',...
xtotal,ypexact(1,:),'bo'),title('yprim aprox +, yprim exac o')
grid on,xlabel('Eje X')
disp('x,yaprox,yprim aprox,yexact, yprim exact')
resumen=[xtotal',ytotal',yexact',ypexact']
2) Funcin para el sistema de EDOs -------------------% funcion fEDOsis define sistema EDOs
% yprima=f(x,y)
% y''+9y=36exp(3x), y(0)=2, y'(0)=6, y exacta= 2exp(3x)
% y exacta= 2exp(3x)
function yprima=fEDOsis(x,y)
yprima(1,1)=y(2);%yprima vector columna
yprima(2,1)=-9*y(1)+36*exp(3*x);
3) 3 Funcin un paso RK2 tag pto medio -------------------% funcion RK2_TgMedia1paso vector sistem EDO,1 paso
% xn,xnm1:abs inic,fin paso,
%yn,ynm1:ord inic,fin paso; h:tamao paso;
function [yim1,xim1] = RK2_TgMedia1paso(xi,yi,h)
% Mtodo de la tangente en punto medio
% yi+1= yi+ h*[f(xi+h/2,yi+(h/2)*f(xi,yi))]
yim1=yi+h*fEDOsis(xi+h/2,yi+(h/2)*fEDOsis(xi,yi));
xim1=xi+h;
-------------------RESULTADO:
h =
0.2000
x,yaprox,yprim aprox,yexact, yprim exact
resumen =
0
2.0000
6.0000
2.0000
6.0000
0.2000
3.5600
11.0390
3.6442
10.9327
0.4000
6.4389
20.3531
6.6402
19.9207
0.6000
11.7410
37.3677
12.0993
36.2979
0.8000
21.4569
68.3041
22.0464
66.1391
1.0000
39.1922 124.5209
40.1711 120.5132

yprim aprox +, yprim exac o

0.5
Eje X

p 12

% DERIVACIN NUMRICA (formulas de tipo interpolatorio polinomial)


>> f=inline('sin(x).*cos(x)','x')
f = Inline function:
f(x) = sin(x).*cos(x)
>> fpexacta=inline('cos(x).^2-sin(x).^2','x')
fpexacta = Inline function:
fpexacta(x) = cos(x).^2-sin(x).^2
>> c=2
c= 2
>> h=[0.01;0.1;0.2]
h=
0.0100
0.1000
0.2000
% frmul bilat centrada 2 puntos, Error=-f()h 2/6, frmul unilateral 2 puntos, Error O(h)
>> [(f(c+h)-f(c-h))./(2*h),(f(c+h)-f(c))./h,fpexacta(c)*ones(length(h),1)]
ans =
-0.6536 -0.6460 -0.6536
-0.6493 -0.5739 -0.6536
-0.6364 -0.4870 -0.6536
>> format long e
>> h=0.01;
>> [(f(c+h)-f(c-h))/(2*h),fpexacta(c)]
ans = -6.536000454937324e-001 -6.536436208636119e-001
>> [(f(c)-f(c-h))/h,fpexacta(c)] % frmula unilateral 2 ptos, Error O(h)
ans = -6.611678181826897e-001 -6.536436208636119e-001
>> [(-f(c-2*h)+4*f(c-h)-3*f(c))/(-2*h),fpexacta(c)] % frmula bilateral 3 ptos , Error=f()h 2/3
ans = -6.537322746496543e-001 -6.536436208636119e-001
>> [(-f(c+2*h)+4*f(c+h)-3*f(c))/(2*h),fpexacta(c)] % frmula bilateral 3 ptos , Error=f()h 2/3
ans = -6.537292476414436e-001 -6.536436208636119e-001
% Deriv 2a, frmula centrada, 3 ptos, f(c)~(f(c-h)-2f(c)+f(c+h))/(h^2), Error =f (iv()h2/12
>> aux1=sin(c+h)*cos(c+h);aux2=sin(c)*cos(c);aux3=sin(c-h)*cos(c-h);
>> fppaprox=(aux1-2*aux2+aux3)/(h^2)
fppaprox = 1.513554537791451e+000
>> fppexacta=2*cos(c)*(-sin(c))-2*sin(c)*cos(c)
fppexacta = 1.513604990615857e+000

p 13

EDO: DIFERENCIAS FINITAS, problema de CONTORNO

. . . . . .

y=f(x) , x en [a,b], y(a)=alfa, y(b)=beta

------ ------ ------ ------ -----i-1

h = (b-a)/n , n=n subinterv, n+1 = nm ptos discret,


yi=(yi+1-2*yi+yi-1)/h^2,

(Error: O(h^2)

i+1

x=a

x=b

yi aprox a y(xi).

y(xi)=f(xi)

Planteamos 1 ecuacin por cada pto discret. Sistema de ecuaciones M yaprox=b:


1 ecuacin en x1=a :

y1 = alfa

Ecuacin i=2,3,,n

yi-1 - 2yi + yi+1 = f(xi)*h^2

n ecuacin en xn+1=b :

yn+1 = beta

Para n=5 subintervalos:

M
1
1
0
0
0
0

0
-2
1
0
0
0

0
1
-2
1
0
0

yaprox
0
0
1
-2
1
0

0
0
0
1
-2
0

0
0
0
0
1
1

y1
y2
y3
y4
y5
y6

b
alfa
f(x2)*h^2
f(x3)*h^2
f(x4)*h^2
f(x5)*h^2
beta

Sistema de ecuaciones lineales. Matriz de coeficientes tipo banda, dispersa, sparse, con
muchos ceros
Programa Matlab:
% prContorno1DifFinitas y=f(x) DIFERENCIAS FINITAS, BASICO
clear all,close all
a=0;b=10;alfa=0;beta=0;
L=b-a;
n=10;h=(b-a)/n;
f=inline('x*(L-x)','x','L')
x=linspace(a,b,n+1);
M=zeros(n+1,n+1);% construir matriz coef M
M(1,1)=1;M(n+1,n+1)=1;b(1)=alfa;b(n+1)=beta;
for i=2:n
M(i,[i-1,i,i+1])=[1,-2,1];
b(i)=f(x(i),L)*h^2;
end
M,b
% Escribimos en Ventana Comandos matriz coef y vector indep
yaprox=M\b'; % resolucion sistema ecuaciones lineales
yexacta=L*x.^3/6-x.^4/12-L^3*x/12; % calculo solucion exacta
% Escritura y dibujo de resultados
disp('x, yaprox,yexacta'),[x',yaprox,yexacta']
figure,plot(x,yaprox,'k+',x,yexacta,'or'),grid on

p 14

EJECUCIN:
f =
Inline function:
f(x,L) = x*(L-x)
M =
1
1
0
0
0
0
0
0
0
0
0

0
-2
1
0
0
0
0
0
0
0
0

0
1
-2
1
0
0
0
0
0
0
0

0
0
1
-2
1
0
0
0
0
0
0

0
0
0
1
-2
1
0
0
0
0
0

0
0
0
0
1
-2
1
0
0
0
0

0
0
0
0
0
1
-2
1
0
0
0

0
0
0
0
0
0
1
-2
1
0
0

0
0
0
0
0
0
0
1
-2
1
0

0
0
0
0
0
0
0
0
1
-2
0

0
0
0
0
0
0
0
0
0
1
1

16

21

24

25

24

21

16

b =

x, yaprox,yexacta
ans =
0
1.0000
2.0000
3.0000
4.0000
5.0000
6.0000
7.0000
8.0000
9.0000
10.0000

-50

0
-82.5000
-156.0000
-213.5000
-250.0000
-262.5000
-250.0000
-213.5000
-156.0000
-82.5000
0

0
-81.7500
-154.6667
-211.7500
-248.0000
-260.4167
-248.0000
-211.7500
-154.6667
-81.7500
0

-100

-150

-200

-250

-300

>>

Ejemplo: Ecuacin de la viga de longitud L, en trminos de la derivada segunda de la ley de


flechas y(x), y la ley de momentos flectores M(x)
y(x)=M(x)/(E*I) , x en [0, L]
E: mdulo de elasticidad del material, I: momento de inercia de la seccin transversal de la
viga
Viga biapoyada de longitud L:
Mnsula empotrada en x=0;

y(0)=0,
y(0)=0,

y(L)=0

y(0)=0

10

p 15

% Ej Lab1 TAYLOR 1 PASO A PASO, BASICO


% y'=x-y , x en [0,1.2], y(0)=1,
clear all
x(1)=0,yaprox(1)=1;yexacta(1)=2*exp(-x(1))+x(1)-1;error(1)=0;
h=0.01
npasos=round(1.2/h);
for i=1:npasos
x(i+1)=x(i)+h;
yaprox(i+1)=yaprox(i)+h*(x(i)-yaprox(i));
yexacta(i+1)=2*exp(-x(i+1))+x(i+1)-1;
error(i+1)=yexacta(i+1)-yaprox(i+1);
end
x,yaprox,yexacta,error

% Contorno y=f(x) DIFERENCIAS FINITAS, BASICO


clear all
n=10;L=5;h=L/n;
f=inline('x*(L-x)','x','L')
x(1)=0;
for i=2:n+1,
x(i)=x(i-1)+h;
end
x
M=zeros(n+1,n+1);
M(1,1)=1;M(n+1,n+1)=1;
for i=2:n,
M(i,[i-1,i,i+1])=[1,-2,1];
end
M
b(1)=0;b(n+1)=0;
for i=2:n,
b(i)=f(x(i),L)*h^2;
end
b
yaprox=M\b'
yexacta=L*x.^3/6-x.^4/12-L^3*x/12

También podría gustarte