0
$\begingroup$

I tried to compute the 40-th iteration by FindRoot but without result. Please If any body solve that, I would to thank him. This question has a nonlinear system. And the solution for n=1 is solved. But there is problem when n=2,3, ...40.

The following code for computing the four unknowns for the nonlinear system. The four unknowns : u[0,n], u[1,n], u[2,n], u[3,n] ? Initial conditions:

 u[0, 0] := 0.4720012157682348`; u[1, 0] := 0; 
 u[2, 0] := -0.4994032582704072`; u[3, 0] := 0;

 F1 = -u[0, n] + 99999.99999999999` (-u[0, -1 + n] + u[0, n]) + 
 0.7071067811865475` u[1, n] - 
 70710.67811865473` (-u[1, -1 + n] + u[1, n]) - 16.` u[2, n] - 
 2.775557561562891`*^-12 (-u[2, -1 + n] + u[2, n]) - 
 70710.67811865476` (u[3, -1 + n] - 1.` u[3, n]) + (u[0, n] - 
 0.7071067811865475` u[1, n] - 2.7755575615628914`*^-17 u[2, n] + 
 0.7071067811865477` u[3, n])^2 + 67.17514421272202` u[3, n]

F2 = 0.` - u[0, n] + 99999.99999999999` (-u[0, -1 + n] + u[0, n]) - 
0.7071067811865475` u[1, n] + 
70710.67811865473` (-u[1, -1 + n] + u[1, n]) - 16 u[2, n] + 
70710.67811865442` (u[3, -1 + n] - 1.` u[3, n]) + (0.` + u[0, n] + 
0.7071067811865475` u[1, n] - 0.7071067811865444` u[3, n])^2 - 
67.17514421272199` u[3, n]
F3 = u[0, n] - u[1, n] + u[2, n] - u[3, n]

F4 = u[0, n] + u[1, n] + u[2, n] + u[3, n]

n := 1

Sol = 
FindRoot[{F1 == 0, F2 == 0, F3 == 0, 
F4 == 0}, { {u[0, n], 0.4720012157682348`}, {u[1, n], 
0}, {u[2, n], -0.4994032582704072`}, {u[3, n], 0}}] // Flatten

 {u[0, 1] -> 0.4719281993760747, u[1, 1] -> 0., 
u[2, 1] -> -0.4719281993760747, u[3, 1] -> 0.}
$\endgroup$
  • $\begingroup$ Can you explain a bit more? What do you mean by 40th iteration? What is wrong with the output of FindRoot? $\endgroup$ – anderstood Sep 8 '17 at 21:06
  • 3
    $\begingroup$ Please edit the original question instead of re-posting it. If you fix the problems with it, it will be re-opened, and people might withdraw their downvotes. The problem is still not explained in words. Can you explain it in plain words, in such a way that it will be mostly understandable without having to read the code? $\endgroup$ – Szabolcs Sep 8 '17 at 21:14
  • $\begingroup$ Thank you for advices. Actually I am new to this site. Yes I repeated this question, since I could not edit the last question because the icons not active. So I resent it and edited and added the question in the body of the post. This question has a nonlinear system. And the solution for n=1 is solved. But there is problem when n=2,3, ...40. $\endgroup$ – Khaled Sep 8 '17 at 22:01
  • 2
    $\begingroup$ @Khaled your issue is in how you defined F1, F2, F3 and F4. Their explicit dependence of u[_,1] is the problem. You will want them to depend on u[_,n] instead. I suggest converting each into, e.g. F1[n_] where it constructs the expression with appropriate dependence on n. Then also make Sol a function, like Sol[n_], where you use F1[n]==0, F2[n]==0, etc. $\endgroup$ – b3m2a1 Sep 8 '17 at 23:48
  • $\begingroup$ Thank you b3m2a1. I tried but without results. $\endgroup$ – Khaled Sep 9 '17 at 1:36
0
$\begingroup$

With the Fs defined as in the question, one way to iterate the calculation is

Sol = { u[0, 0] -> 0.4720012157682348`, u[1, 0] -> 0, 
    u[2, 0] -> -0.4994032582704072`, u[3, 0] -> 0};
Do[Sol = FindRoot[{F1, F2, F3, F4} /. Sol, 
    {{u[0, n], 0.4720012157682348`}, {u[1, n], 0}, {u[2, n], -0.4994032582704072`}, 
     {u[3, n], 0}}] // Flatten // Chop; Print[Sol], {n, 40}]

(* {u[0,1]->0.471928,u[1,1]->0,u[2,1]->-0.471928,u[3,1]->0} 
   {u[0,2]->0.471855,u[1,2]->0,u[2,2]->-0.471855,u[3,2]->0}
    ...
   {u[0,39]->0.469162,u[1,39]->0,u[2,39]->-0.469162,u[3,39]->0}
   {u[0,40]->0.46909,u[1,40]->0,u[2,40]->-0.46909,u[3,40]->0} *)

Whether the results should be printed, as here, saved in an array, or post-processed in some way depends on how the results are to be used.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you very much bbgodfrey. $\endgroup$ – Khaled Sep 10 '17 at 20:49
0
$\begingroup$

I guess you want something like that:

fr1[0] = {u[0, 0] -> 0.4720012157682348`, u[1, 0] -> 0,
          u[2, 0] -> -0.4994032582704072`, u[3, 0] -> 0}

F1[n_] = -u[0, n] + 99999.99999999999` (-u[0, -1 + n] + u[0, n]) + 
         0.7071067811865475` u[1, n] - 
        70710.67811865473` (-u[1, -1 + n] + u[1, n]) - 16.` u[2, n] - 
        2.775557561562891`*^-12 (-u[2, -1 + n] + u[2, n]) - 
        70710.67811865476` (u[3, -1 + n] - 1.` u[3, n]) + (u[0, n] - 
        0.7071067811865475` u[1, n] - 2.7755575615628914`*^-17 u[2, n] + 
        0.7071067811865477` u[3, n])^2 + 67.17514421272202` u[3, n]

Define the F2,F3,F4 the same way

Calculate a table of FindRoot solutions fr1[n], each time inserting fr1[n-1]

tab = Union[{fr1[0]}, 
       Table[fr1[n] = 
         FindRoot[{F1[n] == 0, F2[n] == 0, F3[n] == 0, F4[n] == 0} /. 
            fr1[n - 1], {{u[0, n], 1}, {u[1, n], 
            1}, {u[2, n], -1}, {u[3, n], 1}}], {n, 1, 40}]] // Flatten;

Plot the solution points

Table[ListPlot[Table[u[j, n] /. tab, {n, 0, 40}]], {j, 0, 3}]

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you very much Akku14. $\endgroup$ – Khaled Sep 10 '17 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.