From: Hatoddyam Toto on
Hi,
I have two functions f1(x1,x2) and f2(x1,x2). I want to get
the value of x1 and x2 from interval (a,b) such that f1=f2 (up to n-
decimal). More clearly,

choose x1,x2 from (a,b);
if |f1(x1,x2) - f2(x1,x2)|<0.00001
done
if |f1(x1,x2) - f2(x1,x2)|>0.00001
choose another x1 and x2 and again it will check
and thus it will continue until to get the values

How to write the code for it? Is there any in-built function in matlab
to do that? Note that x1 and x2 are real valued, not a integer.

Thanks for your help,

Gordon
From: Walter Roberson on
Hatoddyam Toto wrote:
> Hi,
> I have two functions f1(x1,x2) and f2(x1,x2). I want to get
> the value of x1 and x2 from interval (a,b) such that f1=f2 (up to n-
> decimal). More clearly,
>
> choose x1,x2 from (a,b);
> if |f1(x1,x2) - f2(x1,x2)|<0.00001
> done
> if |f1(x1,x2) - f2(x1,x2)|>0.00001
> choose another x1 and x2 and again it will check
> and thus it will continue until to get the values
>
> How to write the code for it? Is there any in-built function in matlab
> to do that? Note that x1 and x2 are real valued, not a integer.

Perhaps if you used one of the minimizers, giving it a function handle and
space for two variables, each of which you would provide with the bounds (a,b)
? The function handle would do (f1(x1,x2) - f2(x1,x2)).^2 and you would have
told the minimizer that the tolerance was 0.00001 ?

This would not be the same as randomly choosing values from the interval until
you found something, but it could take advantage of the information from
different function calls in order to determine the direction of change of the
variables most likely to produce the required conditions. That should be
faster than just trying points at random.


Note: several of the minimizers assume that the function is continuous, at
least in the first differential (that's why I used the square of the
difference instead of the absolute value). If that is not true for your
functions then you may be restricted in your choice of minimizers.
From: John D'Errico on
Hatoddyam Toto <bhattacharyya.samit(a)gmail.com> wrote in message <cd3b7890-66ba-4690-8ce4-8ca2538d33d0(a)y14g2000yqm.googlegroups.com>...
> Hi,
> I have two functions f1(x1,x2) and f2(x1,x2). I want to get
> the value of x1 and x2 from interval (a,b) such that f1=f2 (up to n-
> decimal). More clearly,
>
> choose x1,x2 from (a,b);
> if |f1(x1,x2) - f2(x1,x2)|<0.00001
> done
> if |f1(x1,x2) - f2(x1,x2)|>0.00001
> choose another x1 and x2 and again it will check
> and thus it will continue until to get the values
>
> How to write the code for it? Is there any in-built function in matlab
> to do that? Note that x1 and x2 are real valued, not a integer.
>
> Thanks for your help,
>
> Gordon

Whether or not you realize it, you are trying to do
a contour plot.

In general, there may be a curvilinear set of points
(x1,x2), such that

F(x1,x2) = abs(f1(x1,x2) - f2(x1,x2)) == 0

As I said, that is what contour does.

Searching using a random scheme seems a silly thing
to do here.

HTH,
John