Professional Documents
Culture Documents
Civil
METODOS NUMÉRICOS
LAB 8
1. Escriba los comandos Matlab que permitan hallar la integral mostrando su resultado.
3𝜋/4
∫ cos(√𝑥 𝑑𝑥
𝜋/4
2. Halle el área de una región limitada por dos curvas. Una de las curvas obtenida por
interpolación numérica (spline), y la otra curva, sea una función definida explícitamente
mediante una expresión matemática.
1. Programa
function A=trap(f,a,b,n)
A=0;
h=(b-a)/n;
for p=a:h:b-h
Q=(f(p)+f(p+h))*h/2;
A=A+Q;
End
function A=romberg(f,a,b,e)
R(1,1)=trap(f,a,b,1);
R(2,1)=trap(f,a,b,2);
R(2,2)=(4*R(2,1)-R(1,1))/3;
k=2;
while abs(R(k,k)-R(k,k-1))>=e
k=k+1;
R(k,1)=trap(f,a,b,2^(k-1));
for j=2:k;
R(k,j)=((4^(j-1)*R(k,j-1)-R(k-1,j-1))/(4^(j-1)-1));
end
end
A=R(k,k);
end
comandos
>> f=@(x) cos(x^0.5);
>> romberg(f,pi/4,3*pi/4,0.00001)
ans =
0.5018
>> x=0:0.25:1
x=
>> y=x^0.5
Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
>> y=x.^0.5
y=
>> j=0:0.01:1;
>> t=interp1(x,y,j,'spline');
>> q=@(w) w^2;
>> h=@(q,t) q-t
h=
@(q,t)q-t
>> romberg(h,0,1,0.0001
romberg(h,0,1,0.0001
|
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
>> romberg(q,0,1,0.0001)
ans =
0.3333
>> romberg(t,0,1,0.0001)
Attempted to access f(0); index must be a positive integer or logical.
>> romberg(t,0,1,0.0001)
Attempted to access f(0); index must be a positive integer or logical.
>> romberg(t,0,1,0.0001)
Attempted to access f(0); index must be a positive integer or logical.
>> y=x^0.5;
Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
>> y=x.^0.5;
>>
>>
>>
>> y
y=
>> z=interp1(x,y,j,'spline')
z=
Columns 1 through 13
Columns 14 through 26
Ing. Civil
Columns 27 through 39
Columns 40 through 52
Columns 53 through 65
Columns 66 through 78
Columns 79 through 91
>> romberg(z,0,1,0.0001)
Attempted to access f(0); index must be a positive integer or logical.
>> h=@(z) z
h=
@(z)z
Ing. Civil
>> romberg(z,0,1,0.00001)
Attempted to access f(0); index must be a positive integer or logical.
>> romberg(h,0,1,0.00001)
ans =
0.5000