my newton raphson nested while function is not iterating well. What do I do?
Mostrar comentarios más antiguos
Hey, I am having an issue with my code. It is supposed to iterate and produce the value 0.2094 as my rootA but it keeps jumping from 0.20 (My Estimate) to 0.2074 and the iteration stops there. I tried to give it an additional condition i<50 and it would still print 0.200 until the last step and put 0.2074. Thank you in advance.
function [rootA,rootB,rootC,y,i] = Isonewton1(Tr,Pr)
%Isonewton the Newton Raphson function to obtain roots of a polynomial
% Detailed explanation goes here
i=1; %my first iteration
Pr= 0.45
Tr= 0.85
MV= [0.24:0.35:1.3]
root_estimates = [0.15 0.35 1.9] % these are my three estimates of 3 roots.
rootA(i)= root_estimates (1); % assiging of each root value with a value from my root estimate row vector.
y=((8*Tr)/(8.*rootA(i)-1))-(27/(64.*rootA(i)^2))-Pr;% this is my y-value
g=(27/(32.*rootA(i)^3))-((64*Tr)/(((8.*rootA(i)-1))^2));
h=y/g;
while (h<=0.001)
rootA(i)= root_estimates (1);
y=8.*Tr/(8.*rootA(i)-1)-27/(64.*rootA(i).^2)-Pr; % this is my y-value
g=27/(32.*rootA(i).^3)-64.*Tr/(8.*rootA(i)-1).^2;
h=y/g; %adjustment
rootA(i+1)=rootA(i)-h;
i=i+1 ;
P=max(rootA);
end
1 comentario
Jim Riggs
el 9 de Nov. de 2018
I do not even understand what function you are trying to find roots for. Why does your y value calculation contain the "rootA" variable? Can you write the mathematical function for which you are trying to find roots?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Newton-Raphson Method en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!