How to extract factors of variables in an equation?

10 Ansichten (letzte 30 Tage)
Robert Roos
Robert Roos am 5 Apr. 2019
Beantwortet: Robert Roos am 24 Apr. 2019
I am using the symbolic toolbox to generate a set of three very big equations:
The result should be an equation of motion, so of this form:
Here q, f , τ and N are vectors of three elements and M and C are 3x3.
If I have a variable with the vector 'f', is there a way of find the matrices M and C?
I found the `collect` function, which orders an equation into polynomials with respect to a variable and this can be easily used to manually find those matrices, however, the rest of the equation remains, so it cannot be automated.
Example, say the function is I want to extract the factors 10, 7 and -1 for the three states respectively as seperate variables.
  2 Kommentare
madhan ravi
madhan ravi am 6 Apr. 2019
Have you seen coeffs()?
Robert Roos
Robert Roos am 6 Apr. 2019
I did not. And it seems it's exactly what I was looking for! I'll come back with a working example.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Robert Roos
Robert Roos am 24 Apr. 2019
I ended up accomplishing this using coeffs: (Thanks to madhan ravi)
for i = 1:N
for j = 1:N
% M matrix
cM = coeffs(eom(i), ddq(j), 'All');
if length(cM) > 2
error('Polynomial in mass-matrix count not equal to 2, equation is not linear to mass');
end
if length(cM) == 2
M(i,j) = cM(1);
else
M(i,j) = 0;
end
end
end
I look at the coefficients for each equation with respect to each state and put the result in the matrix.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by