Working Iterative formula for a system of equations











up vote
3
down vote

favorite












I have been given a project, I need to show the use of a version of Newton's method to solve these non-linear equations. The version of Newton's method I am required to use is: $ X_{n+1} = X_n - J^{(-1)} F(X_n) $. I have all the values required here, and this works to find the point $ X_1 $. However I need to find a code that inputs the following points $ X_2, X_3, ..., X_n $ automatically. Here are the given values:



f[x_, y_] := x^2 + y^2 - 5;
g[x_, y_] := x^3 - y^3 - 7;

x0 = 2.1;
y0 = 0.9;

f[x0, y0]
g[x0, y0]



0.22



1.532




M = {{2*x0, 2*y0}, {3*x0^2, -3*y0^2}}



{{4.2, 1.8}, {13.23, -2.43}}




J = Inverse[M]



{{0.0714286, 0.0529101}, {0.388889, -0.123457}}




F0 = {{f[x0, y0]}, {g[x0, y0]}}
X0 = {{x0}, {y0}}
X1 = X0 - J.F0



{{0.22}, {1.532}}

{{2.1}, {0.9}}

{{2.00323}, {1.00358}}




Thank you in Advance!










share|improve this question









New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3




    Have a look at FixedPoint and FixedPointList and their option SameTest. Nest(List) and NestWhile(List) also come to mind. You can also use FindRoot which has all this built-in.
    – Henrik Schumacher
    3 hours ago












  • Ok Thank you, I will try some of the commands you have listed. Unfortunately, FindRoot does not help me in my situation as I need to show all the iterations leading up to the point, rather than just find the point itself.
    – Andrew Bradley
    2 hours ago










  • Oh, this can also be done with FindRoot: Try Reap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]. Btw.: Using LinearSolve instead of Inverse should be faster for larger systems and should prevent certain problems with precision loss.
    – Henrik Schumacher
    1 hour ago

















up vote
3
down vote

favorite












I have been given a project, I need to show the use of a version of Newton's method to solve these non-linear equations. The version of Newton's method I am required to use is: $ X_{n+1} = X_n - J^{(-1)} F(X_n) $. I have all the values required here, and this works to find the point $ X_1 $. However I need to find a code that inputs the following points $ X_2, X_3, ..., X_n $ automatically. Here are the given values:



f[x_, y_] := x^2 + y^2 - 5;
g[x_, y_] := x^3 - y^3 - 7;

x0 = 2.1;
y0 = 0.9;

f[x0, y0]
g[x0, y0]



0.22



1.532




M = {{2*x0, 2*y0}, {3*x0^2, -3*y0^2}}



{{4.2, 1.8}, {13.23, -2.43}}




J = Inverse[M]



{{0.0714286, 0.0529101}, {0.388889, -0.123457}}




F0 = {{f[x0, y0]}, {g[x0, y0]}}
X0 = {{x0}, {y0}}
X1 = X0 - J.F0



{{0.22}, {1.532}}

{{2.1}, {0.9}}

{{2.00323}, {1.00358}}




Thank you in Advance!










share|improve this question









New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3




    Have a look at FixedPoint and FixedPointList and their option SameTest. Nest(List) and NestWhile(List) also come to mind. You can also use FindRoot which has all this built-in.
    – Henrik Schumacher
    3 hours ago












  • Ok Thank you, I will try some of the commands you have listed. Unfortunately, FindRoot does not help me in my situation as I need to show all the iterations leading up to the point, rather than just find the point itself.
    – Andrew Bradley
    2 hours ago










  • Oh, this can also be done with FindRoot: Try Reap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]. Btw.: Using LinearSolve instead of Inverse should be faster for larger systems and should prevent certain problems with precision loss.
    – Henrik Schumacher
    1 hour ago















up vote
3
down vote

favorite









up vote
3
down vote

favorite











I have been given a project, I need to show the use of a version of Newton's method to solve these non-linear equations. The version of Newton's method I am required to use is: $ X_{n+1} = X_n - J^{(-1)} F(X_n) $. I have all the values required here, and this works to find the point $ X_1 $. However I need to find a code that inputs the following points $ X_2, X_3, ..., X_n $ automatically. Here are the given values:



f[x_, y_] := x^2 + y^2 - 5;
g[x_, y_] := x^3 - y^3 - 7;

x0 = 2.1;
y0 = 0.9;

f[x0, y0]
g[x0, y0]



0.22



1.532




M = {{2*x0, 2*y0}, {3*x0^2, -3*y0^2}}



{{4.2, 1.8}, {13.23, -2.43}}




J = Inverse[M]



{{0.0714286, 0.0529101}, {0.388889, -0.123457}}




F0 = {{f[x0, y0]}, {g[x0, y0]}}
X0 = {{x0}, {y0}}
X1 = X0 - J.F0



{{0.22}, {1.532}}

{{2.1}, {0.9}}

{{2.00323}, {1.00358}}




Thank you in Advance!










share|improve this question









New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have been given a project, I need to show the use of a version of Newton's method to solve these non-linear equations. The version of Newton's method I am required to use is: $ X_{n+1} = X_n - J^{(-1)} F(X_n) $. I have all the values required here, and this works to find the point $ X_1 $. However I need to find a code that inputs the following points $ X_2, X_3, ..., X_n $ automatically. Here are the given values:



f[x_, y_] := x^2 + y^2 - 5;
g[x_, y_] := x^3 - y^3 - 7;

x0 = 2.1;
y0 = 0.9;

f[x0, y0]
g[x0, y0]



0.22



1.532




M = {{2*x0, 2*y0}, {3*x0^2, -3*y0^2}}



{{4.2, 1.8}, {13.23, -2.43}}




J = Inverse[M]



{{0.0714286, 0.0529101}, {0.388889, -0.123457}}




F0 = {{f[x0, y0]}, {g[x0, y0]}}
X0 = {{x0}, {y0}}
X1 = X0 - J.F0



{{0.22}, {1.532}}

{{2.1}, {0.9}}

{{2.00323}, {1.00358}}




Thank you in Advance!







matrix iteration






share|improve this question









New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago









Αλέξανδρος Ζεγγ

3,7321927




3,7321927






New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Andrew Bradley

161




161




New contributor




Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Andrew Bradley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 3




    Have a look at FixedPoint and FixedPointList and their option SameTest. Nest(List) and NestWhile(List) also come to mind. You can also use FindRoot which has all this built-in.
    – Henrik Schumacher
    3 hours ago












  • Ok Thank you, I will try some of the commands you have listed. Unfortunately, FindRoot does not help me in my situation as I need to show all the iterations leading up to the point, rather than just find the point itself.
    – Andrew Bradley
    2 hours ago










  • Oh, this can also be done with FindRoot: Try Reap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]. Btw.: Using LinearSolve instead of Inverse should be faster for larger systems and should prevent certain problems with precision loss.
    – Henrik Schumacher
    1 hour ago
















  • 3




    Have a look at FixedPoint and FixedPointList and their option SameTest. Nest(List) and NestWhile(List) also come to mind. You can also use FindRoot which has all this built-in.
    – Henrik Schumacher
    3 hours ago












  • Ok Thank you, I will try some of the commands you have listed. Unfortunately, FindRoot does not help me in my situation as I need to show all the iterations leading up to the point, rather than just find the point itself.
    – Andrew Bradley
    2 hours ago










  • Oh, this can also be done with FindRoot: Try Reap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]. Btw.: Using LinearSolve instead of Inverse should be faster for larger systems and should prevent certain problems with precision loss.
    – Henrik Schumacher
    1 hour ago










3




3




Have a look at FixedPoint and FixedPointList and their option SameTest. Nest(List) and NestWhile(List) also come to mind. You can also use FindRoot which has all this built-in.
– Henrik Schumacher
3 hours ago






Have a look at FixedPoint and FixedPointList and their option SameTest. Nest(List) and NestWhile(List) also come to mind. You can also use FindRoot which has all this built-in.
– Henrik Schumacher
3 hours ago














Ok Thank you, I will try some of the commands you have listed. Unfortunately, FindRoot does not help me in my situation as I need to show all the iterations leading up to the point, rather than just find the point itself.
– Andrew Bradley
2 hours ago




Ok Thank you, I will try some of the commands you have listed. Unfortunately, FindRoot does not help me in my situation as I need to show all the iterations leading up to the point, rather than just find the point itself.
– Andrew Bradley
2 hours ago












Oh, this can also be done with FindRoot: Try Reap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]. Btw.: Using LinearSolve instead of Inverse should be faster for larger systems and should prevent certain problems with precision loss.
– Henrik Schumacher
1 hour ago






Oh, this can also be done with FindRoot: Try Reap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]. Btw.: Using LinearSolve instead of Inverse should be faster for larger systems and should prevent certain problems with precision loss.
– Henrik Schumacher
1 hour ago












2 Answers
2






active

oldest

votes

















up vote
2
down vote













jac = D[{f[x, y], g[x, y]}, {{x, y}, 1}];
Xlist = NestList[# - Inverse[jac /. Thread[{x, y} -> #]].{f @@ #, g @@ #} &, {x0, y0}, 5]



{{2.1, 0.9}, {2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}, {2., 1.}}




You can get the same from FindRoot:



{res, {steps}} = Reap[FindRoot[{f[x, y], g[x, y]}, {{x, x0}, {y, y0}}, 
Method -> "Newton", StepMonitor :> Sow[{x, y}]]]



{{x -> 2., y -> 1.}, {{{2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}}}}







share|improve this answer























  • The OP may want to see the iterates also.
    – Moo
    2 hours ago










  • Thank you so much, you are my hero!
    – Andrew Bradley
    1 hour ago


















up vote
1
down vote













I'll show it with FixedPointList



f[x_, y_] = {x^2 + y^2 - 5, x^3 - y^3 - 7};
j[x_, y_] = Grad[f[x, y], {x, y}];


with LinearSolve:



FixedPointList[(# - LinearSolve[j[Sequence @@ #], f[Sequence @@ #]]) &, {2.1, 0.9}, 3]
{{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}


with Inverse:



FixedPointList[(# - Inverse[j[Sequence @@ #]].f[Sequence @@ #]) &, {2.1, 0.9}, 3]
{{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}





share|improve this answer





















    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Andrew Bradley is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f187696%2fworking-iterative-formula-for-a-system-of-equations%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    jac = D[{f[x, y], g[x, y]}, {{x, y}, 1}];
    Xlist = NestList[# - Inverse[jac /. Thread[{x, y} -> #]].{f @@ #, g @@ #} &, {x0, y0}, 5]



    {{2.1, 0.9}, {2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}, {2., 1.}}




    You can get the same from FindRoot:



    {res, {steps}} = Reap[FindRoot[{f[x, y], g[x, y]}, {{x, x0}, {y, y0}}, 
    Method -> "Newton", StepMonitor :> Sow[{x, y}]]]



    {{x -> 2., y -> 1.}, {{{2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}}}}







    share|improve this answer























    • The OP may want to see the iterates also.
      – Moo
      2 hours ago










    • Thank you so much, you are my hero!
      – Andrew Bradley
      1 hour ago















    up vote
    2
    down vote













    jac = D[{f[x, y], g[x, y]}, {{x, y}, 1}];
    Xlist = NestList[# - Inverse[jac /. Thread[{x, y} -> #]].{f @@ #, g @@ #} &, {x0, y0}, 5]



    {{2.1, 0.9}, {2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}, {2., 1.}}




    You can get the same from FindRoot:



    {res, {steps}} = Reap[FindRoot[{f[x, y], g[x, y]}, {{x, x0}, {y, y0}}, 
    Method -> "Newton", StepMonitor :> Sow[{x, y}]]]



    {{x -> 2., y -> 1.}, {{{2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}}}}







    share|improve this answer























    • The OP may want to see the iterates also.
      – Moo
      2 hours ago










    • Thank you so much, you are my hero!
      – Andrew Bradley
      1 hour ago













    up vote
    2
    down vote










    up vote
    2
    down vote









    jac = D[{f[x, y], g[x, y]}, {{x, y}, 1}];
    Xlist = NestList[# - Inverse[jac /. Thread[{x, y} -> #]].{f @@ #, g @@ #} &, {x0, y0}, 5]



    {{2.1, 0.9}, {2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}, {2., 1.}}




    You can get the same from FindRoot:



    {res, {steps}} = Reap[FindRoot[{f[x, y], g[x, y]}, {{x, x0}, {y, y0}}, 
    Method -> "Newton", StepMonitor :> Sow[{x, y}]]]



    {{x -> 2., y -> 1.}, {{{2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}}}}







    share|improve this answer














    jac = D[{f[x, y], g[x, y]}, {{x, y}, 1}];
    Xlist = NestList[# - Inverse[jac /. Thread[{x, y} -> #]].{f @@ #, g @@ #} &, {x0, y0}, 5]



    {{2.1, 0.9}, {2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}, {2., 1.}}




    You can get the same from FindRoot:



    {res, {steps}} = Reap[FindRoot[{f[x, y], g[x, y]}, {{x, x0}, {y, y0}}, 
    Method -> "Newton", StepMonitor :> Sow[{x, y}]]]



    {{x -> 2., y -> 1.}, {{{2.0032275, 1.0035802}, {2.0000033, 1.0000051}, {2., 1.}, {2., 1.}}}}








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 hours ago

























    answered 2 hours ago









    Coolwater

    14.4k32452




    14.4k32452












    • The OP may want to see the iterates also.
      – Moo
      2 hours ago










    • Thank you so much, you are my hero!
      – Andrew Bradley
      1 hour ago


















    • The OP may want to see the iterates also.
      – Moo
      2 hours ago










    • Thank you so much, you are my hero!
      – Andrew Bradley
      1 hour ago
















    The OP may want to see the iterates also.
    – Moo
    2 hours ago




    The OP may want to see the iterates also.
    – Moo
    2 hours ago












    Thank you so much, you are my hero!
    – Andrew Bradley
    1 hour ago




    Thank you so much, you are my hero!
    – Andrew Bradley
    1 hour ago










    up vote
    1
    down vote













    I'll show it with FixedPointList



    f[x_, y_] = {x^2 + y^2 - 5, x^3 - y^3 - 7};
    j[x_, y_] = Grad[f[x, y], {x, y}];


    with LinearSolve:



    FixedPointList[(# - LinearSolve[j[Sequence @@ #], f[Sequence @@ #]]) &, {2.1, 0.9}, 3]
    {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}


    with Inverse:



    FixedPointList[(# - Inverse[j[Sequence @@ #]].f[Sequence @@ #]) &, {2.1, 0.9}, 3]
    {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}





    share|improve this answer

























      up vote
      1
      down vote













      I'll show it with FixedPointList



      f[x_, y_] = {x^2 + y^2 - 5, x^3 - y^3 - 7};
      j[x_, y_] = Grad[f[x, y], {x, y}];


      with LinearSolve:



      FixedPointList[(# - LinearSolve[j[Sequence @@ #], f[Sequence @@ #]]) &, {2.1, 0.9}, 3]
      {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}


      with Inverse:



      FixedPointList[(# - Inverse[j[Sequence @@ #]].f[Sequence @@ #]) &, {2.1, 0.9}, 3]
      {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        I'll show it with FixedPointList



        f[x_, y_] = {x^2 + y^2 - 5, x^3 - y^3 - 7};
        j[x_, y_] = Grad[f[x, y], {x, y}];


        with LinearSolve:



        FixedPointList[(# - LinearSolve[j[Sequence @@ #], f[Sequence @@ #]]) &, {2.1, 0.9}, 3]
        {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}


        with Inverse:



        FixedPointList[(# - Inverse[j[Sequence @@ #]].f[Sequence @@ #]) &, {2.1, 0.9}, 3]
        {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}





        share|improve this answer












        I'll show it with FixedPointList



        f[x_, y_] = {x^2 + y^2 - 5, x^3 - y^3 - 7};
        j[x_, y_] = Grad[f[x, y], {x, y}];


        with LinearSolve:



        FixedPointList[(# - LinearSolve[j[Sequence @@ #], f[Sequence @@ #]]) &, {2.1, 0.9}, 3]
        {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}


        with Inverse:



        FixedPointList[(# - Inverse[j[Sequence @@ #]].f[Sequence @@ #]) &, {2.1, 0.9}, 3]
        {{2.1, 0.9}, {2.00323, 1.00358}, {2., 1.00001}, {2., 1.}}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        rmw

        2047




        2047






















            Andrew Bradley is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Andrew Bradley is a new contributor. Be nice, and check out our Code of Conduct.













            Andrew Bradley is a new contributor. Be nice, and check out our Code of Conduct.












            Andrew Bradley is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f187696%2fworking-iterative-formula-for-a-system-of-equations%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu