I have the following code, and it is not working, because c2 is a 1*1 adjoint float type array. If I define b2=ones(3), then the code will work. The question is that how to manually change the type of c2 ?(In my application, b2 is extracted from a matrix and couldn’t be defined).
using LinearAlgebra
a=[1.0,2,3]
b2=ones(3,1)
c2=a'*b2
det(c2)
It is from a Jacobian matrix, and the dimension of the matrix could be 1x1, 2x2, or 3x3. I would like to keep the same form for all dimensions. The output I need is a number, rather than a 1x1 array.
One the other hand, a zeros(3) vector is different to a zeros(3,1) vector in terms of array type. This could lead to some problems in subsequent code development.
I think the problem is the inconsistency of your use of vector vs 1 column matrix. a is a vector while b2 is a 1 column matrix. The multiplication of a row vector and a matrix can be either viewed as another row vector or as a matrix. In Julia, the “row vector”, i.e. Adjoint{Float64, Vector{Float64}} is chosen. The det of a “vector” doesn’t make sense, so if you want the result to be a matrix instead, just make a a matrix as well. On the other hand, if you define both as vectors, the result will be a scalar for which det is also defined. So really, just be consistent and it will just work.
This would lead to the problem I posted originally, which is the return of a two dimensional array, rather than a number.
I think the real issue is that the slice operation b=a[1:3,:] doesn’t work for vectors, because the output has become a two dimensional array. This could potentially lead to some problems in different applications.
Well, normally we wouldn’t use b=a[1:3,:] for vectors either.
You are saying you want your code to work in multiple dimensions but then you do something completely different when you are in 1 dimension. Those two things seems at odds to me.
The problem I showed is that for one dimensional problems, you would normally only define vectors. You wouldn’t define matrices for a one dimensional problem.
If you define a matrix for a one dimensional problem, then it works. However, my point is that people normally only define a vector for a one dimensional problem, and then you could get matrices out from slicing a vector.
In my original example, a is a vector defined for a one dimensional problem. This would be a natural thing, and b2 is sliced from a vector, which would also be normal. It is not working in Julia.
Of course, after the original example, you know that vectors could lead to problems, and now you define matrices for even one dimensional problems, which is ok for me. But I think people don’t know this could still have problems.