comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: matrix division
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: matrix division [message #60421] Thu, 22 May 2008 05:59 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
d.poreh@gmail.com writes:

> Sorry!!! Yes as you mentioned above b> eps but 0<eps. Doesn=92t it? I
> mean how we can reach something like b/0=3Db/eps???

If you divide by zero you get positive or negative
infinity. If you divide by something very close to
zero, you get a very big number, but not infinity.
In code, it is better to have a very big number rather
than an INF. This just makes sure get a big number.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60422 is a reply to message #60421] Thu, 22 May 2008 05:55 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
James Kuyper writes:

> What if b is < 0?

I was hoping you would tell me, so I didn't have to
think about it anymore. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60423 is a reply to message #60422] Thu, 22 May 2008 05:47 Go to previous messageGo to next message
jameskuyper is currently offline  jameskuyper
Messages: 79
Registered: October 2007
Member
d.poreh@gmail.com wrote:
>> I think, in this situation with integers:
>>
>> IDL> eps = (Machar()).eps
>> IDL> c = Float(a) / (b > eps)
...
> b>eps??? but 0<eps!!!!!!

Hint: In IDL, "b > eps" means something quite different from "b gt eps".
Understand that difference, and the code makes a little more sense.
Re: matrix division [message #60425 is a reply to message #60423] Thu, 22 May 2008 05:42 Go to previous messageGo to next message
jameskuyper is currently offline  jameskuyper
Messages: 79
Registered: October 2007
Member
David Fanning wrote:
> d.poreh@gmail.com writes:
>
>> how we can avoid dividing by zero?in matlab we use *eps* what about
>> IDL?
>
> I think, in this situation with integers:
>
> IDL> eps = (Machar()).eps
> IDL> c = Float(a) / (b > eps)

What if b is < 0?
Re: matrix division [message #60426 is a reply to message #60425] Thu, 22 May 2008 05:40 Go to previous messageGo to next message
d.poreh is currently offline  d.poreh
Messages: 406
Registered: October 2007
Senior Member
On May 22, 2:29 pm, David Fanning <n...@dfanning.com> wrote:
> d.po...@gmail.com writes:
>> b>eps??? but 0<eps!!!!!!
>
> Lo siento. Habla Ingles?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Sorry!!! Yes as you mentioned above b> eps but 0<eps. Doesn’t it? I
mean how we can reach something like b/0=b/eps???
Cheers
Re: matrix division [message #60427 is a reply to message #60426] Thu, 22 May 2008 05:29 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
d.poreh@gmail.com writes:

> b>eps??? but 0<eps!!!!!!

Lo siento. Habla Ingles?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60428 is a reply to message #60427] Thu, 22 May 2008 05:24 Go to previous messageGo to next message
d.poreh is currently offline  d.poreh
Messages: 406
Registered: October 2007
Senior Member
> I think, in this situation with integers:
>
>    IDL> eps = (Machar()).eps
>    IDL> c = Float(a) / (b > eps)
>
> It would be slightly more complicated with floats, and I haven't
> had my coffee yet.
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

b>eps??? but 0<eps!!!!!!
Cheers,
Re: matrix division [message #60429 is a reply to message #60428] Thu, 22 May 2008 05:13 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
adam.ranson@bris.ac.uk writes:

> Thanks for the quick response David! This is the way I'd
> assumed it would be done but doesn't give me the numbers
> back I'd expect. For example:
>
> I = [[1, 2, 2],[2,1,1]]
> C = [[8, 2, 8],[2,8,1]]
> Z = I/C
>
> IDL> print, z gives...
> 0 1 0
> 1 0 1
>
> I want to divide 1 by 8, 2 by 2, 2 by 8, 2 by 2, 1 by 8 & 1 by 1.

Well, this is integer division, so this is what you hope
will happen, given the rules of integer division. If you
want something else, try this:

IDL> c = Float(a) / b

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60431 is a reply to message #60429] Thu, 22 May 2008 05:08 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
d.poreh@gmail.com writes:

> how we can avoid dividing by zero?in matlab we use *eps* what about
> IDL?

I think, in this situation with integers:

IDL> eps = (Machar()).eps
IDL> c = Float(a) / (b > eps)

It would be slightly more complicated with floats, and I haven't
had my coffee yet.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60432 is a reply to message #60431] Thu, 22 May 2008 04:41 Go to previous messageGo to next message
adam.ranson is currently offline  adam.ranson
Messages: 4
Registered: May 2008
Junior Member
On 22 May, 11:00, Nigel Wade <n...@ion.le.ac.uk> wrote:
> adam.ran...@bris.ac.uk wrote:
>
>> Thanks for the quick response David! This is the way I'd
>> assumed it would be done but doesn't give me the numbers
>> back I'd expect. For example:
>
>> I = [[1, 2, 2],[2,1,1]]
>> C = [[8, 2, 8],[2,8,1]]
>> Z = I/C
>
>> IDL> print, z gives...
>> 0 1 0
>> 1 0 1
>
>> I want to divide 1 by 8, 2 by 2, 2 by 8, 2 by 2, 1 by 8 & 1 by 1.
>
> You have done.
>
> But maybe what you really want to do is divide 1.0 by 8.0, etc...
>
> --
> Nigel Wade

Oh right I see what's happening now! How can I force it to use a
floating point (?) data type then?

Sorry for the dumb questions, the manual/online I got with my copy
seems
to be very unhelpful to me!

Best wishes and thanks for your time

Adam
Re: matrix division [message #60433 is a reply to message #60432] Thu, 22 May 2008 03:07 Go to previous messageGo to next message
d.poreh is currently offline  d.poreh
Messages: 406
Registered: October 2007
Senior Member
On May 22, 12:00 pm, Nigel Wade <n...@ion.le.ac.uk> wrote:
> adam.ran...@bris.ac.uk wrote:
>
>> Thanks for the quick response David!  This is the way I'd
>> assumed it would be done but doesn't give me the numbers
>> back I'd expect.  For example:
>
>>       I = [[1, 2, 2],[2,1,1]]
>>       C = [[8, 2, 8],[2,8,1]]
>>       Z = I/C
>
>> IDL> print, z gives...
>>        0       1       0
>>        1       0       1
>
>> I want to divide 1 by 8, 2 by 2, 2 by 8, 2 by 2, 1 by 8 & 1 by 1.
>
> You have done.
>
> But maybe what you really want to do is divide 1.0 by 8.0, etc...
>
> --
> Nigel Wade

hi
how we can avoid dividing by zero?in matlab we use *eps* what about
IDL?
Cheers
Dave
Re: matrix division [message #60434 is a reply to message #60433] Thu, 22 May 2008 03:00 Go to previous messageGo to next message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
adam.ranson@bris.ac.uk wrote:

>
> Thanks for the quick response David! This is the way I'd
> assumed it would be done but doesn't give me the numbers
> back I'd expect. For example:
>
> I = [[1, 2, 2],[2,1,1]]
> C = [[8, 2, 8],[2,8,1]]
> Z = I/C
>
> IDL> print, z gives...
> 0 1 0
> 1 0 1
>
> I want to divide 1 by 8, 2 by 2, 2 by 8, 2 by 2, 1 by 8 & 1 by 1.

You have done.

But maybe what you really want to do is divide 1.0 by 8.0, etc...

--
Nigel Wade
Re: matrix division [message #60435 is a reply to message #60434] Thu, 22 May 2008 01:07 Go to previous messageGo to next message
adam.ranson is currently offline  adam.ranson
Messages: 4
Registered: May 2008
Junior Member
Thanks for the quick response David! This is the way I'd
assumed it would be done but doesn't give me the numbers
back I'd expect. For example:

I = [[1, 2, 2],[2,1,1]]
C = [[8, 2, 8],[2,8,1]]
Z = I/C

IDL> print, z gives...
0 1 0
1 0 1

I want to divide 1 by 8, 2 by 2, 2 by 8, 2 by 2, 1 by 8 & 1 by 1.

Thanks again

Adam

On 21 May, 19:35, David Fanning <n...@dfanning.com> wrote:
> adam.ran...@bris.ac.uk writes:
>> I have a question about IDL 5.6 which I'm pretty new to... I seem to
>> remember having a similar problem in MatLab a while back too. I'm
>> trying to divide each of the elements in a 2D array by the elements in
>> 2nd 2D array of identical dimensions and put the result into 3rd
>> array. Is it possible to do this in one statement in IDL or do I have
>> to go through each item using a loop?
>
> I would try something like this:
>
> IDL> c = a / b
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60443 is a reply to message #60435] Wed, 21 May 2008 11:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
adam.ranson@bris.ac.uk writes:

> I have a question about IDL 5.6 which I'm pretty new to... I seem to
> remember having a similar problem in MatLab a while back too. I'm
> trying to divide each of the elements in a 2D array by the elements in
> 2nd 2D array of identical dimensions and put the result into 3rd
> array. Is it possible to do this in one statement in IDL or do I have
> to go through each item using a loop?

I would try something like this:

IDL> c = a / b

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: matrix division [message #60569 is a reply to message #60422] Thu, 22 May 2008 07:57 Go to previous message
jameskuyper is currently offline  jameskuyper
Messages: 79
Registered: October 2007
Member
David Fanning wrote:
> James Kuyper writes:
>
>> What if b is < 0?
>
> I was hoping you would tell me, so I didn't have to
> think about it anymore. :-(

For the integer case:

ratio = numerator/denominator
bad = WHERE(denominator eq 0, count)
IF count gt 0 THEN ratio[bad] = replacement_value

replacement_value needs to be carefully chose for the context of your
problem. You might want to give different replacement values depending
upon whether the numerator is positive, negative, or 0. There's
probably a more elegant approach, but three different WHERE's would
certainly be sufficient to cover those cases.

For the floating point case, IDL fills in the relevant elements of
ratio with -Inf, Nan, or Inf, depending upon the sign of the
numerator, and I can't think of any better way of handling it than to
use precisely those value. If you need to use your result for further
computations where those values would be unacceptable, replace them,
with logic similar to the above, but using the FINITE() function.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: plotting graphics for web pages
Next Topic: Re: interact with iimage from the command line?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:43:55 PDT 2025

Total time taken to generate the page: 0.00489 seconds