Using equationsToMatrix( ) with symbolic variables representing derivatives

5 vues (au cours des 30 derniers jours)
Matthew Frost
Matthew Frost le 21 Avr 2021
Commenté : Dominik Huber le 17 Oct 2021
Currently trying to put a system of equations into matrix form. There is a function y1 (function of x(t)) that is differentiated twice, and then a function y2 (function of z(t)) differentiated once. With these derivations, the chain rule is being applied, so the derivatives of the x and z variables are becoming present. For this example problem, after being differentiated, they should be put into a matrix as follows:
[A][x_ddot; z_dot] = [b]
where [A] is a 1x2 matrix of coefficients to x_ddot and z_dot, and [b] is the rest of the equation (function of other variables/derivatives of variables). Here is the current code:
syms t x(t) z(t) % define symbolic variables
y1 = x^3 % expression for y1 where x is a function of time
y1dot = diff(y1,t) % differentiation of y1
y1ddot = diff(y1dot,t) % differentiation of y1_ddot
eqn1 = 2*y1ddot == 4 % equation 1
y2 = z^4 % expression for y2 where z is a function of time
y2dot = diff(y2,t) % differentiation of y2
eqn2 = 3*y2dot == 17 % equation 2
eqns = [eqn1; eqn2] % system of equations to put into matrix form
vars = [sym(diff(x,2)); sym(diff(z,1))] % array of variables to sort each equation by in symbolic form
[A,b] = equationsToMatrix(eqns,vars) % equationsToMatrix expression
The expected output should look like this:
[6*x^2, 12z^3]*[x_ddot; z_dot] = [4-12*x*x_dot^2; 17]
I'm currently getting an error saying "Second argument must be a vector of symbolic variables." Is there a way to properly have the equationsToMatrix command use derivatives (like x_ddot and z_dot) to sort the matrices by? The syntax I used of sym(diff(x,2)) seemed to work for the built in isolate function, but not for thie equationsToMatrix.
  1 commentaire
Dominik Huber
Dominik Huber le 17 Oct 2021
Hello,
have the same problem. Were you able to find a solution for this problem?

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by