Você está na página 1de 16

y

dy s e n2 x e
= =f ( x , y )
d x c o s x ( y2 y− y )

function euler
clc, clear
syms x y
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=input('ingrese el valor de x inicial=');
xf=input('ingrese el valor de x final=');
y=input('ingrese el valor de y inicial=');
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x(n) y(n)')
for i=1:n+1;
y1=feval(f,x,y);
hy1=h*y1;
fprintf('\n%0.5f %0.5f',x,y)
y=y+hy1;
x=x+h;
end

corrida

ingrese la ecuacion diferencial:(sin(2*x)*exp(y))/(cos(x)*(exp(2*y)-y))

ingrese el valor de x inicial=0

ingrese el valor de x final=1

ingrese el valor de y inicial=2

ingrese la cantidad de intervalos=10

h=

0.1000

x(n) y(n)

0.00000 2.00000

0.10000 2.00000

0.20000 2.00280

0.30000 2.00837
0.40000 2.01660

0.50000 2.02735

0.60000 2.04044

0.70000 2.05564

0.80000 2.07271

0.90000 2.09138

1.00000 2.11136>>

function taylor
clc, clear
syms x y
F=(sin(2*x)*exp(y))/(cos(x)*(exp(2*y)-y));
a=diff(F,x)
b=diff(F,y)
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=0;
xf=1;
y=2;
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x(n) y(n)')
for i=1:n+1;
a1=eval(a);
b1=eval(b);
F1=eval(F);
y1=feval(f,x,y);
hy1=h*y1+(h/2)*(a1-b1*F1);
fprintf('\n%0.5f %0.5f %0.5f %0.5f %0.5f',a1,b1,F1,x,y)
y=y+hy1;
x=x+h;
end
corrida:

a=

- (2*cos(2*x)*exp(y))/(cos(x)*(y - exp(2*y))) - (sin(2*x)*exp(y)*sin(x))/(cos(x)^2*(y - exp(2*y)))

b=
- (sin(2*x)*exp(y))/(cos(x)*(y - exp(2*y))) - (sin(2*x)*exp(y)*(2*exp(2*y) - 1))/(cos(x)*(y -
exp(2*y))^2)

ingrese la ecuacion diferencial:(sin(2*x)*exp(y))/(cos(x)*(exp(2*y)-y))

ingrese la cantidad de intervalos=10

h=

0.1000

x(n) y(n)

0.28096 0.00000 0.00000 0.00000 2.00000

0.27544 -0.02918 0.02764 0.10000 2.01405

0.26660 -0.05700 0.05404 0.20000 2.03062

0.25475 -0.08300 0.07880 0.30000 2.04951

0.24026 -0.10683 0.10158 0.40000 2.07046

0.22352 -0.12822 0.12211 0.50000 2.09317

0.20495 -0.14699 0.14021 0.60000 2.11734

0.18496 -0.16305 0.15579 0.70000 2.14264

0.16394 -0.17638 0.16880 0.80000 2.16874

0.14227 -0.18703 0.17929 0.90000 2.19530

0.12027 -0.19509 0.18730 1.00000 2.22202>>


function eulermodif
clc, clear
syms x y
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=input('ingrese el valor de x inicial=');
xf=input('ingrese el valor de x final=');
y=input('ingrese el valor de y inicial=');
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x y1 y2')
for i=1:n+1;
y1=y+h*(feval(f,x,y));
x1=x+h;
y2=y+(h/2)*(feval(f,x,y)+feval(f,x1,y1));
fprintf('\n%0.5f %0.5f %0.5f',x1,y1,y2)
x=x1;
y=y1;
y1=y2;
end

corrida:

ingrese la ecuacion diferencial:(sin(2*x)*exp(y))/(cos(x)*(exp(2*y)-y))

ingrese el valor de x inicial=0

ingrese el valor de x final=1

ingrese el valor de y inicial=2

ingrese la cantidad de intervalos=10

h=

0.1000

x y1 y2

0.10000 2.00000 2.00140

0.20000 2.00280 2.00419

0.30000 2.00837 2.00970

0.40000 2.01660 2.01786

0.50000 2.02735 2.02852

0.60000 2.04044 2.04150

0.70000 2.05564 2.05657

0.80000 2.07271 2.07351

0.90000 2.09138 2.09204

1.00000 2.11136 2.11188

1.10000 2.13239 2.13277>>


function kuta
clc, clear
syms x y
f=input('ingrese la f=');
x0=input('ingrese la x0=');
xf=input('ingrese la xf=');
y0=input('ingrese la y0=');
n=input('ingrese n=');
h=(xf-x0)/n;
k=0;
a=x0;
disp('el valor de y es:')
for i=1:n
k=k+1;
x=x0;
y=y0;
k1=eval(f);
x=x0+h/2;
y=y0+h/2*k1;
k2=eval(f);
x=x0+h/2;
y=y0+h/2*k2;
k3=eval(f);
x=x0+h;
y=y0+h*k3;
k4=eval(f);
y1=y0+h/6*(k1+2*(k2+k3)+k4);
x0=a+i*h;
y0=y1;
disp([i,x,y1])
end

corrida

ingrese la f=(sin(2*x)*exp(y))/(cos(x)*(exp(2*y)-y))

ingrese la x0=0

ingrese la xf=1

ingrese la y0=2

ingrese n=10

el valor de y es:

1.0000 0.1000 2.0014

2.0000 0.2000 2.0056

3.0000 0.3000 2.0125


4.0000 0.4000 2.0219

5.0000 0.5000 2.0338

6.0000 0.6000 2.0478

7.0000 0.7000 2.0639

8.0000 0.8000 2.0816

9.0000 0.9000 2.1008

10.0000 1.0000 2.1211

N=10 y(0)=1

function euler
clc, clear
syms x y
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=input('ingrese el valor de x inicial=');
xf=input('ingrese el valor de x final=');
y=input('ingrese el valor de y inicial=');
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x(n) y(n)')
for i=1:n+1;
y1=feval(f,x,y);
hy1=h*y1;
fprintf('\n%0.5f %0.5f',x,y)
y=y+hy1;
x=x+h;
end

corrida:
ingrese la ecuacion diferencial:(2*x/y)+x^2*exp(x)

ingrese el valor de x inicial=1

ingrese el valor de x final=1.5

ingrese el valor de y inicial=1

ingrese la cantidad de intervalos=10

h=

0.0500

x(n) y(n)

1.00000 1.00000

1.05000 1.23591

1.10000 1.47840

1.15000 1.73456

1.20000 2.00969

1.25000 2.30845

1.30000 2.63528

1.35000 2.99467

1.40000 3.39126

1.45000 3.82995

1.50000 4.31597>>

function taylor
clc, clear
syms x y
F=(2*x/y)+x^2*exp(x);
a=diff(F,x);
b=diff(F,y);
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=1;
xf=1.5;
y=1;
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x(n) y(n)')
for i=1:n+1;
a1=eval(a);
b1=eval(b);
F1=eval(F);
y1=feval(f,x,y);
hy1=h*y1+(h/2)*(a1-b1*F1);
fprintf('\n%0.5f %0.5f %0.5f %0.5f %0.5f',a1,b1,F1,x,y)
y=y+hy1;
x=x+h;
end

corrida:

ingrese la ecuacion diferencial:(2*x/y)+x^2*exp(x)

ingrese la cantidad de intervalos=10

h=

0.0500

x(n) y(n)

10.15485 -2.00000 4.71828 1.00000 1.00000

10.31058 -0.70516 4.36746 1.05000 1.72570

11.12185 -0.42364 4.60045 1.10000 2.27883

12.14587 -0.28604 4.98782 1.15000 2.83562

13.33331 -0.20467 5.48184 1.20000 3.42433

14.67215 -0.15168 6.06945 1.25000 4.05980

16.16206 -0.11509 6.74812 1.30000 4.75309

17.80792 -0.08880 7.51982 1.35000 5.51397

19.61762 -0.06940 8.38901 1.40000 6.35185

21.60110 -0.05477 9.36175 1.45000 7.27630

23.76991 -0.04358 10.44537 1.50000 8.29723>>


function eulermodif
clc, clear
syms x y
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=input('ingrese el valor de x inicial=');
xf=input('ingrese el valor de x final=');
y=input('ingrese el valor de y inicial=');
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x y1 y2')
for i=1:n+1;
y1=y+h*(feval(f,x,y));
x1=x+h;
y2=y+(h/2)*(feval(f,x,y)+feval(f,x1,y1));
fprintf('\n%0.5f %0.5f %0.5f',x1,y1,y2)
x=x1;
y=y1;
y1=y2;
end

corrida:

ingrese la ecuacion diferencial:(2*x/y)+x^2*exp(x)

ingrese el valor de x inicial=1

ingrese el valor de x final=1.5

ingrese el valor de y inicial=1

ingrese la cantidad de intervalos=10

h=

0.0500

x y1 y2

1.05000 1.23591 1.23920

1.10000 1.47840 1.48524

1.15000 1.73456 1.74405

1.20000 2.00969 2.02150

1.25000 2.30845 2.32249

1.30000 2.63528 2.65156


1.35000 2.99467 3.01327

1.40000 3.39126 3.41231

1.45000 3.82995 3.85361

1.50000 4.31597 4.34243

1.55000 4.85491 4.88439>>


function kuta
clc, clear
syms x y
f=input('ingrese la f=');
x0=input('ingrese la x0=');
xf=input('ingrese la xf=');
y0=input('ingrese la y0=');
n=input('ingrese n=');
h=(xf-x0)/n;
k=0;
a=x0;
disp('el valor de y es:')
for i=1:n
k=k+1;
x=x0;
y=y0;
k1=eval(f);
x=x0+h/2;
y=y0+h/2*k1;
k2=eval(f);
x=x0+h/2;
y=y0+h/2*k2;
k3=eval(f);
x=x0+h;
y=y0+h*k3;
k4=eval(f);
y1=y0+h/6*(k1+2*(k2+k3)+k4);
x0=a+i*h;
y0=y1;
disp([i,x,y1])
end

corrida:

ingrese la f=(2*x/y)+x^2*exp(x)

ingrese la x0=1

ingrese la xf=1.5

ingrese la y0=1

ingrese n=10

el valor de y es:

1.0000 1.0500 1.2384


2.0000 1.1000 1.4869

3.0000 1.1500 1.7516

4.0000 1.2000 2.0375

5.0000 1.2500 2.3490

6.0000 1.3000 2.6908

7.0000 1.3500 3.0673

8.0000 1.4000 3.4835

9.0000 1.4500 3.9443

10.0000 1.5000 4.4552

>>

function euler
clc, clear
syms x y
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=input('ingrese el valor de x inicial=');
xf=input('ingrese el valor de x final=');
y=input('ingrese el valor de y inicial=');
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x(n) y(n)')
for i=1:n+1;
y1=feval(f,x,y);
hy1=h*y1;
fprintf('\n%0.5f %0.5f',x,y)
y=y+hy1;
x=x+h;
end

corrida:

ingrese la ecuacion diferencial:sin(x^4/(x*y^2))-exp(x^4*y^5/x^3*y^4)+cos(x*y)

ingrese el valor de x inicial=1

ingrese el valor de x final=5

ingrese el valor de y inicial=1

ingrese la cantidad de intervalos=10

h=

0.4000

x(n) y(n)

1.00000 1.00000

1.40000 0.46540

1.80000 0.42381

2.20000 0.66045

2.60000 0.02173

3.00000 0.42005

3.40000 0.45783

3.80000 -0.27114

4.20000 -0.85434

4.60000 -1.02880

5.00000 -1.32409>>
function taylor
clc, clear
syms x y
F=sin(x^4/(x*y^2))-exp(x^4*y^5/x^3*y^4)+cos(x*y);
a=diff(F,x);
b=diff(F,y);
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=1;
xf=5;
y=1;
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x(n) y(n)')
for i=1:n+1;
a1=eval(a);
b1=eval(b);
F1=eval(F);
y1=feval(f,x,y);
hy1=h*y1+(h/2)*(a1-b1*F1);
fprintf('\n%0.5f %0.5f %0.5f %0.5f %0.5f',a1,b1,F1,x,y)
y=y+hy1;
x=x+h;
end

ingrese la ecuacion diferencial:sin(x^4/(x*y^2))-exp(x^4*y^5/x^3*y^4)+cos(x*y)

ingrese la cantidad de intervalos=10

h=

0.4000

x(n) y(n)

-1.93885 -26.38661 -1.33651 1.00000 1.00000

2.45352 -0.45206 -0.88606 1.40000 -6.97556

0.97122 -0.16528 1.11530 1.80000 -6.91939

-5.37978 2.10683 0.66337 2.20000 -6.24216

-1.20271 0.63760 1.29823 2.60000 -7.33229

-1.91575 1.10786 -0.44956 3.00000 -7.21909

-5.95050 2.97431 1.16850 3.40000 -7.68245

0.62552 0.02582 -0.38457 3.80000 -9.10025

-5.00803 2.61146 1.58222 4.20000 -9.12698

3.97788 -1.50238 -0.14502 4.60000 -10.32208

8.36522 -4.18974 0.44909 5.00000 -9.62809>>


function eulermodif
clc, clear
syms x y
f=inline(input('ingrese la ecuacion diferencial:','s'));
x=input('ingrese el valor de x inicial=');
xf=input('ingrese el valor de x final=');
y=input('ingrese el valor de y inicial=');
n=input('ingrese la cantidad de intervalos=');
h=(xf-x)/n
disp(' x y1 y2')
for i=1:n+1;
y1=y+h*(feval(f,x,y));
x1=x+h;
y2=y+(h/2)*(feval(f,x,y)+feval(f,x1,y1));
fprintf('\n%0.5f %0.5f %0.5f',x1,y1,y2)
x=x1;
y=y1;
y1=y2;
end

corrida:

ingrese la ecuacion diferencial:sin(x^4/(x*y^2))-exp(x^4*y^5/x^3*y^4)+cos(x*y)

ingrese el valor de x inicial=1

ingrese el valor de x final=5

ingrese el valor de y inicial=1

ingrese la cantidad de intervalos=10

h=

0.4000

x y1 y2

1.40000 0.46540 0.71190

1.80000 0.42381 0.56292

2.20000 0.66045 0.22277

2.60000 0.02173 0.54025

3.00000 0.42005 0.23978

3.40000 0.45783 0.07445


3.80000 -0.27114 -0.19825

4.20000 -0.85434 -0.64997

4.60000 -1.02880 -1.08922

5.00000 -1.32409 -0.82395

5.40000 -0.61910 -1.22224>>


function kuta
clc, clear
syms x y
f=input('ingrese la f=');
x0=input('ingrese la x0=');
xf=input('ingrese la xf=');
y0=input('ingrese la y0=');
n=input('ingrese n=');
h=(xf-x0)/n;
k=0;
a=x0;
disp('el valor de y es:')
for i=1:n
k=k+1;
x=x0;
y=y0;
k1=eval(f);
x=x0+h/2;
y=y0+h/2*k1;
k2=eval(f);
x=x0+h/2;
y=y0+h/2*k2;
k3=eval(f);
x=x0+h;
y=y0+h*k3;
k4=eval(f);
y1=y0+h/6*(k1+2*(k2+k3)+k4);
x0=a+i*h;
y0=y1;
disp([i,x,y1])
end

corrida:

ingrese la f=sin(x^4/(x*y^2))-exp(x^4*y^5/x^3*y^4)+cos(x*y)

ingrese la x0=1

ingrese la xf=5

ingrese la y0=1

ingrese n=10

el valor de y es:

1.0000 1.4000 0.6980


2.0000 1.8000 0.3479

3.0000 2.2000 0.2368

4.0000 2.6000 0.4143

5.0000 3.0000 0.2013

6.0000 3.4000 0.1399

7.0000 3.8000 -0.0630

8.0000 4.2000 -0.5235

9.0000 4.6000 -0.8728

10.0000 5.0000 -0.7991

>>

Você também pode gostar