Message Boards Message Boards

Help with fixed point iterative schemes

Posted 5 months ago

POSTED BY: Kapil Dhankhar
4 Replies
Posted 4 months ago

sir, can you please correct the error? I do not understand your hint. please help me, Sir.

POSTED BY: Kapil Dhankhar

This version runs fine:

T[x_] := (3/4)*(x + 1/x);
m = 1;
a0 = 1;
iterations = 5;
a = {N[a0]};
b = {};
c = {};
implicitEquation[a_, c_] := c == (m/(m + 1))*a + (1/(m + 1))*T[c]
n = 1;
converged = True;
While[n <= iterations && converged,
 (*Solve for c implicitly*)
 Print["Iteration: ", n];
 Print["Current a[[n]]: ", a[[n]]];
 csol = Quiet[FindRoot[implicitEquation[a[[n]], c], {c, a[[n]]}]];
 If[NumericQ[csol[[1, 2]]],
  (*Append the found csol to the list*)
  c = Append[c, N[csol[[1, 2]]]];
  (*Calculate b_n*)
  bsol = T[c[[-1]]];
  b = Append[b, N[bsol]];
  (*Calculate a_(n+1)*)
  asol1 = T[bsol];
  a = Append[a, N[asol1]];
  Print["Computed c_n: ", c[[-1]]];
  Print["Computed b_n: ", bsol];
  Print["Computed a_(n+1): ", asol1];,
  (*Handle non-numeric c_n*)
  converged = False;
  MessageDialog["Error: Non-numeric value
encountered in iteration " <> ToString[n]];];
 n++;]

(*Display the results in a table*)
TableForm[Transpose[{Range[0, Length[a] - 1], a}],
 TableHeadings -> {None, {"Iteration", "a"}}]

(*Plot the results*)
ListLinePlot[a, PlotMarkers -> Automatic,
 GridLines -> Automatic, AxesLabel -> {"Iteration", "a"},
 PlotLabel -> "Implicit Iterations of Example 4"]

I personally would do the iteration using NestList:

NestList[Function[a, T[T[1/5 (2 a + Sqrt[15 + 4 a^2])]]],
  a0, 5] // N
POSTED BY: Gianluca Gorni
Posted 4 months ago

Thank you very much Sir. It helps me a lot.

POSTED BY: Kapil Dhankhar

Beware that c_n, b_n, a_n1 are patterns in Wolfram language, not subscripted variables.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract