my newton raphson nested while function is not iterating well. What do I do?

8 ビュー (過去 30 日間)
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
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?

サインインしてコメントする。

採用された回答

Jim Riggs
Jim Riggs 2018 年 11 月 9 日
I haven't spent the time to understand all of your code, but one thing jumps out at me from the start. Inside the while loop, you keep resetting the root to the estimate.
rootA(i)= root_estimates (1);
Perhaps this statement should be outside the while loop.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by