Substituting values in a symbolic expression, it doesn't throw the expected values

조회 수: 6 (최근 30일)
Hello MATLAB Community,
I've got this symbolic matrix made by the symbolic vector q values :
q = sym('q',[6 1],'real');
% J generation process here. The solution, is present in the .txt file as J (too heavy to just post it)
J = [ ... ]
Until here, everything is alright. However I'm having trouble when I try to substitute values in it, getting wrong answers.
q_des = [0.088026003561672 0.667678035326211 0.121424602485228 0.000000000000068 0.781693688983434 0.088026003561606]';
J1 = [ ... ] % Matrix present in the .txt file as J1
The output is:
J1 =
-0.049283892702272 -0.051798667044203 -0.333398260713620 -0.004025626985947 -0.064748333805210 0
0.558431958260024 -0.004571443147132 -0.029423753180835 0.045614066538309 -0.005714303933907 0
0 -0.490602492044063 -0.267703341011117 0.000000000000002 -0.000000000000002 0
NaN NaN NaN NaN NaN NaN
0.000000595347956 0 0 -0.000000422426208 0.000000000931323 -0.000000595347956
-0.000000000000004 0.000000000000006 0.000000000000006 -0.000000000000005 0.000000000000006 0.000000000000004
NaN NaN NaN NaN NaN NaN
This is weird, because from my knowledge of the physical system this matrix is modelling, these values can't be correct. Trying out with the function subs():
J2 = double(subs(J,q,q_des));
And the result is:
J2 =
-0.049283892702272 -0.051798667044203 -0.333398260713620 -0.004025626985947 -0.064748333805210 0
0.558431958260024 -0.004571443147132 -0.029423753180835 0.045614066538309 -0.005714303933907 0
0 -0.490602492044063 -0.267703341011117 0.000000000000002 -0.000000000000002 0
-0.000000000000012 -0.498064106193923 -0.498064106193923 -0.030966361430369 -0.498064106193925 -0.000000000000012
-0.500000000000000 0.000000000000012 0.000000000000012 0.354860691160197 -0.000000000000012 0.500000000000000
-0.000000000000004 0.000000000000006 0.000000000000006 -0.000000000000005 0.000000000000006 0.000000000000004
0.000000000000005 -0.043956184107000 -0.043956184107000 0.350877434910071 -0.043956184106976 0.000000000000005
Which makes much more sense. The final 4 rows of equations in J seem to be the problematic ones. But why? What is the internal explanation of this anomaly, and more important, how can I get the proper result without using subs(), which is extremely slow? I need it to implement it in a Simulink Function, with plenty of iterations.
Thank you for your time,
  • JOSE
  댓글 수: 5
Jose Antonio Aliaga
Jose Antonio Aliaga 2019년 6월 24일
Hello, thank you for the library. I've tried it, but for numerous iterations in a Simulink model, it's even slower than subs(). I guess I'm just stuck here.
Walter Roberson
Walter Roberson 2019년 6월 24일
You could experiment. Instead of using subs, define q_des as a vector of symbolic numbers by using sym() around the expression. In particular you might want the sym(expression,'d') form.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by