Lambdify function to matrix

Hi there! Im trying to obtain a 20x20 matrix from the next code

fn = lambdify(t, [V, g, k])
ges = range(1, 2, 20); kes = range(1, 2, 20)
fn.(1, ges, kes)

But I obtain a vector…

20-element Vector{ComplexF64}:

Function “t” is a long expression obtained from solving linear system with SymPy Package.

Any ideas how can I handle this?
Thanks!

I’m not familiar with SymPy, but in this case, I’m guessing that you need to transpose one of your arrays, either ges or kes. Here’s an example with a made-up fn:

fn(x, y, z) = y*z + x 

ges = 1:5
kes = 1:5

fn.(1, ges, kes)

ges and kes are both vectors, so broadcasting will produce a vector:

5-element Vector{Int64}:
  2
  5
 10
 17
 26

However, running

fn.(1, ges, kes')

will produce a matrix:

5×5 Matrix{Int64}:
 2   3   4   5   6
 3   5   7   9  11
 4   7  10  13  16
 5   9  13  17  21
 6  11  16  21  26

and running

fn.(1, ges', kes)

will produce the same matrix transposed.

See the Julia manual here for details: Single- and multi-dimensional Arrays · The Julia Language: Broadcasting

3 Likes

You are absolutely right!
Thanks!