getting symbolic vector when using coeffs function to extract some coeffs
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
Hore you are doing well.
I am using the symbolic toolbox in MATLAB R2021a. I am interested in the coefficient which multiplies a certain variable.
In order to extract that coefficient, i am using the function coeffs which returns a vector containing the coefficients from lower degree to the highest. The returned vector is 1x2. When i want the second term in the vector, it replaces the variiable with 2.
syms M Rot_mat Inertia_principal_spar Ixx_spar Iyy_spar q_su(t) q_sw(t) q_he(t) q_ro(t) q_pi(t) q_d_su(t) q_d_sw(t) q_d_he(t) q_d_ro(t) q_d_pi(t) q_dd_su(t) q_dd_sw(t) q_dd_he(t) q_dd_ro(t) q_dd_pi(t) spar_mass
Rot_mat=[cos(q_pi) sin(q_pi)*sin(q_ro) sin(q_pi)*cos(q_ro);cos(q_pi) cos(q_ro) -sin(q_ro); -sin(q_pi) cos(q_pi)*sin(q_ro) cos(q_pi)*cos(q_ro)];
Inertia_principal_spar=[Ixx_spar 0 0;Iyy_spar 0 0;0 0 0];
Inertia_global_spar=Rot_mat*Inertia_principal_spar*Rot_mat^(-1);
Rot_velocity=[q_d_ro(t);q_d_pi(t);0];
Ec_spar_trans= 0.5*spar_mass*(q_d_su^2 + q_d_sw^2 + q_d_he^2);
Ec_spar_rot= 0.5*Rot_velocity.'*Inertia_global_spar*Rot_velocity;
Ec_spar=Ec_spar_trans+Ec_spar_rot;
Ec_spar_surge=diff(Ec_spar,q_d_su);
Ec_spar_sway=diff(Ec_spar,q_d_sw);
Ec_spar_heave=diff(Ec_spar,q_d_he);
Ec_spar_roll=diff(Ec_spar,q_d_ro);
Ec_spar_pitch=diff(Ec_spar,q_d_pi);
Ec_spar_d_surge=diff(Ec_spar_surge,t);
Ec_spar_d_sway=diff(Ec_spar_sway,t);
Ec_spar_d_heave=diff(Ec_spar_heave,t);
Ec_spar_d_roll=diff(Ec_spar_roll,t);
Ec_spar_d_pitch=diff(Ec_spar_pitch,t);
%%% substitution of the variables
Ec_spar_d_surge=subs(Ec_spar_d_surge,[diff(q_su,t),diff(q_sw,t),diff(q_he,t),diff(q_ro,t),diff(q_pi,t),diff(q_d_su,t),diff(q_d_sw,t),diff(q_d_he,t),diff(q_d_ro,t),diff(q_d_pi,t)],[q_d_su,q_d_sw,q_d_he,q_d_ro,q_d_pi,q_dd_su,q_dd_sw,q_dd_he,q_dd_ro,q_dd_pi]);
Ec_spar_d_sway=subs(Ec_spar_d_sway,[diff(q_su,t),diff(q_sw,t),diff(q_he,t),diff(q_ro,t),diff(q_pi,t),diff(q_d_su,t),diff(q_d_sw,t),diff(q_d_he,t),diff(q_d_ro,t),diff(q_d_pi,t)],[q_d_su,q_d_sw,q_d_he,q_d_ro,q_d_pi,q_dd_su,q_dd_sw,q_dd_he,q_dd_ro,q_dd_pi]);
Ec_spar_d_heave=subs(Ec_spar_d_heave,[diff(q_su,t),diff(q_sw,t),diff(q_he,t),diff(q_ro,t),diff(q_pi,t),diff(q_d_su,t),diff(q_d_sw,t),diff(q_d_he,t),diff(q_d_ro,t),diff(q_d_pi,t)],[q_d_su,q_d_sw,q_d_he,q_d_ro,q_d_pi,q_dd_su,q_dd_sw,q_dd_he,q_dd_ro,q_dd_pi]);
Ec_spar_d_roll=subs(Ec_spar_d_roll,[diff(q_su,t),diff(q_sw,t),diff(q_he,t),diff(q_ro,t),diff(q_pi,t),diff(q_d_su,t),diff(q_d_sw,t),diff(q_d_he,t),diff(q_d_ro,t),diff(q_d_pi,t)],[q_d_su,q_d_sw,q_d_he,q_d_ro,q_d_pi,q_dd_su,q_dd_sw,q_dd_he,q_dd_ro,q_dd_pi]);
Ec_spar_d_pitch=subs(Ec_spar_d_pitch,[diff(q_su,t),diff(q_sw,t),diff(q_he,t),diff(q_ro,t),diff(q_pi,t),diff(q_d_su,t),diff(q_d_sw,t),diff(q_d_he,t),diff(q_d_ro,t),diff(q_d_pi,t)],[q_d_su,q_d_sw,q_d_he,q_d_ro,q_d_pi,q_dd_su,q_dd_sw,q_dd_he,q_dd_ro,q_dd_pi]);
%%% mass matrix
M(1,1)=coeffs(Ec_spar_d_surge,q_dd_su);
M(1,2)=coeffs(Ec_spar_d_surge,q_dd_sw);
M(1,3)=coeffs(Ec_spar_d_surge,q_dd_he);
M(1,4)=coeffs(Ec_spar_d_surge,q_dd_ro);
M(1,5)=coeffs(Ec_spar_d_surge,q_dd_pi);
M(2,1)=coeffs(Ec_spar_d_sway,q_dd_su);
M(2,2)=coeffs(Ec_spar_d_sway,q_dd_sw);
M(2,3)=coeffs(Ec_spar_d_sway,q_dd_he);
M(2,4)=coeffs(Ec_spar_d_sway,q_dd_ro);
M(2,5)=coeffs(Ec_spar_d_sway,q_dd_pi);
M(3,1)=coeffs(Ec_spar_d_heave,q_dd_su);
M(3,2)=coeffs(Ec_spar_d_heave,q_dd_sw);
M(3,3)=coeffs(Ec_spar_d_heave,q_dd_he);
M(3,4)=coeffs(Ec_spar_d_heave,q_dd_ro);
M(3,5)=coeffs(Ec_spar_d_heave,q_dd_pi);
M(4,1)=coeffs(Ec_spar_d_roll,q_dd_su);
M(4,2)=coeffs(Ec_spar_d_roll,q_dd_sw);
M(4,3)=coeffs(Ec_spar_d_roll,q_dd_he);
% c_roll=zeros(1,2);
c_roll
% M(4,4)=c_roll(2);
M(4,5)=coeffs(Ec_spar_d_roll,q_dd_pi);
M(5,1)=coeffs(Ec_spar_d_pitch,q_dd_su);
M(5,2)=coeffs(Ec_spar_d_pitch,q_dd_sw);
M(5,3)=coeffs(Ec_spar_d_pitch,q_dd_he);
M(5,4)=coeffs(Ec_spar_d_pitch,q_dd_ro);
M(5,5)=coeffs(Ec_spar_d_pitch,q_dd_pi);
Could anyone help please ?
Best Regards,
2 个评论
John D'Errico
2023-5-6
Posting a picture of text is silly, in that it makes it impossible to just copy the text, and show you how to fix it. And since you can paste in text directly...
Is there a good reason why you want to make it more difficult to get help for your problem?
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!