Re: matrix division [message #60421] |
Thu, 22 May 2008 05:59  |
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 #60429 is a reply to message #60428] |
Thu, 22 May 2008 05:13   |
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 #60432 is a reply to message #60431] |
Thu, 22 May 2008 04:41   |
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   |
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   |
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   |
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 #60569 is a reply to message #60422] |
Thu, 22 May 2008 07:57  |
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.
|
|
|