Mathematica Asked by Blankquestions on April 6, 2021
I am trying to use Nest
to find result using fixed point iteration method, but when I find $g(x)$ and put it in Nest
, it doesn’t gives me the desired result.
expr = x^3 + x^2 - 1
gx = generateG[expr]
result = Nest[(gx &, 0.5, 10]
(* value of result after 10 iterations *)
1 - x^2)^(1/3)
What I want is:
result = Nest[(1 - #^2)^(1/3) &, 0.5, 10]
(* value after 10 iterations *)
0.686642
expr = x^3 + x^2 - 1;
You have not provided the definition of generateG
The value after 10 iterations is not a good estimate of the fixed point.
(data = NestList[(1 - #^2)^(1/3) &, 0.5`15, 50])[[11]] // N
(* 0.686642 *)
The fixed point is
fp = FixedPoint[(1 - #^2)^(1/3) &, 0.5`15,
SameTest -> (Abs[#1 - #2] < 1*^-15 &)] // N
(* 0.754878 *)
ListPlot[data,
Epilog -> {Red, Line[{{0, fp}, {50, fp}}]}]
The fixed point is equal to the positive root
fp == x /. Solve[{expr == 0, x > 0}, x][[1]]
(* True *)
Answered by Bob Hanlon on April 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP