Keno / SIUnits.jl

Efficient unit-checked computation
Other
70 stars 26 forks source link

Dot product with units doesn't work #11

Closed jtveiten closed 10 years ago

jtveiten commented 10 years ago

If you make two vectors, one with unit meter and one with unit Newton, the result should have been Nm

julia> au=[1m 2m 3m] 1x3 Array{SIQuantity{Int64,1,0,0,0,0,0,0},2}: 1 m 2 m 3 m

julia> bu=[2N 3N 4N] 1x3 Array{SIQuantity{Int64,1,1,-2,0,0,0,0},2}: 2 kg m s⁻² 3 kg m s⁻² 4 kg m s⁻²

julia> cu=au*bu' MethodError(conj,(2 kg m s⁻²,))

julia> bu*au' MethodError(conj,(1 m ,))

ivarne commented 10 years ago

This is outside my area of knowledge but it looks like you want the transpose .', instead of the complex conjugate '

julia> cu=au*bu.'
1x1 Array{SIQuantity{Int64,m,kg,s,A,K,mol,cd},2}:
 20 kg m²s⁻²

julia> cu=au.'*bu
3x3 Array{SIQuantity{Int64,m,kg,s,A,K,mol,cd},2}:
 2 kg m²s⁻²  3 kg m²s⁻²   4 kg m²s⁻²
 4 kg m²s⁻²  6 kg m²s⁻²   8 kg m²s⁻²
 6 kg m²s⁻²  9 kg m²s⁻²  12 kg m²s⁻²
jtveiten commented 10 years ago

The dot product multiplies and adds. But here it ends up in a matrix multiplication. Examples: julia> a 1x3 Array{Int64,2}: 1 2 3

julia> b 1x3 Array{Int64,2}: 2 3 4

julia> c=a*b' 1x1 Array{Int64,2}: 20

julia> c1=au*b' 1x1 Array{SIQuantity{Int64,m,kg,s,A,K,mol,cd},2}: 20 m

julia> c1=bu*b' 1x1 Array{SIQuantity{Int64,m,kg,s,A,K,mol,cd},2}: 29 kg m s⁻²

julia> c1=bu*a' 1x1 Array{SIQuantity{Int64,m,kg,s,A,K,mol,cd},2}: 20 kg m s⁻²