- Clear the MATLAB workspace using ‘clear” to avoid any variable conflict.
- Upgrade MATLAB version.
How to change matlab symbolic format output to be in a normal array form?
7 次查看(过去 30 天)
显示 更早的评论
I'm having a problem with my symbolic matlab outputs. Normally, using symbolic variables would produce results that were copy-pastable into other scripts, i.e. results were in normal array form consistent with numerical arrays. However, my symbolic results are producing the attached results. Additionally, the vn term is used opposed to the norm() command as it was producing Unable to resolve name sym.convertString. This also mean all other functions tan(),atan2(), etc. are not functioning. I can't find any documentation on why this is occuring. Thank you.
>> syms rx ry rz rdx rdy rdz a0 a1 a2 g real
X = [rx ry rz rdx rdy rdz a0 a1 a2]';
r = [rx ry rz]';
v = [rdx rdy rdz]'
vn = sqrt(sum(v.^2));
B = vn^2*a0+vn*a1+a2;;
F = [v; [0 0 -g]'-.5*B*vn*v;0;0;0];
jacobian(F,X)
v =
[rdx]
[ ]
[rdy]
[ ]
[rdz]
ans =
[0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0]
[0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0]
[0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0]
[ 2
[ %2 rdx 1/2 1/2
[0 , 0 , 0 , - ------- - %1 %3 rdx - %1 %2 ,
[ 1/2
[ %1
%2 rdx rdy 1/2 %2 rdx rdz 1/2
- ---------- - %1 %4 rdx , - ---------- - %1 %5 rdx ,
1/2 1/2
%1 %1
1/2
-%1 %6 rdx , -0.500000000000000000 %1 rdx ,
]
1/2 ]
-0.500000000000000000 %1 rdx]
]
]
[
[ %2 rdx rdy 1/2
[0 , 0 , 0 , - ---------- - %1 %3 rdy ,
[ 1/2
[ %1
2
%2 rdy 1/2 1/2 %2 rdy rdz 1/2
- ------- - %1 %4 rdy - %1 %2 , - ---------- - %1 %5 rdy ,
1/2 1/2
%1 %1
1/2
-%1 %6 rdy , -0.500000000000000000 %1 rdy ,
]
1/2 ]
-0.500000000000000000 %1 rdy]
]
]
[
[ %2 rdx rdz 1/2 %2 rdy rdz 1/2
[0 , 0 , 0 , - ---------- - %1 %3 rdz , - ---------- - %1 %4 rdz
[ 1/2 1/2
[ %1 %1
2
%2 rdz 1/2 1/2 1/2
, - ------- - %1 %5 rdz - %1 %2 , -%1 %6 rdz ,
1/2
%1
]
1/2 ]
-0.500000000000000000 %1 rdz , -0.500000000000000000 %1 rdz]
]
]
[0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0]
[0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0]
[0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0]
2 2 2
%1 := rdx + rdy + rdz
1/2
%2 := 0.500000000000000000 a0 %1 + 0.500000000000000000 a1 %1
+ 0.500000000000000000 a2
a1 rdx
%3 := 1.000000000 a0 rdx + 0.500000000000000000 ------
1/2
%1
a1 rdy
%4 := 1.000000000 a0 rdy + 0.500000000000000000 ------
1/2
%1
a1 rdz
%5 := 1.000000000 a0 rdz + 0.500000000000000000 ------
1/2
%1
2 2
%6 := 0.500000000000000000 rdx + 0.500000000000000000 rdy
2
+ 0.500000000000000000 rdz
0 个评论
回答(1 个)
Arun
2024-2-22
Hi Liam,
I see that the results output given by you is not the expected result and you also get error for “norm(v)”.
I executed the same code in MATLAB R2023b and get the expected results also there is no error using “norm” function over “v”.
Here is the code integrated with “norm” function:
syms rx ry rz rdx rdy rdz a0 a1 a2 g real
X = [rx ry rz rdx rdy rdz a0 a1 a2]';
r = [rx ry rz]';
v = [rdx rdy rdz]'
%vn = sqrt(sum(v.^2));
vn = norm(v)
B = vn^2*a0+vn*a1+a2;;
F = [v; [0 0 -g]'-.5*B*vn*v;0;0;0];
jacobian(F,X)
The output provides the expected behaviour for symbolic variables and the “norm” function.
You can try few things, which might help you with the issue:
Please refer the shared MATLAB documentation link for more information related to “norm” function: https://www.mathworks.com/help/matlab/ref/norm.html
I hope this helps you to get the expected output.
HTH
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!