converting equation into multiple of two matrix

hi there,
hope you are doing good
guys i want to convert some equations into the multiple of two matrices automatically. for example
it will be appreciated if u will help me.
thanks in advance .

 Accepted Answer

4 Comments

thanks bro but i need something which can be used with a1 b1 c1 a2 b2 c2 kind of multiplier .
If you can extract
A = [a1 b1 c1 ; a2 b2 c2]
and
b = [ 0 ; 0]
from your equations
a1*x + b1*y + c1*z = 0
a2*x + b2*y + c2*z = 0
using EquationsToMatrix, isn't that exactly what you want ?
thanks bro tomorrow i am trying with
[A,b] = equationsToMatrix(eqns)
and getting error as
Error using mupadengine/feval_internal
Unable to convert to matrix form because the system does not seem to be linear.
Error in sym/equationsToMatrix (line 61)
T = eng.feval_internal('symobj::equationsToMatrix',eqns,vars);
Error in P_rough (line 11)
[A,b] = equationsToMatrix(eqns)
but after using
vars = [x y z]
[A,b] = equationsToMatrix(eqns,vars)
i am getting correct
thanks for your time
Of your equations are nonlinear in x,y and z, equationsToMatrix will not work.
Your equations in the graphics you included were linear in x,y and z.

Sign in to comment.

More Answers (1)

HI BRO CAN YOU PLEASE HELP ME WITH THIS IT IS SHOWING SOME ERROR
syms m J x xd TE TEd xb xbd TEb TEbd a b t K1 K2 C1 C2
KE = m*xd^2/2 + J*TEd^2/2;
PE = K1*((x-a*sin(TE))-(xb-a*sin(TEb)))^2/2 + K2*((x+b*sin(TE))-(xb+b*sin(TEb)))^2/2;
R = C1*((xd-a*cos(TE)*TEd)-(xbd-a*cos(TEb)*TEbd))^2/2 + C2*((xd+b*cos(TE)*TEd)-(xbd+b*cos(TEb)*TEbd))^2/2;
L = KE-PE;
%% LagrangeDynamicEqDeriver
q = [x, TE]; Dq = [xd, TEd]; % variables : x and theta
Eq = S_LagrangeDynamicEqDeriver(L, R, q, Dq) == 0
L_q = 
R_Dq = 
L_Dq_dt = 
Eq = 
vars = [xd TEd x TE]
vars = 
[A,b] = equationsToMatrix(Eq,vars)
Error using mupadengine/feval_internal
Unable to convert to matrix form because the system does not seem to be linear.

Error in sym/equationsToMatrix (line 61)
T = eng.feval_internal('symobj::equationsToMatrix',eqns,vars);
Supporting file is
function Eq = S_LagrangeDynamicEqDeriver(L, R, q, Dq)
%%
syms t
N = length(q);
%% Calculation of L_q = r.L/r.q and L_Dq = r.L/r.Dq
L_q = sym(zeros(N,1));
L_Dq = sym(zeros(N,1));
for ii = 1:N
L_q(ii) = diff(L, q(ii)) ; % diff. of L wrt. q one by one
L_Dq(ii) = diff(L, Dq(ii)) ; % diff. of gen. coordinate wrt. q dot one by one
end
L_q
L_Dq;
%% Calculation of R_q = r.L/r.q and R_Dq = r.L/r.Dq
R_Dq = sym(zeros(N,1));
for ii = 1:N
R_Dq(ii) = diff(R, Dq(ii));
end
R_Dq
%% Calculation of L_Dq_dt = qd/dt( r_Dq )
L_Dq_dt = sym(zeros(N,1));
for ii = 1:N
for jj = 1:N
q_dst = [char(q(jj)), '(t)'];
Dq_dst = ['diff(', q_dst,',t)'];
L_Dq(ii) = subs(L_Dq(ii), {q(jj), Dq(jj)}, {str2sym(q_dst), str2sym(Dq_dst)});
end
L_Dq;
L_Dq_fcn = symfun(L_Dq(ii), t);
L_Dq_dt(ii) = diff(L_Dq_fcn, t);
end
L_Dq_dt
%% Lagrange's equations (Second kind)
Eq = sym(zeros(N,1));
for ii = 1:N
Eq(ii) = simplify(L_Dq_dt(ii) + R_Dq(ii) - L_q(ii)) ;
end
end

1 Comment

Your equations are two second-order differential equations.
EquationsToMatrix can't help to solve it.
Specify 4 boundary conditions and try "dsolve".
If "dsolve" fails (which is probable for such a complicated system), use ode45 or another of the numerical integrators.

Sign in to comment.

Asked:

on 5 Jan 2023

Commented:

on 6 Jan 2023

Community Treasure Hunt

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

Start Hunting!