Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
code for function equality

Subject: code for function equality

From: Hatoddyam Toto

Date: 13 Apr, 2010 20:57:04

Message: 1 of 3

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

Subject: code for function equality

From: Walter Roberson

Date: 13 Apr, 2010 21:21:04

Message: 2 of 3

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.

Subject: code for function equality

From: John D'Errico

Date: 13 Apr, 2010 21:59:06

Message: 3 of 3

Hatoddyam Toto <bhattacharyya.samit@gmail.com> wrote in message <cd3b7890-66ba-4690-8ce4-8ca2538d33d0@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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us