Is it possible to generate an error when it is tried to multiply matrix with different dimensions? [message #85386] |
Tue, 30 July 2013 03:15  |
Victor[2]
Messages: 5 Registered: July 2013
|
Junior Member |
|
|
Hi everyone!
I want to know if it is possible to generate an error (or warnning) in IDL (using for instance de COMPILE_OPT or something like that) when it is tried to multiply matrix with different dimensions.
for instance..
a = [1,2,3]
b = [1,2]
The dimensions are different and if I do print,a*b the result is [1,4] but in fact I want to know that the matrix are different.
It is a common error when I use a lot of matrix and could be good to know when this it happens (at least some warning...)
thanks!!
kind regards,
Víctor
|
|
|
|
|
Re: Is it possible to generate an error when it is tried to multiply matrix with different dimensions? [message #85413 is a reply to message #85402] |
Thu, 01 August 2013 00:04  |
Victor[2]
Messages: 5 Registered: July 2013
|
Junior Member |
|
|
Sorry, I wrote the question bad, as you said I would want to control a multiplication of each element of the matrix (not a "classical" mathematical matrix multiplication)
And Yes, I knew that I can control the situation but I wanted to know if it is possible to work in the same way like Matlab ...
Thanks
On Tuesday, July 30, 2013 8:08:55 PM UTC+2, Phillip Bitzer wrote:
> You could always check before multiplying:
>
>
>
> IF N_ELEMENTS(a) EQ N_ELEMENTS(b) THEN c= a*b ELSE MESSAGE, "different number of elements"
>
>
>
> and let your error handler "catch" the error.
>
>
>
> An FYI - this isn't *really* matrix multiplication. What you're doing is multiplying each element of the arrays together. If you're interested in matrix multiplication, check out:
>
>
>
> http://www.exelisvis.com/docs/Matrix_Operators.html
|
|
|