my newton raphson nested while function is not iterating well. What do I do?
이전 댓글 표시
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
Jim Riggs
2018년 11월 9일
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?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!