Working Iterative formula for a system of equations












3














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




















  • 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
    Dec 11 at 12:32












  • 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
    Dec 11 at 13:02










  • 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
    Dec 11 at 14:20


















3














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




















  • 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
    Dec 11 at 12:32












  • 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
    Dec 11 at 13:02










  • 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
    Dec 11 at 14:20
















3












3








3







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















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















share|improve this question













share|improve this question




share|improve this question








edited Dec 11 at 13:05









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

4,0421928




4,0421928










asked Dec 11 at 12:17









Andrew Bradley

161




161








  • 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
    Dec 11 at 12:32












  • 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
    Dec 11 at 13:02










  • 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
    Dec 11 at 14:20
















  • 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
    Dec 11 at 12:32












  • 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
    Dec 11 at 13:02










  • 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
    Dec 11 at 14:20










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
Dec 11 at 12:32






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
Dec 11 at 12:32














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
Dec 11 at 13:02




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
Dec 11 at 13:02












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
Dec 11 at 14:20






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
Dec 11 at 14:20












2 Answers
2






active

oldest

votes


















2














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























  • Thank you so much, you are my hero!
    – Andrew Bradley
    Dec 11 at 13:48



















1














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',
    autoActivateHeartbeat: false,
    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
    });


    }
    });














    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









    2














    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























    • Thank you so much, you are my hero!
      – Andrew Bradley
      Dec 11 at 13:48
















    2














    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























    • Thank you so much, you are my hero!
      – Andrew Bradley
      Dec 11 at 13:48














    2












    2








    2






    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 Dec 11 at 13:17

























    answered Dec 11 at 13:02









    Coolwater

    14.6k32552




    14.6k32552












    • Thank you so much, you are my hero!
      – Andrew Bradley
      Dec 11 at 13:48


















    • Thank you so much, you are my hero!
      – Andrew Bradley
      Dec 11 at 13:48
















    Thank you so much, you are my hero!
    – Andrew Bradley
    Dec 11 at 13:48




    Thank you so much, you are my hero!
    – Andrew Bradley
    Dec 11 at 13:48











    1














    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


























      1














      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
























        1












        1








        1






        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 Dec 11 at 13:46









        rmw

        2047




        2047






























            draft saved

            draft discarded




















































            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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

             ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕