matlabexponentsym

Identify powers in an algebraic expression for a Buckingham Pi calculation in MatLab


This is a continuation of an earlier question I asked here.

If I create a symbolic expression in MatLab

syms L M T
F = M*L/T^2

I want to identify the powers of each dimension M, L, or T. In this case, the answer should be

There is a relatively easy way to do this if the expression F were a polynomial in MatLab employing the coeffs function. However, my expression is clearly not a polynomial as far as MatLab is concerned.

In the end, I will be working with at least two parameters so I will put them in a cell array since I anticipate cellfun will be useful.

V = L/T
param = {F,V};

The final output should be a table where the rows correspond to each dimension, L M and T and the columns are for each parameter F and V.


Solution

  • syms L M T
    F = M*L/T^2
    
    [C,T] = coeffs(expand(log(F),'IgnoreAnalyticConstraints',true))
    [exp(T).' C.']
    

    It returns the table: enter image description here