Curso: Calculo Numérico
Año: 2013
syms x1 x2 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x
%Captura el sistema de ecuaciones
SEc=get(handles.edit1,'string');
%Devuelve el tamaño de la matriz
[m,n]=size(SEc);
%------------------------------------------------
%%%%% Cada i-ésima ecuacion la covierte en objeto simbolico
a1=sym(SEc(1,:));
for i=2:m
a2=sym(SEc(i,:));
a1=[a1;a2];
end
SE=a1
%--------------------------------------------
%------------------------------------------------
%%%%% crea las variables simbolicas x1 x2 x3 x4 ...
cad='';
for i=1:m
cad1=sym(sprintf('x%d',i));
cad=[cad;cad1];
end
cad
%--------------------------------------------
%input('Ingrese los valores iniciales: ');
Po=str2num(get(handles.edit2,'string'));
%input('Ingrese la tolerancia: ');
E=str2double(get(handles.edit3,'string'));
%Simplica el sistema SE
SE=simplify(SE);
%Calcula el JACOBIANO del sistema de ecuaciones
JSE=jacobian(SE,cad);
digits 4
vpa(JSE)
switch m
case 1
% P1 = Po - (inv(subs(JSE,{x1},Po))*subs(SE,{x1},Po))';
P1 = Po - subs(SE,{x},Po)/subs(diff(SE,'x'),Po);
while abs(P1-Po)>E
Po=P1;
%P1 = Po - (inv(subs(JSE,{x1},Po))*subs(SE,{x1},Po))';
P1 = Po - subs(SE,{x},Po)/subs(diff(SE,'x'),Po);
end
case 2
P1 = Po - (inv(subs(JSE,{x1,x2},Po))*subs(SE,{x1,x2},Po))'
while norm(P1-Po)>E
Po=P1;
P1 = Po - (inv(subs(JSE,{x1,x2},Po))*subs(SE,{x1,x2},Po))'
end
case 3
P1 = Po - (inv(subs(JSE,{x1,x2,x3},Po))*subs(SE,{x1,x2,x3},Po))';
while norm(P1-Po)>E
Po=P1;
P1 = Po - (inv(subs(JSE,{x1,x2,x3},Po))*subs(SE,{x1,x2,x3},Po))'
end
case 4
P1 = Po - (inv(subs(JSE,{x1,x2,x3,x4},Po))*subs(SE,{x1,x2,x3,x4},Po))';
while norm(P1-Po)>E
Po=P1;
P1 = Po - (inv(subs(JSE,{x1,x2,x3,x4},Po))*subs(SE,{x1,x2,x3,x4},Po))';
end
case 5
P1 = Po - (inv(subs(JSE,{x1,x2,x3,x4,x5},Po))*subs(SE,{x1,x2,x3,x4,x5},Po))';
while norm(P1-Po)>E
Po=P1;
P1 = Po - (inv(subs(JSE,{x1,x2,x3,x4,x5},Po))*subs(SE,{x1,x2,x3,x4,x5},Po))';
end
case 6
P1 = Po -
(inv(subs(JSE,{x1,x2,x3,x4,x5,x6},Po))*subs(SE,{x1,x2,x3,x4,x5,x6},Po))';
while norm(P1-Po)>E
Po=P1;
P1 = Po -
(inv(subs(JSE,{x1,x2,x3,x4,x5,x6},Po))*subs(SE,{x1,x2,x3,x4,x5,x6},Po))';
end
case 7
P1 = Po -
(inv(subs(JSE,{x1,x2,x3,x4,x5,x6,x7},Po))*subs(SE,{x1,x2,x3,x4,x5,x6,x7},Po))';
while norm(P1-Po)>E
Po=P1;
P1 = Po -
(inv(subs(JSE,{x1,x2,x3,x4,x5,x6,x7},Po))*subs(SE,{x1,x2,x3,x4,x5,x6,x7},Po))';
end
end
%-----------------------------------------
%%Muestra los resultados en la ventana
respuesta='';
for i=1:m
cadena=sprintf(' %10.5f',P1(i))
respuesta=[respuesta;cadena]
end
set(handles.edit5,'string',respuesta);
%-----------------------------------------
Top Related