Skip to main content
Became Hot Network Question
deleted 2 characters in body
Source Link
onk
  • 119
  • 4

I am trying to construct basins of attraction using the newton's method for the system of two equations whose roots are real. I need to develop a code to get basin of attraction. Unfortunately, my code does not work. Can anyone please help me find the error in my code? I don't understand what exactly the problem is. My code for the basins of attraction is given below:

ClearAll["Global`*"]
r1 = {-1, -1};
r2 = {0, 0};
r3 = {1, 1};

x = Range[-2, 2, 0.02];
y = Range[-2, 2, 0.02];

Xr1 = {}; Xr2 = {}; Xr3 = {}; Xr4 = {};

Do[Do[X0 = {x[[i]], y[[j]]};
X = {x[[i]], y[[j]]};
NoIter = 5;
Do[f = {X[[1]]^3 - X[[2]], X[[2]]^3 - X[[1]]};
 Jf = {{3*X[[1]]^2 - 1, -1}, {-1, 3*X[[2]]^2}};
 X = X - Inverse[Jf].f, {NoIter}];
If[Norm[X - r1] < 1 e - 25, Xr1 = Append[Xr1, X0], 
 If[Norm[X - r2] < 1 e - 25, Xr2 = Append[Xr2, X0], 
  If[Norm[X - r3] < 1 e - 25, Xr3 = Append[Xr3, X0], 
   Xr4 = Append[Xr4, X0]]]], {j, Length[y]}], {i, Length[x]}];

ListPlot[{Xr1, Xr2, Xr3, Xr4}, PlotStyle -> {Red, Blue, Green, Black},
AspectRatio -> 1, PlotRange -> {{-2, 2}, {-2, 2}}, Frame -> True, 
FrameLabel -> {"x", "y"}, PlotLegends -> {"r1", "r2", "r3", "r4"}, 
PlotLabel -> 
"Basin of attraction for f(x,y) = x^3-y = 0 and y^3-x=0"] ``` 



 

I am trying to construct basins of attraction using the newton's method for the system of two equations whose roots are real. I need to develop a code to get basin of attraction. Unfortunately, my code does not work. Can anyone please help me find the error in my code? I don't understand what exactly the problem is. My code for the basins of attraction is given below:

ClearAll["Global`*"]
r1 = {-1, -1};
r2 = {0, 0};
r3 = {1, 1};

x = Range[-2, 2, 0.02];
y = Range[-2, 2, 0.02];

Xr1 = {}; Xr2 = {}; Xr3 = {}; Xr4 = {};

Do[Do[X0 = {x[[i]], y[[j]]};
X = {x[[i]], y[[j]]};
NoIter = 5;
Do[f = {X[[1]]^3 - X[[2]], X[[2]]^3 - X[[1]]};
 Jf = {{3*X[[1]]^2 - 1, -1}, {-1, 3*X[[2]]^2}};
 X = X - Inverse[Jf].f, {NoIter}];
If[Norm[X - r1] < 1 e - 25, Xr1 = Append[Xr1, X0], 
 If[Norm[X - r2] < 1 e - 25, Xr2 = Append[Xr2, X0], 
  If[Norm[X - r3] < 1 e - 25, Xr3 = Append[Xr3, X0], 
   Xr4 = Append[Xr4, X0]]]], {j, Length[y]}], {i, Length[x]}];

ListPlot[{Xr1, Xr2, Xr3, Xr4}, PlotStyle -> {Red, Blue, Green, Black},
AspectRatio -> 1, PlotRange -> {{-2, 2}, {-2, 2}}, Frame -> True, 
FrameLabel -> {"x", "y"}, PlotLegends -> {"r1", "r2", "r3", "r4"}, 
PlotLabel -> 
"Basin of attraction for f(x,y) = x^3-y = 0 and y^3-x=0"] ```

 

I am trying to construct basins of attraction using the newton's method for the system of two equations whose roots are real. I need to develop a code to get basin of attraction. Unfortunately, my code does not work. Can anyone please help me find the error in my code? I don't understand what exactly the problem is. My code for the basins of attraction is given below:

ClearAll["Global`*"]
r1 = {-1, -1};
r2 = {0, 0};
r3 = {1, 1};

x = Range[-2, 2, 0.02];
y = Range[-2, 2, 0.02];

Xr1 = {}; Xr2 = {}; Xr3 = {}; Xr4 = {};

Do[Do[X0 = {x[[i]], y[[j]]};
X = {x[[i]], y[[j]]};
NoIter = 5;
Do[f = {X[[1]]^3 - X[[2]], X[[2]]^3 - X[[1]]};
 Jf = {{3*X[[1]]^2, -1}, {-1, 3*X[[2]]^2}};
 X = X - Inverse[Jf].f, {NoIter}];
If[Norm[X - r1] < 1 e - 25, Xr1 = Append[Xr1, X0], 
 If[Norm[X - r2] < 1 e - 25, Xr2 = Append[Xr2, X0], 
  If[Norm[X - r3] < 1 e - 25, Xr3 = Append[Xr3, X0], 
   Xr4 = Append[Xr4, X0]]]], {j, Length[y]}], {i, Length[x]}];

ListPlot[{Xr1, Xr2, Xr3, Xr4}, PlotStyle -> {Red, Blue, Green, Black},
AspectRatio -> 1, PlotRange -> {{-2, 2}, {-2, 2}}, Frame -> True, 
FrameLabel -> {"x", "y"}, PlotLegends -> {"r1", "r2", "r3", "r4"}, 
PlotLabel -> 
"Basin of attraction for f(x,y) = x^3-y = 0 and y^3-x=0"]  



 
Source Link
onk
  • 119
  • 4

Basins of attraction using Newton-Raphson method for nonlinear system

I am trying to construct basins of attraction using the newton's method for the system of two equations whose roots are real. I need to develop a code to get basin of attraction. Unfortunately, my code does not work. Can anyone please help me find the error in my code? I don't understand what exactly the problem is. My code for the basins of attraction is given below:

ClearAll["Global`*"]
r1 = {-1, -1};
r2 = {0, 0};
r3 = {1, 1};

x = Range[-2, 2, 0.02];
y = Range[-2, 2, 0.02];

Xr1 = {}; Xr2 = {}; Xr3 = {}; Xr4 = {};

Do[Do[X0 = {x[[i]], y[[j]]};
X = {x[[i]], y[[j]]};
NoIter = 5;
Do[f = {X[[1]]^3 - X[[2]], X[[2]]^3 - X[[1]]};
 Jf = {{3*X[[1]]^2 - 1, -1}, {-1, 3*X[[2]]^2}};
 X = X - Inverse[Jf].f, {NoIter}];
If[Norm[X - r1] < 1 e - 25, Xr1 = Append[Xr1, X0], 
 If[Norm[X - r2] < 1 e - 25, Xr2 = Append[Xr2, X0], 
  If[Norm[X - r3] < 1 e - 25, Xr3 = Append[Xr3, X0], 
   Xr4 = Append[Xr4, X0]]]], {j, Length[y]}], {i, Length[x]}];

ListPlot[{Xr1, Xr2, Xr3, Xr4}, PlotStyle -> {Red, Blue, Green, Black},
AspectRatio -> 1, PlotRange -> {{-2, 2}, {-2, 2}}, Frame -> True, 
FrameLabel -> {"x", "y"}, PlotLegends -> {"r1", "r2", "r3", "r4"}, 
PlotLabel -> 
"Basin of attraction for f(x,y) = x^3-y = 0 and y^3-x=0"] ```