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!
matrix iteration
New contributor
add a comment |
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!
matrix iteration
New contributor
3
Have a look atFixedPoint
andFixedPointList
and their optionSameTest
.Nest(List)
andNestWhile(List)
also come to mind. You can also useFindRoot
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 withFindRoot
: TryReap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]
. Btw.: UsingLinearSolve
instead ofInverse
should be faster for larger systems and should prevent certain problems with precision loss.
– Henrik Schumacher
1 hour ago
add a comment |
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!
matrix iteration
New contributor
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
matrix iteration
New contributor
New contributor
edited 2 hours ago
Αλέξανδρος Ζεγγ
3,7321927
3,7321927
New contributor
asked 3 hours ago
Andrew Bradley
161
161
New contributor
New contributor
3
Have a look atFixedPoint
andFixedPointList
and their optionSameTest
.Nest(List)
andNestWhile(List)
also come to mind. You can also useFindRoot
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 withFindRoot
: TryReap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]
. Btw.: UsingLinearSolve
instead ofInverse
should be faster for larger systems and should prevent certain problems with precision loss.
– Henrik Schumacher
1 hour ago
add a comment |
3
Have a look atFixedPoint
andFixedPointList
and their optionSameTest
.Nest(List)
andNestWhile(List)
also come to mind. You can also useFindRoot
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 withFindRoot
: TryReap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]
. Btw.: UsingLinearSolve
instead ofInverse
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
add a comment |
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.}}}}
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
add a comment |
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.}}
add a comment |
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.}}}}
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
add a comment |
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.}}}}
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
add a comment |
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.}}}}
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.}}}}
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
add a comment |
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
add a comment |
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.}}
add a comment |
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.}}
add a comment |
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.}}
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.}}
answered 1 hour ago
rmw
2047
2047
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
3
Have a look at
FixedPoint
andFixedPointList
and their optionSameTest
.Nest(List)
andNestWhile(List)
also come to mind. You can also useFindRoot
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
: TryReap[FindRoot[Sin[x] == 0.2, {x, Pi/42}, EvaluationMonitor :> Sow[x]]]
. Btw.: UsingLinearSolve
instead ofInverse
should be faster for larger systems and should prevent certain problems with precision loss.– Henrik Schumacher
1 hour ago