Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Nombre: Sofia palomino

Anlisis Numrico

Deber 1

Integral de Simpson

function [ S ] = IntegralSimpson(f,a,b,N)

h=(b-a)./N;

c=[a:h:b];

M=length(c);

S=0;

for m=1:2:M-2

A=vander(c(m:m+2));

Z=inv(A)*(f(c(m:m+2)));

S=S+Z(1).[c(m+2).^3-c(m).^3]./3+Z(2).[c(m+2).^2-c(m).^2]./2+Z(3).*2.*h;

end

end
Deber 2

Resolver Vector
Trapecio Vector
Simpson Vector

function [ S ] = ResolverVector( a,b )

N=length(a);

M=length(b);

S=0;

if rem(N,2)==0

[ S ] = TrapecioVector(a,b);

else

[ S ] = SimpsonVector( a,b );

end

end

function [ S ] = TrapecioVector(a,b)

N=length(a);

S=0;

for n=1:N-1

S=S+(b(n)+b(n+1)).*(a(n+1)-a(n))./2;

end

end

function [ S ] = SimpsonVector( a,b )

M=length(a);

S=0;

for m=1:2:M-2

A=vander(a(m:m+2));

Z=inv(A).*(b(m:m+2));

S=S+Z(1).[b(m+2).^3-b(m).^3]./3+Z(2).[b(m+2).^2-b(m).^2]./2+Z(3).*2.*a(m+2);

end

end

You might also like