Mathematica I need a little bit help about mathematica

  • Thread starter Thread starter sedat
  • Start date Start date
  • Tags Tags
    Bit Mathematica
AI Thread Summary
The discussion revolves around solving two non-linear equations using Mathematica's FindRoot and NSolve functions to obtain independent roots for variables x and y. The user seeks to extract these roots separately for plotting in a 2D coordinate system, specifically for angles ranging from 0 to 360 degrees. Initial attempts resulted in complex-conjugate roots, prompting a need for real roots instead. Suggestions included using NSolve to find roots, followed by plotting the imaginary components to identify real roots. The final solution involved selecting only real roots from the computed values and using ListPlot to visualize them as a point cloud in 2D. The user confirmed that the proposed solution worked effectively for their needs.
sedat
Messages
15
Reaction score
0
Hello, my problem is that I could not be able to find to separate the roots with the command of FindRoot. Altough I have 2 non-linear equations, I can solve these with FindRooot, but I'd like to have separetely the roots I mean independent roots each other (x apart and y apart). I wonder if i can print this in mathematica or not.

Since i need it to get into a equation separetely. After having the roots apart apart, I will need to have a loop from 0 degree to 359 degree in order to have X-Y loci.

I will be very gratefull If somebody helps me on this issue.

Already Thanks
Sending a print screen
 

Attachments

  • adsız.JPG
    adsız.JPG
    20.6 KB · Views: 466
Physics news on Phys.org
Looking forward to hearing smth from you...
 
Your FindRoot[] is going to return {T->nn.nnn, P->mm.mmm}.

It is unclear what you expect from the ArcTan[] following that. It has no trailing ; Can you explain what you expect the ArcTan[] to do.

N is a special symbol for Mathematica, I suggest using some other name.

Inside your For[] are you looking for the solution in T and P for the 12 angles a? If you can explain what you want for a result then perhaps I can suggest how to change this.
 
Bill Simpson said:
Your FindRoot[] is going to return {T->nn.nnn, P->mm.mmm}.

It is unclear what you expect from the ArcTan[] following that. It has no trailing ; Can you explain what you expect the ArcTan[] to do.

N is a special symbol for Mathematica, I suggest using some other name.

Inside your For[] are you looking for the solution in T and P for the 12 angles a? If you can explain what you want for a result then perhaps I can suggest how to change this.[/QUOT

I am looking for X and Y values for each angles till 12 degress, but I'd like to have X and Y as apart form, namely; printing X and then Y values seperately on the screen that I can put these into different equations. As to Tan, I just realized it is unnecessary maybe I put it into another step soon. After getting X and Y values, I need to plot these in 2D graphics represantation as well.

I hope that it is clear now.
 
Last edited:
Replace beginning at your FindRoot[] with this

M=NSolve[{T,P},{x,y}];

and then

xroots=Table[x/.M,{a,0,11}]

and then

yroots=Table[y/.M,{a,0,11}]

Tell me if those are the correct solutions to the original problem.

For graphics, since it looks like you have 12 conjugate pairs of roots for x and for y, are you expecting the graphics to be two plots of 12 pairs of points in the complex plane? I can't tell what form you want your graphics to be in.
 
Bill Simpson said:
Replace beginning at your FindRoot[] with this

M=NSolve[{T,P},{x,y}];

and then

xroots=Table[x/.M,{a,0,11}]

and then

yroots=Table[y/.M,{a,0,11}]

Tell me if those are the correct solutions to the original problem.

For graphics, since it looks like you have 12 conjugate pairs of roots for x and for y, are you expecting the graphics to be two plots of 12 pairs of points in the complex plane? I can't tell what form you want your graphics to be in.

I wrote your suggestions into the programme and I saw that I have complex-conjugate roots as you predicted before, but I need to have only real roots and I trace the roots into a plotting in X-Y coordinate system.
 
Since you seem to be interested in 0<=a<=12 degrees and you must have real roots, If I use
M = NSolve[{T, P}, {x, y}];
xroots = x/.M;
yroots = y/.M;
and then look at these one at a time
Plot[Im[First[xroots]],{a,0,12}]
Plot[Im[Last[xroots]],{a,0,12}]
Plot[Im[First[yroots]],{a,0,12}]
Plot[Im[Last[yroots]],{a,0,12}]
that gives me an idea where you will have zero imaginary component and thus a real root.

Study those four plots and see what you can decide about real roots for your problem.
 
Bill Simpson said:
Since you seem to be interested in 0<=a<=12 degrees and you must have real roots, If I use
M = NSolve[{T, P}, {x, y}];
xroots = x/.M;
yroots = y/.M;
and then look at these one at a time
Plot[Im[First[xroots]],{a,0,12}]
Plot[Im[Last[xroots]],{a,0,12}]
Plot[Im[First[yroots]],{a,0,12}]
Plot[Im[Last[yroots]],{a,0,12}]
that gives me an idea where you will have zero imaginary component and thus a real root.

Study those four plots and see what you can decide about real roots for your problem.

source code is the following,

l1 = 40.1039;
l2 = 12;
l3 = 41.8413;
l4 = 42.2413;
l5 = 35.5833;
T = (x - l1*Cos[a Degree])^2 + (y - l1*Sin[a Degree])^2 - (l2 + l3)^2 == 0;
P = y^2 + (l5 - x)^2 - l4^2 == 0;
M = NSolve[{T, P}, {x, y}];
S = For[a = 0, a < 360, a++, Print[M]];
xroots = Table[x /. M, {a, 0, 360}];
yroots = Table[y /. M, {a, 0, 360}];
Plot[Im[First[xroots]], {a, 0, 360}]
Plot[Im[Last[xroots]], {a, 0, 360}]
Plot[Im[First[yroots]], {a, 0, 360}]
Plot[Im[Last[yroots]], {a, 0, 360}]

everything is fine apart from plotting, What I expect, my friend ; is to have a point-cloud in the plotting including all the real roots in 2D x and y

Thank you
 
M = NSolve[{T, P}, {x, y}];
roots = Table[{x, y} /. M, {a, 0, 360}];
realroots = Select[Flatten[roots, 1], Element[First[#], Reals] && Element[Last[#], Reals] &];
ListPlot[realroots]
 
  • #10
Bill Simpson said:
M = NSolve[{T, P}, {x, y}];
roots = Table[{x, y} /. M, {a, 0, 360}];
realroots = Select[Flatten[roots, 1], Element[First[#], Reals] && Element[Last[#], Reals] &];
ListPlot[realroots]

Thank you my friend, it works very well.
 

Similar threads

Replies
2
Views
2K
Replies
1
Views
1K
Replies
5
Views
2K
Replies
6
Views
10K
Replies
1
Views
5K
Replies
1
Views
2K
Replies
4
Views
3K
Back
Top