Concerned that matlabFunction( ), when converting from symbolic to numerical, changes the sizes of matrices and vectors,

2 Ansichten (letzte 30 Tage)
Hi there!
I am currently concerned that the function matlabFunction( ), when converting from symbolic to numerical, changes the sizes of matrices and vectors. For instance, I started with a 3x3 symbolic matrix M, gotten from equationsToMatrix( ). Then, I simplified this matrix using simplify( ). And, finally, I used matlabFunction to convert from symbolic to numerical, and to write the numerical matrix to a separate file. Now, when I go to check this separate file that's generated by Matlab, here is the last line, which gives the matrix M, and, it doesn't look 3x3 anymore. Does matlabFunction change the size of symbolic matrices and vectors, when converting from symbolic to numerical? If so, how can I preserve the original sizes of the symbolic matrices and vectors, after the conversion to numerical? Please see M below, generated by Matlab; it looks maybe 2x2 now, but I can't be sure. I don't know the 'reshape' command that Matlab used. But, it kind of looks 2x2, and, perhaps certainly, no longer 3x3. That is weird.
Another example is that my 3x1 vector 'b' no longer looks 3x1; it now looks 2x1, generated by Matlab.
Any help is greatly appreciated; thanks in advance!
mt1 = [(af.*m_perp_added.*(t26.*sin(t45)-1.0))./2.0-m_parallel_added.*t3.*t18.*t48+FD.*t2.*t18.*t47.*t53+FL.*t2.*t18.*t50.*t53;g.*(m_D+m_wing)-(af.*m_perp_added.*(t26.*cos(t45)+1.0))./2.0-V.*g.*rho_f-m_parallel_added.*t4.*t18.*t48+FD.*t2.*t18.*t50.*t53-FL.*t2.*t18.*t47.*t53];
mt2 = [(A.*omega.*rho_f.*w.^3.*abs(omega))./1.28e+2-t2.*t18.*t53.*(-yG+t18.*(m_D.*yG+m_wing.*yG-d_CD.*m_D.*t4)+(t2.*t18.*t56.*w.*(t6+t8+t25+t5.*t15-t6.*t14+t7.*t15-t8.*t14+t9.*t14+t15.*t25))./8.0).*(-t16+t31+FD.*t5+FD.*t7+FD.*t30+FL.*t6+FL.*t8+FL.*t40)-t2.*t18.*t53.*(-xG+t18.*(m_D.*xG+m_wing.*xG-d_CD.*m_D.*t3)+(t2.*t3.*t18.*t56.*w.*(t21+t22+t23+t24+t3.*t25+t4.*t25))./4.0).*(t16+t31-FD.*t6-FD.*t8+FD.*t29+FL.*t5+FL.*t7+FL.*t30)-V.*g.*m_D.*rho_f.*t18.*(xG-d_CD.*t3)];
b = [mt1;mt2];
M = reshape([-t4.*t12.*(m_parallel_added+m_wing+t13+t8.*t11),t22,0.0,t22,-t4.*t12.*(m_perp_added+m_wing-t13+t14),0.0,m_D.*m_perp_added.*t12.*t17,m_D.*m_perp_added.*t9.*t12,-m_D.*(t20+t21)-t12.*(t5.*t20+t5.*t21)-(m_wing.*(h.^2+w.^2))./1.2e+1],[3,3]);

Akzeptierte Antwort

Torsten
Torsten am 26 Nov. 2024
Bearbeitet: Torsten am 26 Nov. 2024
As you can see
M = reshape([...],[3 3])
Thus the expression in [ ] is 1x9, but it is finally reshaped to 3x3.
  13 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 26 Nov. 2024
The expression is creating a 1 x 9 vector and reshape() it to 3 x 3. It may be a bit clumsy compared to directly generating a 3 x 3, but it is workable code.
  3 Kommentare
Noob
Noob am 26 Nov. 2024
Hi Walter,
What about my 3x1 vector 'b' that I just added to this question? It no longer looks 3x1; it looks 2x1 to me. Thanks!
Noob
Noob am 26 Nov. 2024
Ok, got it Torsten! Then my bugs are elsewhere then. I should keep debugging.
Thanks again!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by