Newton Raphson Method!!!
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hi,
I'm trying to run the Newton Raphson method for 3 different initial values. 5 iterations for each value. I'm trying to get results stored as r1,r2,r3. So far only r1 looks ok but the other 2 are 0 which is wrong. Any help would be appreciated. 
[r1,r2,r3] = newton();
function [r1,r2,r3] = newton()
r1= 0;
r2=0;
r3=0;
r = [r1 , r2 , r3]; 
x0= [0.5,1.5,2.5];
x= [ 0 , 0 , 0 ];
i=0; 
j=1:3;
for j= 1:3;
    f = x0(j)^4 - 9*x0(j)^3+29*x0(j)^2-39*x0(j)+18;
df = 4*x0(j)^3 - 27*x0(j)^2 +58*x0(j) -39;  
while i < 5
    i= i+1; 
     x(j) = x(j) - f/df;
    x0(j) = x(j);
    disp (r1);
    if i==5
        r(j)=x0 (j); 
        disp('root is');
        disp(r); 
        break
    end
end
end
end 
0 commentaires
Réponse acceptée
  David Hill
      
      
 le 5 Mai 2020
        
      Modifié(e) : David Hill
      
      
 le 5 Mai 2020
  
      function x = newton()
x=[0.5,1.5,2.5];
f=[1,-9,29,-39,18];
df=polyder(f);
for j= 1:5
   x = x - polyval(f,x)./polyval(df,x);
end
4 commentaires
  David Hill
      
      
 le 5 Mai 2020
				The loop is performing all the calculations at once doing element-wise calculations of the arrays.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

