フィルターのクリア

Iteration of a formula

16 ビュー (過去 30 日間)
Sam Thorpe
Sam Thorpe 2019 年 2 月 28 日
コメント済み: Sam Thorpe 2019 年 3 月 1 日
I have the following function y=4*(1-cos(x)).^2+x.^3. Using newtonian iteration how can iterate the formula 100 times with initial guess of x=4?
I have the following code so far which gets me the first root, but im not sure how to progress from here.
maxIter=100'; %number of iterations
x=4; %initial guess
i=0;
f=4*(1-cos(x)).^2+x.^3 %function
dfx=3*x.^2+8*sin(x)*(1-cos(x)) %derivative of function
y=x-(f/dfx)
newx=y
x=newx
i=i+1
Thanks for any help

採用された回答

Yasasvi Harish Kumar
Yasasvi Harish Kumar 2019 年 3 月 1 日
Hi,
All you need is a loop. This should fix your problem.
maxIter=100'; %number of iterations
i = 1;
x(i)=4; %initial guess
while i<=maxIter
f=4*(1-cos(x(i))).^2+x.^3 %function
dfx=3*x(i)^2+8*sin(x(i))*(1-cos(x(i))) %derivative of function
y=x(i)-(f/dfx)
i=i+1
x(i) = y;
end
x is an array with all the roots.
Regards
  1 件のコメント
Sam Thorpe
Sam Thorpe 2019 年 3 月 1 日
thanks a lot yasasvi. that is brilliant.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by