Re: Sovling non-linear eq-sys (beginners question)
- To: mathgroup at smc.vnet.net
- Subject: [mg71232] Re: [mg71207] Sovling non-linear eq-sys (beginners question)
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 11 Nov 2006 03:38:17 -0500 (EST)
- Reply-to: hanlonr at cox.net
A numeric solution is more practical Needs["Graphics`"]; ellipseParameters[pts_List/;Length[pts]==4, {ox_Symbol,oy_Symbol,s_Symbol,b_Symbol}]:= Module[{x,y,eqn,sub,param}, eqn=(x-ox)^2/s^2+(y-oy)^2/b^2==1; sub=Thread[{x,y}->#]&/@pts; param=Select[Solve[eqn/.sub,{ox,oy,s,b}], FreeQ[#,Complex]&&(b>0 && s>0/.#)&]//Flatten]; While[pts=Table[ {Random[Real,{1/4,3/4}],Random[Real,{1/4,3/4}]},{4}]; Length[param=ellipseParameters[pts,{ox,oy,s,b}]]<1,]; eqn=(x-ox)^2/s^2+(y-oy)^2/b^2==1/.param ImplicitPlot[eqn, {x,-0.01,1.5}, Epilog->{Red,AbsolutePointSize[6],Point/@pts}, ImageSize->288,Frame->True,Axes->False, PlotRange->{{0,1},{0,1}}]; Bob Hanlon ---- 17538 at student.hhs.se wrote: > I wonder how I can use Mathematica to solve a system of non-linear > equations. > > If I want to find the parameters of an ellipse, given coordinates of > some points on it, then I have a system of four non-linear equations. > Where should I go from here in order to make Mathematica help me with > the substitutions necessary to express each parameter as a function of > the coordinates of the points? > > Here follows an example: > > The formula of an ellipse (with an axis parallell to the x-axis of the > coordinate system) is: > > (x-ox)^2 / s^2 + (y-oy)^2 / b^2 = 1 > > where > s: half length of small axis. > b: half length of big axis. > ox: x-coordinate of the center of the ellipse. > oy: y-coordinate of the center of the ellipse. > x,y: coordinates of a point on perimeter of the ellipse. > > I solve for each of the 4 parameters s, b, ox, oy and insert unique > {x,y}-values in each equation: > s = f(x1,y1,b,ox,oy) > b = f(x2,y2,s,ox,oy) > ox = f(x3,y3,b,s,oy) > oy = f(x4,y4,b,s,ox) > > [Of course, there are two functions for each parameter, one describing > the upper half and the other describing the lower half, so to speak.] > > Now I should be able to substitute my way to a solution like this: > > Inserting b = f(x2,y2,s,ox,oy) in s = f(x1,y1,b,ox,oy) gives: > s = f(x1,y1,f(x2,y2,s,ox,oy),ox,oy) > > Solving for s gives: > s = f(x1,y1,x2,y2,ox,oy) > > And then continue with inserting oy = f(...) in s' = f(...) above and > again solving for s, then the same with ox so that I arrive at s = > f(x1,y1,x2,y2,x3,y3,x4,y4). Then the procedure is repeated with each of > the other parameters b, ox, oy. > > The thing is that it gets quite tedious even for a pretty simple > problem like this. And what about doing it for an ellipse with a tilted > axis (not parallell with the x-axis of the coordinate system)? That > would introduce a new parameter, a new equation in the system and > significantly longer equations too (maybe it is pointless to work with > algebraic solutions in that case anyway). > > So, what tricks can Mathematica perform in order to do the work for me? > > I'm grateful for any comments or reference that could help me! >