[Scilab-users] Building a f(P, T) matrix from P and T line vectors

Antoine Monmayrant antoine.monmayrant at laas.fr
Thu Dec 19 14:19:47 CET 2013


Le 19/12/13 08:59, Dang, Christophe a écrit :
> Dear all,
>
> I often have to work with 2-variable functions,
> e.g. from equations of state involving pressure and temperature.
>
> I have a range of P and T and build line vectors,
> with linspace() or v1:p:v2.
>
> The Kronecker product allows an easy build of P*T
>
> P'.*.T
> ->
> [P(1)*T(1) P(1)*T(2)
> P(2)*T(1) P(2)*T(2)]
>
> Now, I'd like to have the same thing with the sum,
> without using a loop
> (of course it's not the sum only,
> there are adequate coefficients
> and it's possibly enclosed in a exp() function or so).
>
> A colleague of mine suggested the following way
> which works well:
>
> sP = size(P, "c");
> sT = size(T, "c");
>
> P_matrix = P'*ones(1, sT);
> T_matrix = T*ones(sP, 1);
>
> P_matrix + T_matrix
> ->
> [P(1)+T(1) P(1)+T(2)
> P(2)+T(1) P(2)+T(2)]
>
> Now my question:
>
> is there a more convenient way to do this,
Hi Christophe,

I use this approach all the time and I haven't found a better way.
> and especially,
> if I want to generate a f(P, T) matrix,
> do I have to build P_matrix and T_matrix and perform
>
> f(P_matrix, T_matrix)
>
> or is there a way to get it directly from the P and T vectors?
Well, again, I do the same and be glad to hear about a better way.
I think this approaches might not be optimal in term of memory usage...

Cheers,

Antoine
>




More information about the users mailing list