Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Y f
a ab b X
2
y(u) | x h
x
2x h
(x h x) f
2
, y(
2x h
2
)
h h
y(x h) y(x) h f x , y(x )
2 2
Aplicando el método de Euler a y(x+h/2) se obtiene
h h
y(x h) y(x) h f x , y(x) f (x, y(x))
2 2
h h
y(x i h) y(x i ) h f x i , y(x i ) f (x i , y(x i ))
2 2
Ahora hacemos w i y(x i ) y obtenemos
w0
h h i=0,...,n-1
w i 1 w i h f x i 2 , w i 2 f (x i , w i )
w0
k1 h f (x i , w i )
o h 1 i=0,...,n-1
k 2 h f x i 2 , w i 2 k1
w i 1 w i k 2
b ba
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
a
g(x)dx
2
[g(a) g(b)]
InitializeDrawingArea(); Del problema (P) tenemos
} x h x h
Graphics oGraphics; h
oGraphics = Graphics.FromImage(area);
y(x h) y(x)
2
f (x, y(x)) f (x h, y(x h))
myPen.Color = Color.AliceBlue; Aplicando el método de Euler a y(x+h) se tiene
for ( int x = 0; x < this.Width; x++) { h
oGraphics.DrawLine(myPen, x, 0, x, this.Height); y(x h) y(x) f (x, y(x)) f (x h, y(x) hf (x, y(x)))
2
}
h
//oGraphics.Dispose(); y(x i h) y(x i ) f (x i , y(x i )) f (x i h, y(x i ) hf (x i , y(x i )))
//this.Invalidate(); 2
} Haciendo w i y(x i ) tenemos
w0
private void Form1_Paint(object sender,
h
w i 1 w i 2 f (x i , w i ) f (x i 1 , w i h f (x i , w i ))
System.Windows.Forms.PaintEventArgs e) {
Graphics g=e.Graphics;
g.DrawImage( area,
450,90, w0
area.Width,
area.Height); k1 h f (x i , w i )
//g.Dispose(); o k 2 h f x i h, w i k1 i=0,...,n-1
}
w w 1 [k k ]
i 1 i
2
1 2
h
y(x h) y(x) [f (x, y(x)) 4f (x h2 , y(x h2 )) f (x h, y(x h))]
6
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 4 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 25
l[i,i-1]=a[i,i-1]; h
l[i,i]=a[i,i]-l[i,i-1]*u[i-1,i]; y(x h) y(x) [f (x, y(x)) 2f (x h , y(x) h f (x, y(x)))
6 2 2
u[i,i+1]=a[i,i+1]/l[i,i];
} 2f (x h , y(x) h f (x h , y(x) h f (x, y(x)))
2 2 2 2
l[n-1,n-2]=a[n-1,n-2];
f (x h, y(x) h f (x h , y(x) h f (x h , y(x) h f (x, y(x))))]
l[n-1,n-1]=a[n-1,n-1]-l[n-1,n-2]*u[n-2,n-1]; 2 2 2 2
//Resuelve el sistema Av=b Luego, sustituyendo x=xi wiy(xi) en la ecuación anterior y haciendo la
//donde A=LU asignación respectiva se obtiene el esquema de Runge-Kutta
//Primero se resuelve Lz=b w0
z[0]=a[0,n]/l[0,0]; k
for(int i=1;i<=n-1;i++) 1 h f (x i , w i )
z[i]=(a[i,n]-l[i,i-1]*z[i-1])/l[i,i]; k h f x i 12 h, w i 12 k1
//Resuelve Uv=z 2
v[n-1]=z[n-1]; k3 h f x i 12 h, w i 12 k 2 i=0,...,n-1
w[n]=w[n]+v[n-1]; k4 h f (x i h, w i k 3 )
for(int i=n-2;i>=0;i--){
1
v[i]=z[i]-u[i,i+1]*v[i+1]; w w i k1 2k 2 2k 3 k 4
w[i+1]=w[i+1]+v[i]; i 1 6
}
//calculo de la norma euclideana 7.3.5 ALGORITMO DEL MÉTODO DE RUNGE-KUTTA
double s=0; Entrada: a, b, valor, n
for(int i=0;i<=n-1;i++) h=(b-a)/n
s=s+Math.Pow(Math.Abs(v[i]),2); w=valor
double norma=Math.Sqrt(s); x=a
if(norma<tol){ Para i=1,...,n hacer
for(int i=0;i<=n+1;i++) { k1=h*f(x,w)
xx[i]=aa+i*(float)h; k2=h*f(x+h/2,w+k1/2)
listBox1.Items.Add("x["+i+"]="+xx[i]+" k3=h*f(x+h/2,w+k2/2)
"+"w["+i+"]="+w[i]+"\n"); k4=h*f(x+h,w+k3)
sr.WriteLine("{0}",xx[i]); w=w+(k1+2*k2+2*k3+k4)/6
} x=x+h
for(int i=0;i<=n+1;i++) { Salida: i, x, w
sr.WriteLine("{0}",w[i]); fin
}
break; 7.3.6 MÉTODO DE RUNGE KUTTA DE TERCER ORDEN
} w0
k=k+1;
} k1 f (x i , w i )
k 2 f (x i 2 h, w i 2 hk1 )
1 1
sr.Close();
} k f (x h, w hk 2hk )
private void button1_Click(object sender, System.EventArgs e){ 3 i i 1 2
textBoxA.Clear(); w i 1 w i h (k1 4k 2 k 3 )
6
textBoxB.Clear();
textBoxYa.Clear();
textBoxYb.Clear();
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 6 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 23
f (x
//almacenamiento de la matriz tridiagonal
Pq (x) p i , y(x p i )) L i (x) double x=aa+h;
i0 double t=(w[2]-ya)/(2*h);
q
x x p l a[0,0]=2+h*h*fy1(x,w[1],t);
donde Li (x) x l 0 p i x pl
a[0,1]=-1+(h/2)*fy2(x,w[1],t);
a[0,n]=-(2*w[1]-w[2]-ya+h*h*f(x,w[1],t));
l i
for(int i=2;i<=n-1;i++) {
Reemplazando en la ecuación (1): x=aa+i*h;
q
f (x
xpk xpk t=(w[i+1]-w[i-1])/(2*h);
y(x p k ) y(x p j )
xp j
Pq (x) dx
i0
p i , y(x p i ))
xp j
Li (x) dx a[i-1,i-1]=2+h*h*fy1(x,w[i],t);
a[i-1,i]=-1+(h/2)*fy2(x,w[i],t);
q a[i-1,i-2]=-1-(h/2)*fy2(x,w[i],t);
h i 0
qi f (x p i , y(x p i ))
}
a[i-1,n]=-(2*w[i]-w[i+1]-w[i-1]+h*h*f(x,w[i],t));
q x=b-h;
x x pm
x
xp k xpk
1 1
donde qi
h xp j
Li (x)dx
h xp j
m0 p i x pm
dx t=(yb-w[n-1])/(2*h);
a[n-1,n-1]=2+h*h*fy1(x,w[n],t);
mi a[n-1,n-2]=-1-(h/2)*fy2(x,w[n],t);
q
x mh x p a[n-1,n]=-(2*w[n]-w[n-1]-yb+h*h*f(x,w[n],t));
xpk
1
Sea x p m x p ( m)h qi dx //método de crout
h xp j (m i)h l[0,0]=a[0,0];
m0
mi u[0,1]=a[0,1]/l[0,0];
for(int i=1;i<=n-2;i++) {
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 22 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 7
printf("\n a(%2d,%2d)=%10.8f",i,j,a[i][j]); x xp
q
}
printf("\n");
Sea s
h
yp k yp j h
i 0
qi f (x p i , y(x p i ))
} q
m i ds
k
sm
donde qi
double f(double x,double y1, double y2){ j
m 0
return (32+2*x*x*x-y1*y2)/8; m i
}
double fy1(double x,double y1, double y2){ 1) MÉTODOS DE ADAMS-BASHFORTH (EXPLÍCITOS)
return -y2/8; k=1, j=0, q=0,1,2,3,…..
} q
m i ds
1
double fy2(double x,double y1, double y2){ sm
qi
return -y1/8; 0
m 0
} m i
qi \ i 0 1 2 3 4
PROGRAMA EN C#, QUE RESUELVE EL PROBLEMA LINEAL DE UNA 0i 1
ECUACION DIFERENCIAL ORDINARIA CON CONDICIONES DE 1i 3/2 -1/2
FRONTERA.
2i 23/12 -16/12 5/12
using System.IO;
namespace DifFinitasCSharp{ 3i 55/24 -59/24 37/24 -9/24
public class Form1 : System.Windows.Forms.Form { 4i 1901/720 -2774/720 2616/720 -1274/720 251/720
q
private Bitmap area;
private Pen myPen;
//Definición de funciones (o métodos)
y p 1 y p h
i 0
qi f (x p i , y(x p i ))
m i ds
0
sm
} qi
float g1(float x){ 1
m0
return (float)Math.Exp(-x*x)*(float)Math.Sin(x); mi
} qi \ i 0 1 2 3 4
private void ButtonCalcular_Click(object sender, System.EventArgs e){ 0i 1
float aa=Convert.ToSingle(textBoxA.Text); 1i 1/2 1/2
float b=Convert.ToSingle(textBoxB.Text); 2i 5/12 8/12 -1/12
double ya=Convert.ToDouble(textBoxYa.Text);
3i 9/24 19/24 -5/24 1/24
double yb=Convert.ToDouble(textBoxYb.Text);
int n=Convert.ToInt32(textBoxN.Text); 4i 251/720 646/720 -264/720 106/720 -19/720
q
int m=Convert.ToInt32(textBoxM.Text);
double tol=Convert.ToDouble(textBoxTol.Text); y p y p 1 h qi f (x p i , y(x p i ))
string arch=Convert.ToString(textBoxIa.Text); i 0
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 8 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 21
q l[i][i-1]=a[i][i-1];
y p 1 y p h
i 0
qi f (x p i , y(x p i )) l[i][i]=a[i][i]-l[i][i-1]*u[i-1][i];
u[i][i+1]=a[i][i+1]/l[i][i];
}
3) MÉTODOS DE NYSTROEM (EXPLÍCITO) l[n-1][n-2]=a[n-1][n-2];
k=1, j=1, q=0, 1, 2, …. l[n-1][n-1]=a[n-1][n-1]-l[n-1][n-2]*u[n-2][n-1];
q //Resuelve el sistema Av=b
m i ds
1
sm //donde A=LU
qi
1
m0
//Primero se resuelve Lz=b
mi z[0]=a[0][n]/l[0][0];
qi \ i 0 1 2 3 4 for(i=1;i<=n-1;i++)
0i 2 z[i]=(a[i][n]-l[i][i-1]*z[i-1])/l[i][i];
//Resuelve Uv=z
1i 2 0
v[n-1]=z[n-1];
2i 7/3 -2/3 1/3
w[n]=w[n]+v[n-1];
3i 8/3 -5/3 4/3 -1/3 for(i=n-2;i>=0;i--) {
4i 269/90 -266/90 294/90 -146/90 29/90 v[i]=z[i]-u[i][i+1]*v[i+1];
q
w[i+1]=w[i+1]+v[i];
y p 1 y p 1 h
i0
qi f (x p i , y(x p i )) }
//calculo de la norma euclideana
s=0;
4) MÉTODOS DE MILNE-THOMPOSON (IMPLÍCITO) for(i=0;i<=n-1;i++)
k=0, j=2, q=0, 1, 2, …. s=s+pow(fabs(v[i]),2);
q norma=sqrt(s);
sm
m i ds
0
qi printf("Solucion:\n");
2
m0 if(norma<tol){
mi for(i=0;i<=n+1;i++){
qi \ i 0 1 2 3 4 xx[i]=aa+i*h;
0i 0 printf("%3d %5.1f% 17.10f\n",i,xx[i],w[i]);
1i 0 2 }
2i 1/3 4/3 1/3 break;
3i 1/3 4/3 1/3 0 }
k=k+1;
4i 29/90 124/90 24/90 4/90 -1/90
q
}
//Imprime en pantalla los valores de la matriz: a
yp yp 2 h qi f (x p i , y(x p i )) printf("Matriz ampliada a:\n");
i0 for(i=0;i<=n-1;i++){
q
for(j=0;j<=n;j++)
yp 1 yp1 h i 0
qi f (x p i , y(x p i )) printf("%12.8f",a[i][j]);
printf("\n");
}
5) MÉTODO DE PREDICTOR-CORRECTOR //valores de la matriz ampliada
h printf("\n");
y%p 1 { y p
12
23f (x p , yp ) f (x p 1 , y p 1 ) 5f (x p 2 , y p 2 ) for(i=0;i<=n-1;i++) {
q 2 (A B)
for(j=0;j<=n;j++)
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 20 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 9
l[i]=new double[n]; h
u=new double*[n]; y%
p 1 { yp
24
9f (x p 1 , y%
p 1 ) 19f (x p , y p ) 5f (x p 1 , y p 1 ) f (x p 2 , y p 2 )
q 3 (A M)
for(i=0;i<n;i++)
u[i]=new double[n];
v=new double[n]; Esto es una combinación de los métodos de Adams-Bashforth para q=2 y Adam-
z=new double[n]; Moulton para q=3. En cada paso se necesita solamente dos evaluaciones de la
w=new double[n+2]; función f.
xx=new double[n+2];
//inicializacion de las matrices 6) OTRO MÉTODO DE PREDICTOR-CORRECTOR
h
for(i=0;i<=n-1;i++){
for(j=0;j<=n;j++)
y%p 1
{ y p 1 7f (x p , yp ) 2f (x p 1 , y p 1 ) f (x p 2 , y p 2 )
3
q 2 (N)
a[i][j]=0;
h
v[i]=0; y%
p 1 { yp
3
f (x p 1 , y%p 1 ) 4f (x p , y p ) f (x p 1 , y p 1 )
z[i]=0; q 3 (M T)
}
h=(b-aa)/(n+1); 7) DEFINICIÓN DE MÉTODO MULTIPASO LINEAL EN GENERAL
w[0]=alfa; Son de la forma:
w[n+1]=beta; w j r a r 1w j r L a 0 w j b r f (x j r , w j r ) L b0 f (x j , w j )
for(i=1;i<=n;i++)
w[i]=alfa+i*h*(beta-alfa)/(b-aa);
7.5 MÉTODOS DE DIFERENCIAS FINITAS PARA ECUACIONES
k=1;
DIFERENCIALES ORDINARIAS CON CONDICIONES DE
while(k<=m) {
FRONTERA
//almacenamiento de la matriz tridiagonal
x=aa+h;
7.5.1 PROBLEMA LINEAL
t=(w[2]-alfa)/(2*h);
Sea el problema lineal
a[0][0]=2+h*h*fy1(x,w[1],t);
a[0][1]=-1+(h/2)*fy2(x,w[1],t); y(x) p(x)y(x) q(x)y(x) r(x), a x b
a[0][n]=-(2*w[1]-w[2]-alfa+h*h*f(x,w[1],t)); y(a)
for(i=2;i<=n-1;i++){ y(b)
x=aa+i*h;
t=(w[i+1]-w[i-1])/(2*h); Dividamos [a, b] en n+1 subintervalos de igual longitud
a[i-1][i-1]=2+h*h*fy1(x,w[i],t); xi=a+ih, i=0,..., n+1
a[i-1][i]=-1+(h/2)*fy2(x,w[i],t); ba
h
a[i-1][i-2]=-1-(h/2)*fy2(x,w[i],t); n 1
a[i-1][n]=-(2*w[i]-w[i+1]-w[i-1]+h*h*f(x,w[i],t)); y(xi) wi
} 1 1
x=b-h; y(x i ) 2 y(x i 1 ) 2y(x i ) y(x i 1 ) 2 w i 1 2w i w i 1
h h
t=(beta-w[n-1])/(2*h);
1 1
a[n-1][n-1]=2+h*h*fy1(x,w[n],t); y(x i )
2h
y(x i 1 ) y(x i 1 ) 2h w i 1 w i 1
a[n-1][n-2]=-1-(h/2)*fy2(x,w[n],t);
a[n-1][n]=-(2*w[n]-w[n-1]-beta+h*h*f(x,w[n],t)); Al reemplazar estas afirmaciones en la ecuación diferencial se tiene
//método de crout y(x i ) p(x i )y(x i ) q(x i )y(x i ) r(x i )
l[0][0]=a[0][0]; w i 1 2w i w i 1 p(x i )[w i 1 w i 1 ]
u[0][1]=a[0][1]/l[0][0]; 2
q(x i )w i r(x i )
h 2h
for(i=1;i<=n-2;i++){
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 10 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 19
k4=h*fu(t+h,w+k3); fin
w=w+(k1+2*k2+2*k3+k4)/6; x=bb-h
t=a+(i+1)*h; an=2+h2q(x)
cout<<i+1<<" "<<t<<" "<<w<<" "<<endl; cn=-1-(h/2)p(x)
salida<<t<<" "<<w<<" "<<endl; dn=-h2r(x)+(1-(h/2)p(x))
} Resuelve el sistema tridiagonal usando el método de Crout
} l1=a1
u1=b1/a1
double fu(double t, double y){ para i=2,...,n-1 hacer
return y-t*t+1; li=ai – ciui-1
} ui=bi/li
fin
PROGRAMA PARA RESOLVER UN SISTEMA DE ECUACIONES ln=an - cnun-1
DIFERENCIALES ORD. CON EL MÉTODO RUNGE-KUTTA. z1=d1/l1
#include<iostream.h> para i=2,...,n hacer
const int m=1; zi=(di - cizi-1)/li
void fx(double t,double f[m+1],double w0,double w1){ fin
f[0]=-4*w0+3*w1+6; w0=
f[1]=-2.4*w0+1.6*w1+3.6; wn+1=
} wn=zn
void main(){ Para i=n-1,...,1 hacer
double a,b,h,t,f[m+1],alfa[m+1],k1[m+1],k2[m+1]; wi=zi – uiwi+1
double k3[m+1],k4[m+1],w0,w1,w[m+1]; fin
int n;
cout<<"Ingrese el intervalo [a,b]: "; 7.5.3 PROBLEMA NO LINEAL
cin>>a>>b; Sea el problema no lineal
cout<<"Ingrese los valores iniciales: ";
y(x) f (x, y(x), y(x)) a x b
for(int j=0;j<=m;j++)
cin>>alfa[j]; y(a)
cout<<"Ingrese el numero de subintervalos: "; y(b)
cin>>n;
Sean
h=(b-a)/n;
xi=a+ih, i=0,..., n+1
t=a;
for(j=0;j<=m;j++) w[j]=alfa[j]; ba
h
w0=w[0]; n 1
w1=w[1]; y(xi) wi
cout<<"i"<<" "<<"t"<<" "<<"w0"<<" "<<"w1"<<endl; Luego, de la ecuación diferencial se tiene
cout<<0<<" "<<t<<" "<<w0<<" "<<w1<<" "<<endl; y(x i ) f (x i , y(x i ), y(x i ))
for(int i=1;i<=n;i++){ w i 1 2w i w i 1 w w i 1
fx(t,f,w0,w1); f x i , w i , i 1
for(j=0;j<=m;j++) k1[j]=h*f[j]; h2 2h
fx(t+h/2,f,w0+k1[0]/2,w1+k1[1]/2);
for(j=0;j<=m;j++) k2[j]=h*f[j];
fx(t+h/2,f,w0+k2[0]/2,w1+k2[1]/2);
for(j=0;j<=m;j++) k3[j]=h*f[j];
Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 12 Dr. Pilar Nuñez B. Métodos Numéricos para Ecuaciones Diferenciales 17