clase metodo de newton- raphson

14
>> diary off >> syms x1 x2 x3 >> f=x1+x2+x3-3 f = x1 + x2 + x3 - 3 >> g=x1^2+x2^2+x3^2-5 g = x1^2 + x2^2 + x3^2 - 5 >> h=exp(x1)+x1*x2-x1*x3-1 h = exp(x1) + x1*x2 - x1*x3 - 1 >> p=jacobian([f;g;h],[x1;x2;x3]) p = [ 1, 1, 1] [ 2*x1, 2*x2, 2*x3] [ x2 - x3 + exp(x1), x1, -x1] >> q=-[f;g;h] q = 3 - x2 - x3 - x1 - x1^2 - x2^2 - x3^2 + 5 x1*x3 - x1*x2 - exp(x1) + 1 >> x1o=0;x2o=1;x3o=0 x3o = 0 >> % iteracion 1 >> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1] [ 0, 2, 0] [ 2, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 2 4 0 >> a=inv(P)*Q

Upload: leonardo-peralta-navarro

Post on 11-Apr-2016

221 views

Category:

Documents


0 download

DESCRIPTION

informacion

TRANSCRIPT

Page 1: Clase Metodo de Newton- Raphson

>> diary off>> syms x1 x2 x3>> f=x1+x2+x3-3 f = x1 + x2 + x3 - 3 >> g=x1^2+x2^2+x3^2-5 g = x1^2 + x2^2 + x3^2 - 5 >> h=exp(x1)+x1*x2-x1*x3-1 h = exp(x1) + x1*x2 - x1*x3 - 1 >> p=jacobian([f;g;h],[x1;x2;x3]) p = [ 1, 1, 1][ 2*x1, 2*x2, 2*x3][ x2 - x3 + exp(x1), x1, -x1] >> q=-[f;g;h] q = 3 - x2 - x3 - x1 - x1^2 - x2^2 - x3^2 + 5 x1*x3 - x1*x2 - exp(x1) + 1 >> x1o=0;x2o=1;x3o=0

x3o =

0

>> % iteracion 1>> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1][ 0, 2, 0][ 2, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 2 4 0 >> a=inv(P)*Q

Page 2: Clase Metodo de Newton- Raphson

a = 0 2 0 >> xx=x1o+a(1) xx = 0 >> yy=x2o+a(2) yy = 3 >> zz=x3o+a(3) zz = 0 >> % iteracion 2>> x1o=xx;x2o=yy;x30=zz;>> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1][ 0, 6, 0][ 4, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 0 -4 0 >> a=inv(P)*Q a = 0 -2/3 2/3 >> xx=x1o+a(1) xx = 0 >> yy=x2o+a(2) yy =

Page 3: Clase Metodo de Newton- Raphson

7/3 >> zz=x3o+a(3) zz = 2/3 >> format>> x1o=xx;x2o=yy;x30=zz;>> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1][ 0, 14/3, 0][ 10/3, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 2/3 -4/9 0 >> a=inv(P)*Q a = 0 -2/21 16/21 >> xx=x1o+a(1) xx = 0 >> yy=x2o+a(2) yy = 47/21 >> zz=x3o+a(3) zz = 16/21 >> x1o=xx;x2o=yy;x30=zz;>> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1][ 0, 94/21, 0]

Page 4: Clase Metodo de Newton- Raphson

[ 68/21, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 16/21 -4/441 0 >> a=inv(P)*Q a = 0 -2/987 754/987 >> xx=x1o+a(1) xx = 0 >> yy=x2o+a(2) yy = 2207/987 >> zz=x3o+a(3) zz = 754/987 >> format short>> xx xx = 0 >> yy yy = 2207/987 >> vpa(xx,5) ans = 0.0 >> vpa(yy,5) ans = 2.2361

Page 5: Clase Metodo de Newton- Raphson

>> vpa(zz,5) ans = 0.76393 >> x1o=xx;x2o=yy;x30=zz;>> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1][ 0, 4414/987, 0][ 3194/987, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 754/987 -4/974169 0 >> a=inv(P)*Q a = 0 -2/2178309 1664080/2178309 >> xx=x1o+a(1) xx = 0 >> yy=x2o+a(2) yy = 4870847/2178309 >> zz=x3o+a(3) zz = 1664080/2178309 >> vpa(xx,5) ans = 0.0 >> vpa(yy,5) ans =

Page 6: Clase Metodo de Newton- Raphson

2.2361 >> vpa(zz,5) ans = 0.76393 >> x1o=xx;x2o=yy;x30=zz;>> P=subs(p,{x1,x2,x3},{x1o,x2o,x3o}) P = [ 1, 1, 1][ 0, 9741694/2178309, 0][ 7049156/2178309, 0, 0] >> Q=subs(q,{x1,x2,x3},{x1o,x2o,x3o}) Q = 1664080/2178309 -4/4745030099481 0 >> a=inv(P)*Q a = 0 -2/10610209857723 8105479075762/10610209857723 >> xx=x1o+a(1) xx = 0 >> yy=x2o+a(2) yy = 23725150497407/10610209857723 >> zz=x3o+a(3) zz = 8105479075762/10610209857723 >> vpa(xx,5) ans = 0.0 >> vpa(yy,5) ans =

Page 7: Clase Metodo de Newton- Raphson

2.2361 >> vpa(zz,5) ans = 0.76393 >> subs(f,{x1,x2,x3},{xx,yy,zz}) ans = 0 >> subs(g,{x1,x2,x3},{xx,yy,zz}) ans = 65698791047615605735880648/112576553224922323902744729 >> subs(h,{x1,x2,x3},{xx,yy,zz}) ans = 0 >> subs(g,{x1,x2,x3},{xx,yy,zz}) ans = 65698791047615605735880648/112576553224922323902744729 >> vpa(ans,5) ans = 0.58359 >> 0^2+2.2361^2+0.76393^2-5

ans =

0.5837

>> clear all>> syms x1 x2>> f=x1^2+x2^2-2*x1*x2-1 f = x1^2 - 2*x1*x2 + x2^2 - 1 >> g=x1^2+5*x2+1 g = x1^2 + 5*x2 + 1 >> p=jacobian([f;g],[x1;x2])

Page 8: Clase Metodo de Newton- Raphson

p = [ 2*x1 - 2*x2, 2*x2 - 2*x1][ 2*x1, 5] >> q=-[f;g] q = - x1^2 + 2*x1*x2 - x2^2 + 1 - x1^2 - 5*x2 - 1 >> x1o=1;x2=0.5;>> P=subs(p,{x1,x2},{x1o,x2o})Undefined function or variable 'x2o'. >> x1o=1;x2=0,5;

x2 =

0

>> P=subs(p,{x1,x2},{x1o,x2o})Undefined function or variable 'x2o'. >> x1o=1;x2o=0.5;>> P=subs(p,{x1,x2},{x1o,x2o}) P = [ 2 - 2*x2, 2*x2 - 2][ 2, 5] >> Q=subs(q,{x1,x2},{x1o,x2o}) Q = - x2^2 + 2*x2 - 5*x2 - 2 >> a=inv(P)*Q a = - (5*x2)/7 - (5*(- x2^2 + 2*x2))/(14*(x2 - 1)) - 2/7 (- x2^2 + 2*x2)/(7*(x2 - 1)) - (5*x2)/7 - 2/7 >> xx=x1o+a(1) xx = 5/7 - (5*(- x2^2 + 2*x2))/(14*(x2 - 1)) - (5*x2)/7 >> yy=x2o+a(2) yy = (- x2^2 + 2*x2)/(7*(x2 - 1)) - (5*x2)/7 + 3/14

Page 9: Clase Metodo de Newton- Raphson

>> clear all>> syms x1 x2>> f=x1^2+x2^2-2*x1*x2-1 f = x1^2 - 2*x1*x2 + x2^2 - 1 >> g=x1^2+5*x2+1 g = x1^2 + 5*x2 + 1 >> p=jacobian([f;g],[x1;x2]) p = [ 2*x1 - 2*x2, 2*x2 - 2*x1][ 2*x1, 5] >> q=-[f;g] q = - x1^2 + 2*x1*x2 - x2^2 + 1 - x1^2 - 5*x2 - 1 >> x1o=1;x2o=0.5;>> P=subs(p,{x1,x2},{x1o,x2o}) P = [ 1, -1][ 2, 5] >> Q=subs(q,{x1,x2},{x1o,x2o}) Q = 3/4 -9/2 >> avp(q,5)Undefined function 'avp' for input arguments of type 'sym'. >> avp(q;5) avp(q;5) |Error: Unbalanced or unexpected parenthesis or bracket. >> avp(Q,5)Undefined function 'avp' for input arguments of type 'sym'. >> format short>> Q=subs(q,{x1,x2},{x1o,x2o}) Q = 3/4

Page 10: Clase Metodo de Newton- Raphson

-9/2 >> vpa(Q,5) ans = 0.75 -4.5 >> a=inv(P)*Q a = -3/28 -6/7 >> xx=x1o+a(1) xx = 25/28 >> yy=x2o+a(2) yy = -5/14 >> vpa(xx,5) ans = 0.89286 >> vpa(yy,5) ans = -0.35714 >> x1o=xx;x2o=yy;>> P=subs(p,{x1,x2},{x1o,x2o}) P = [ 5/2, -5/2][ 25/14, 5] >> Q=subs(q,{x1,x2},{x1o,x2o}) Q = -9/16 -9/784 >> a=inv(P)*Q a = -891/5320

Page 11: Clase Metodo de Newton- Raphson

153/2660 >> xx=x1o+a(1) xx = 3859/5320 >> yy=x2o+a(2) yy = -797/2660 >> vpa(xx,5) ans = 0.72538 >> vpa(yy,5) ans = -0.29962 >> x1o=xx;x2o=yy;>> P=subs(p,{x1,x2},{x1o,x2o}) P = [ 41/20, -41/20][ 3859/2660, 5] >> Q=subs(q,{x1,x2},{x1o,x2o}) Q = -81/1600 -793881/28302400 >> a=inv(P)*Q a = -175830021/7485442160 4511943/3742721080 >> xx=x1o+a(1) xx = 5253929621/7485442160 >> yy=x2o+a(2) yy = -1116897343/3742721080

Page 12: Clase Metodo de Newton- Raphson

>> vpa(xx,5) ans = 0.70189 >> vpa(yy,5) ans = -0.29842 >> x1o=xx;x2o=yy;>> P=subs(p,{x1,x2},{x1o,x2o}) P = [ 3281/1640, -3281/1640][ 5253929621/3742721080, 5] >> Q=subs(q,{x1,x2},{x1o,x2o}) Q = -6561/10758400 -30916196284860441/56031844330705465600 >> a=inv(P)*Q a = -12310902221373458991/37976537170478625410720 -367227051443417547/18988268585239312705360 >> xx=x1o+a(1) xx = 26642901879889707176591/37976537170478625410720 >> yy=x2o+a(2) yy = -5666818527511203400453/18988268585239312705360 >> vpa(xx,5) ans = 0.70156 >> vpa(yy,5) ans = -0.29844 >> x1o=xx;x2o=yy;>> P=subs(p,{x1,x2},{x1o,x2o})

Page 13: Clase Metodo de Newton- Raphson

P = [ 21523361/10761680, -21523361/10761680][ 26642901879889707176591/18988268585239312705360, 5] >> Q=subs(q,{x1,x2},{x1o,x2o}) Q = -43046721/463255025689600 -151558313504217967084648109639958738081/1442217375460744680301658275208586888690918400 >> a=inv(P)*Q a = -10473131338923866638240988874677561552705525841/198761721226510883168236381275956090600910340934517440 -619216969975368699439172130446370251549090997/99380860613255441584118190637978045300455170467258720 >> xx=x1o+a(1) xx = 139443694263394522239370191115507203003525839194698641/198761721226510883168236381275956090600910340934517440 >> yy=x2o+a(2) yy = -29659013481558287728089704060142326076469155001829803/99380860613255441584118190637978045300455170467258720 >> vpa(xx,5) ans = 0.70156 >> vpa(yy,5) ans = -0.29844 >> subs(f,{x1,x2},{x1o,x2o}) ans = 43046721/463255025689600 >> subs(g,{x1,x2},{xx,yy}) ans =

Page 14: Clase Metodo de Newton- Raphson

109686480042349223527042349124244555293073962631482395909257067425705709140105897176318757281/39506221824925226978804371548096848555924168548992142287007967094935620784775275400457186085982045664153600 >> subs(f,{x1,x2},{xx,yy}) ans = 1853020188851841/858420955073127194654367846400 >> vpa(ans,5) ans = 2.1586e-15 >> subs(f,{x1,x2},{xx,yy}) ans = 1853020188851841/858420955073127194654367846400 >> vpa(ans,5) ans = 2.1586e-15 >> !notepad