Está en la página 1de 3

function z=ft(x,y)

z=x^2;
function [y,x]=eu(f,a,b,y_a,n)
x=linspace(a,b,n+1);
y(1)=y_a;
delta=(b-a)/n;
for i=1:n
y(1+i)=y(i)+delta*(feval(f,x(i),y(i)));
end

valores de x e y
[x,y]=eu(@ft,2,6,0,40)
x=
Columns 1 through 8
0 0.4000 0.8410 1.3250 1.8540 2.4300 3.0550 3.7310
Columns 9 through 16
4.4600 5.2440 6.0850 6.9850 7.9460 8.9700 10.0590 11.2150
Columns 17 through 24
12.4400 13.7360 15.1050 16.5490 18.0700 19.6700 21.3510 23.1150
Columns 25 through 32
24.9640 26.9000 28.9250 31.0410 33.2500 35.5540 37.9550 40.4550
Columns 33 through 40
43.0560 45.7600 48.5690 51.4850 54.5100 57.6460 60.8950 64.2590
Column 41
67.7400
y=
Columns 1 through 8
2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000
Columns 9 through 16
2.8000 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 3.5000
Columns 17 through 24
3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000
Columns 25 through 32
4.4000 4.5000 4.6000 4.7000 4.8000 4.9000 5.0000 5.1000
Columns 33 through 40
5.2000 5.3000 5.4000 5.5000 5.6000 5.7000 5.8000 5.9000
Column 41
6.0000

PREGUNTA Nº5
b = input ('ingrese el valor de b = ');
a = input ('ingrese el valor de a = ');
n = input ('ingrese el numero de las particiones n = ');
y_a=input ('ingrese el valor de y_a =');
[x,y]=euler1(@h,a,b,y_a,n);

fprintf ('el valor = %0.2f\n', y);


fprintf ('el valor = %0.2f\n', x);

function [x,y]=euler1(h,a,b,y_a,n)
x=linspace(a,b,n+1);
y(1)=y_a;
delta=(b-a)/n;

for i=1:n
y(1+i)=y(i)+delta*(feval(h,x(i),y(i)));

end

function z=h(x,y)
z=(x^3)+cos ;

----------------------------------------------------------

ingrese el valor de b = 100


ingrese el valor de a = 125
ingrese el numero de las particiones n = 135
ingrese el valor de y_a =2

mostrando la gráfica

plot(x,y)

PREGUNTA Nº4

b = input ('ingrese el valor de b = ');


a = input ('ingrese el valor de a = ');
n = input ('ingrese el numero de las particiones n = ');
s = metodotrapecio(@f,a,b,n);
fprintf ('el valor = %0.2f\n', s);

function Z=f(x)
Z=2*sin(x)-2*cos(2*x)+x^2-(pi^2-2);
function K=metodotrapecio(f,a,b,n)
x=linspace(a,b,n+1);
sumass=0;
for i=1:n
area=(x(i+1)-x(i))*(feval(f,x(1+i))+feval(f,x(i)))/2;
sumass=sumass+area;
end
K=sumass;

También podría gustarte