The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 352 Weeks Ago, 4 Days Ago |
| Questions Answered: | 20103 |
| Tutorials Posted: | 20155 |
MBA, PHD
Phoniex
Jul-2007 - Jun-2012
Corportae Manager
ChevronTexaco Corporation
Feb-2009 - Nov-2016
Â
Â
Incase the file NEWTONS_METHOD Doesn't open, the code is here:
proc iml;
/** x##3 - 2 x##2 -4 x + 3 **/
q = {1, -2, -4, 3};
start eval(p,x,val);
N = NROW(p);
val = p[1];
do k = 1 to N-1;
val = val*x + p[k+1];
end;
finish eval;
start der(p,p_prime);
p_prime = J(NROW(p)-1,1,0);
do k = 1 to NROW(p) - 1;
p_prime[k] = (NROW(p)-k)*p[k];
end;
finish der;
start newton(q,x0,tol,root);
/* The value x0 is the initial estimate of the root.
The value tol is how close to zero the polynomial should be to for the currentÂ
estimate to be accepted as a root.*/
call der(q,q_prime);
iter_max = 100;
xnext = x0;
do k = 1 to iter_max;
call eval(q,xnext,val_1);
if abs(val_1) < tol then k = iter_max;
call eval(q_prime,xnext,val_2);
xnext = xnext - val_1/val_2;
end;
root = xnext;
finish newton;
call newton(q,0,0.0001,r1);
print r1;
/*Try a different starting value ..*/
call newton(q, 2.5,0.0001,r2);
print r2;
call newton(q, -7,0.0001,r3);
print r3;
/* Compare with the roots obtained using the built-in function. */
roots = polyroot(q);
print roots;
quit;
run;
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- T-----------han-----------k Y-----------ou -----------for----------- us-----------ing----------- ou-----------r w-----------ebs-----------ite----------- an-----------d a-----------cqu-----------isi-----------tio-----------n o-----------f m-----------y p-----------ost-----------ed -----------sol-----------uti-----------on.----------- Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m o-----------nli-----------ne -----------or -----------inb-----------ox -----------me -----------a m-----------ess-----------age----------- I -----------wil-----------l