Sei sulla pagina 1di 5

08425495

Curso: Laboratorio de Mtodos Numricos


Alumno: Huayhuapuma Gonzaga Erick
Cdigo: 13190236
Tema: Resolucin de examen

Pregunta 1
% Programa para calcular raices de ecuaciones basado en el metodo de biseccion
%
function biseccion
clc;
clear;
a=input('Valor de la cota inferior: ');
b=input('Valor de la cota superior: ');
TOL=input('Tolerancia de error : ');
max_iter=input('Numero de iteracciones: ');
iter = 0;
fprintf('\nMETODO DE BISECCION...\nRESULTADOS\n')
fprintf('Iter a Xr b f(a) f(xr) Error\n');
while 1 %Inicio un cliclo infinito del cual salgo al hallar la raiz o exceder
max_iter
xr=(b+a)/2; %Aproximo el valor de la posible raiz como el punto medio del
intervalo.
fa = funcion(a); %Evaluamos la funcion en la cota inferior
fb = funcion(b); %evaluamos la funcion en la cota superior
fxr= funcion(xr); %Evaluamos la funcion en la posible raiz
error = abs((b - a)/a);
% Impresion de resultados en cada iteracion
fprintf('%4.0f,%10.6f,%10.6f,%10.6f,%10.6f,%10.6f,
%12.6f\n',iter,a,xr,b,fa,fxr,error)
if error <= TOL %Si supero el error aceptado detengo el proceso
fprintf('Proceso concluido exitosamente con el nivel de error <=
%10.6f\n\n',TOL)
break;
end
if abs(fxr)<=TOL %Se hallo la aproximacion a la raiz y salgo del ciclo
infinito
fprintf('\nProceso concluido exitosamente con el nivel de error <=
%12.6e\n\n',TOL)
break;
end
if fa*fxr < 0
b=xr; %La raiz esta en el primer intervalo
else
a=xr; %La raiz esta en el segundo intervalo
end
if (iter > max_iter) %Verifico si se excede el numero de iteracciones
fprintf('\nNumero de iteracciones excedido...\n\n')
break;
end
iter=iter+1; %Incremento el numero de iteracciones
end
fprintf('Raiz aproximada: %12.6f',xr);
fprintf(' Iteraciones : %5.0f\n',iter);
% Modelo grafico
x=CotaInf:0.01:CotaSup;
f=funcion(x);
plot(x,f)
gris
function y=funcion(x) %A continuacin debo colocar la funcin a evaluar
y=5*sin(x)*exp(x)-1;

metodo de bolzano
Valor de la cota inferior: 1.5
Valor de la cota superior: 2
Tolerancia de error : 0.01
Numero de iteracciones: 4

METODO DE BISECCION...
RESULTADOS
Iter

Xr

f(a)

f(xr)

Error

0, 1.500000, 1.750000, 2.000000, 21.352312, 27.312241,

0.333333

1, 1.750000, 1.875000, 2.000000, 27.312241, 30.107104,

0.142857

2, 1.875000, 1.937500, 2.000000, 30.107104, 31.399367,

0.066667

3, 1.937500, 1.968750, 2.000000, 31.399367, 32.010365,

0.032258

4, 1.968750, 1.984375, 2.000000, 32.010365, 32.305876,

0.015873

5, 1.984375, 1.992188, 2.000000, 32.305876, 32.450977,

0.007874

Proceso concluido exitosamente con el nivel de error <= 0.010000

Raiz aproximada:

1.992188 Iteraciones :

pregunta 3
matriz=input ('Ingrese la matriz aumentada del sistema, A|b, A tiene que ser
simtrica y positiva
tam=size(matriz);
n=tam(1);
for i=1:n
b(i)=matriz(i,n+1);
for j=1:n
A(i,j)=matriz(i,j);
end
end
b1=b';
for k=1:n
for i=1:k-1
sum=0;
for j=1:i-1
sum=sum+A(i,j)*A(k,j);
end
A(k,i)=(A(k,i)-sum)/A(i,i);
end
sum=0;
for j=1:k-1

sum=sum+A(k,j)*A(k,j);
end
A(k,k)=sqrt(A(k,k)-sum);
end
for i=1:n-1
for j=1:n
if j>i
A(i,j)=0;
end
end
end
L=A;
Lt=L';
c=b1;
c(1)=b1(1)/L(1,1);
for i=2:n
s=0;
for j=1:n-1
if i~=j & i>j
s=s+L(i,j)*c(j) ;
end
end
c(i)=(b1(i)-s)/L(i,i);
end
x=c;
x(n)=c(n)/Lt(n,n);
for i=n-1:-1:1
z=0;
for j=n:-1:2
if i~=j & i<j
z=z+Lt(i,j)*x(j);
end
end
x(i)=(c(i)-z)/Lt(i,i);
end
L
Lt
LLt=L*Lt
x
clear all
solucion
las ecuaciones son
11I1-10I2=1
-85I1+10I2-8I3=0
4I2-55I3=10
Ingrese la matriz aumentada del sistema, A|b, A tiene que ser simtrica y
positiva
[11 -10 0 1;-5 10 -4 0;0 4 -55 10]
L =
3.316624790355400

-1.507556722888818

2.779797245712846

0
0
0
0 + 7.554507808937265i

1.438953868369003

Lt =
3.316624790355400

-1.507556722888818

2.779797245712846

0
1.438953868369003

0
0 - 7.554507808937265i

x =
0.077388531170044
-0.029745231425904
0.171098742527314

Pregunta 4
a) ecuaciones del circuito
(8+2j)I1-8jI2=j20
-j8I1+4I2=0

b)por el metodo de cholasky


Ingrese la matriz aumentada del sistema, A|b, A tiene que ser
simtrica y positiva
[(8+2*i) -i*8 i*20;-8*i 4 0]

L=

2.8501 + 0.3509i

-0.3404 - 2.7650i 3.4067 - 0.2763i

Lt =

2.8501 - 0.3509i -0.3404 + 2.7650i


0

x=

3.4067 + 0.2763i

0.0000 - 4.0367i
1.6113 - 0.4028i
c)
function x=metododegauss(a,b)
% Metodo de Gauss sin pivotaje
%Introducimos una matriz cuadrada a y un vector b
% La salida es x, solucion del sistema
a=input('Ingrese la matriz A = \n');
b=input('\nIngrese el vector b, correspondiente a los terminos independientes
b=\n');
n=length(a); % Medimos la matriz a
for j=1:n-1
for i=j+1:n
l=a(i,j)/a(j,j);
for k=j:n
a(i,k)=a(i,k)-l*a(j,k);
end
b(i)=b(i)-l*b(j);
end
end
% Sustitucion regresiva
x=zeros(n,1);
x(n)=b(n)/a(n,n);
for i=n-1:-1:1
for j=1+i:n
b(i)=b(i)-a(i,j)*x(j);
end
x(i)=b(i)/a(i,i);
end
return

Ingrese la matriz A =

[(8+2*i) -i*8;-i*8 4]

Ingrese el vector b, correspondiente a los terminos independientes b=


[20*i,0]

ans =

0.068965517241379 + 0.827586206896552i
-1.655172413793103 + 0.137931034482759i

Potrebbero piacerti anche