Register to reply

Finding Numerically the solution line for an equation

by LayMuon
Tags: equation, line, numerically, solution
Share this thread:
LayMuon
#1
Dec10-12, 07:03 PM
P: 148
I have a function which depends say upon two variables: [itex] f(x,y) [/itex].

I need to find numerically the solution line [itex] y(x) [/itex] of the equation [itex] f(x,y) = 0 [/itex]. The function itself for arbitrary set of {x,y} may evaluate to some complex number (it involves lots of square roots) but for the solution I am seeking the imaginary part on the solution line should be zero. I understand that one in principal can scan through the whole region of {x,y} to get the curve but I need numerically efficient way to write the code.

Thanks.
Phys.Org News Partner Science news on Phys.org
Scientists develop 'electronic nose' for rapid detection of C. diff infection
Why plants in the office make us more productive
Tesla Motors dealing as states play factory poker
haruspex
#2
Dec11-12, 03:21 AM
Homework
Sci Advisor
HW Helper
Thanks
P: 9,863
Is f(x,y) differentiable analytically? I'll assume not, but I will assume it's continuous.
If you can feed in a feasible range for y(x0) then you could program a binary chop on the values. (Do I need to explain that?) Having found one point on the line, (x0, y0), you could then search for solutions of f(x,y) = 0 where the |(x,y)-(x0, y0)| = some small r. Again, you could do a binary chop on the direction from (x0, y0) to (x,y).
LayMuon
#3
Dec11-12, 12:35 PM
P: 148
What is "binary chop"?

HallsofIvy
#4
Dec11-12, 07:56 PM
Math
Emeritus
Sci Advisor
Thanks
PF Gold
P: 39,556
Finding Numerically the solution line for an equation

If [itex]f(x_0, y_0)> 0[/itex] and [itex]f(x_1, y_1)< 0[/itex] then, because f is continuous, there must be a point between [itex](x_0, y_0)[/itex] and [itex](x_1, y_1)[/itex] where f is 0. We have no idea where so checking one point is as good as another- use the midpoint, [itex](x_2, y_2)= ((x_0+ x_1)/2, (y_0+ y_1)/2)[/itex]. Now look at [itex]f(x_2, y_2)[/itex]. If it is 0, we are done! If not, it is either positive or negative. If it is positive, then, since [itex]f(x_1, y_1)< 0[/itex], there must be a solution between them. If it is negative, then, since [itex]f(x_0, y_0)> 0[/itex], there be a solution between them. In either case, define [itex](x_3, y_3)[/itex] to be the mid point of that interval.

That is, I think, what haruspex is calling a "binary chop". I would call it a "binary search".
LayMuon
#5
Dec11-12, 08:17 PM
P: 148
My concern is that f(x,y) does not evaluate necessarily to real value, it might as well be complex, so it being positive or negative is not well defined.
haruspex
#6
Dec11-12, 08:36 PM
Homework
Sci Advisor
HW Helper
Thanks
P: 9,863
Quote Quote by LayMuon View Post
My concern is that f(x,y) does not evaluate necessarily to real value, it might as well be complex, so it being positive or negative is not well defined.
That's not a problem. 0 is 0, and the modulus of f is zero if and only if f is 0.
LayMuon
#7
Dec11-12, 08:44 PM
P: 148
Quote Quote by haruspex View Post
That's not a problem. 0 is 0, and the modulus of f is zero if and only if f is 0.
But then if you are taking |f(x,y)| how do you implement the comparisons of where it is positive and where negative?
haruspex
#8
Dec11-12, 08:54 PM
Homework
Sci Advisor
HW Helper
Thanks
P: 9,863
Quote Quote by LayMuon View Post
But then if you are taking |f(x,y)| how do you implement the comparisons of where it is positive and where negative?
Ooops! Yes, you're right, sorry. Let me think some more.
haruspex
#9
Dec11-12, 09:11 PM
Homework
Sci Advisor
HW Helper
Thanks
P: 9,863
OK, instead of doing the binary chop based on the sign of f, you can look for local minima of |f|. This is a bit trickier because you need to track three 'current' points. E.g. if |f(x,y0)| > |f(x,y1)| < |f(x,y2)|, y0 < y1 < y2, then you know there is a min between y0 and y2. So next pick y3 = (y0 + y2). If |f(x,y3)| > |f(x,y1)| then you know there's one between y3 and y2. But it might turn out to be > 0, and there could be a min between y0 and y3.
LayMuon
#10
Dec11-12, 09:15 PM
P: 148
Quote Quote by haruspex View Post
OK, instead of doing the binary chop based on the sign of f, you can look for local minima of |f|. This is a bit trickier because you need to track three 'current' points. E.g. if |f(x,y0)| > |f(x,y1)| < |f(x,y2)|, y0 < y1 < y2, then you know there is a min between y0 and y2. So next pick y3 = (y0 + y2). If |f(x,y3)| > |f(x,y1)| then you know there's one between y3 and y2. But it might turn out to be > 0, and there could be a min between y0 and y3.
but in that case you would just find local minima of the function, not zeros.
haruspex
#11
Dec11-12, 10:25 PM
Homework
Sci Advisor
HW Helper
Thanks
P: 9,863
Quote Quote by LayMuon View Post
but in that case you would just find local minima of the function, not zeros.
Since |f| ≥ 0, every zero will be a local minimum. So if you find all the minima you will find all the zeroes.
LayMuon
#12
Dec11-12, 11:44 PM
P: 148
But not all local minima are the zeros
LayMuon
#13
Dec12-12, 12:16 AM
P: 148
And another problematic thing with what you suggest is that you have to literally scan all x values, the problem is like for single variable case. I was more looking to be able to dispense with scanning x fully.
haruspex
#14
Dec12-12, 12:23 AM
Homework
Sci Advisor
HW Helper
Thanks
P: 9,863
Quote Quote by LayMuon View Post
But not all local minima are the zeros
Quite so.
And another problematic thing with what you suggest is that you have to literally scan all x values, the problem is like for single variable case. I was more looking to be able to dispense with scanning x fully.
As I understood it, you want to plot y as a function of x. So you would choose whatever set of x values then for each one try to find that y for which f(x,y)=0. All I can offer is some way to find those corresponding y values.


Register to reply

Related Discussions
Finding Equation of an Orthogonal Line Calculus & Beyond Homework 3
Finding the equation for the tangent line. Calculus & Beyond Homework 6
Finding the equation of a line Calculus 3
Finding equation of a line Precalculus Mathematics Homework 3