You are on page 1of 8

function euler

syms x y
g= input('ingrese la funcion y^=g(x,y); g= ','s')
x1=input('ingrese el valor inicial de x1= ')
y1=input('ingrese el valor y(x1) = y1= ')
b=input('ingrese el valor de y(b)= b= ')
n=input('ingrese el numero de particiones n= ')
X=zeros(1,n+1);
X(1)=x1;
Y=zeros(1,n+1);
Y(1)=y1;
h=(b-x1)/n;
for i=2:1:n+1
X(i)=X(1)+(i-1)*h;
end
for i=1:1:n
Y(i+1)=Y(i)+subs(g,{x,y},{X(i),Y(i)})*h;
end
plot(X,Y),grid
disp('los valores de X(i) son= ')
disp(vpa(X,10))
disp('los valores de Y(i) son= ')
disp(vpa(Y,10))
>> euler

ingrese la funcion y^=g(x,y); g= (exp(x)-y)/x

g=

(exp(x)-y)/x

ingrese el valor inicial de x1= 1

x1 =

ingrese el valor y(x1) = y1= 2

y1 =
2

ingrese el valor de y(b)= b= 3

b=

ingrese el numero de particiones n= 4

n=

los valores de X(i) son=

[ 1.0, 1.5, 2.0, 2.5, 3.0]

los valores de Y(i) son=

[ 2.0, 2.359140914, 3.066656966, 4.147256749, 5.754304192]


function heun
syms x y
g= input('ingrese la funcion y^=g(x,y); g= ','s')
x1=input('ingrese el valor inicial de x1= ')
y1=input('ingrese el valor y(x1) = y1= ')
b=input('ingrese el valor de y(b)= b= ')
n=input('ingrese el numero de particiones n= ')
X=zeros(1,n+1);
X(1)=x1;
h=(b-x1)/n;
YE=zeros(1,n+1);
YE(1)=y1;
YH=zeros(1,n+1);
YH(1)=y1;
h=(b-x1)/n;
for i=2:1:n+1
X(i)=X(1)+(i-1)*h;
end
for i=1:1:n
m1=subs(g,{x,y},{X(i),YH(i)});
YE(i+1)=YH(i)+m1*h;
m2=subs(g,{x,y},{X(i+1),YE(i+1)});
YH(i+1)=YH(i)+((m1+m2)/2)*h
end
plot(X,YH),grid
disp('los valores de X(i) son= ')
disp(vpa(X,10))
disp('los valores de Y(i) son= ')
disp(vpa(YH,10))
>> heun

ingrese la funcion y^=g(x,y); g= (exp(x)-y)/x

g=

(exp(x)-y)/x

ingrese el valor inicial de x1= 1

x1 =

1
ingrese el valor y(x1) = y1= 2

y1 =

ingrese el valor de y(b)= b= 3

b=

ingrese el numero de particiones n= 4

n=

YH =

2.0000 2.5333 0 0 0

YH =

2.0000 2.5333 3.3838 0 0


YH =

2.0000 2.5333 3.3838 4.6642 0

YH =

2.0000 2.5333 3.3838 4.6642 6.5759

los valores de X(i) son=

[ 1.0, 1.5, 2.0, 2.5, 3.0]

los valores de Y(i) son=

[ 2.0, 2.533328483, 3.383839509, 4.664226613, 6.575858084]

>> heun

ingrese la funcion y=g(x,y),g=-x/y

g=

-x/y

ingrese el valor inicial x1=3

x1 =

ingrese el valor y(x1)=y1=2


y1 =

ingrese el valor y(b);b=4

b=

ingrese el numero de particion n=2

n=

h=

0.5000

los valores de X_i son

[ 3.0, 3.5, 4.0]

los valores de YH son

[ 2.0, 0.925, 1.013295843]

Gggggggggggggggggggggggggggg
>> x1=3:0.1:4;

>> syms x

>> f=sqrt(25-x^2);

>> y1=subs(f,x,x1);

>> plot(x1,y1)

>> plot(x1,y1),grid

>> hold on

>> X=[3,3.5,4];

>> Y=[4.0,3.5711,3.0015];

>> plot(X,Y,'r')

>>

>>

>> abs(subs(f,4)-Y(end)

abs(subs(f,4)-Y(end)

Error: Expression or statement is

incorrect--possibly unbalanced (, {, or [.

>> abs(subs(f,4)-Y(end))

ans =

0.0015

>>

You might also like