converting equation into multiple of two matrix

1 次查看(过去 30 天)
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 .

采纳的回答

Torsten
Torsten 2023-1-5
  4 个评论
Rahul Jangid
Rahul Jangid 2023-1-6
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
Torsten
Torsten 2023-1-6
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.

请先登录,再进行评论。

更多回答(1 个)

Rahul Jangid
Rahul Jangid 2023-1-6
编辑:Torsten 2023-1-6
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 个评论
Torsten
Torsten 2023-1-6
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by