Problem with 'disp' function while using 'sym'

11 次查看(过去 30 天)
I wanted to view my answer in square root form instead of decimals so I am using the 'sym' function. But while using 'disp' to show my answers, I'm getting the following error:
Error in sym/disp (line 9)
numbers = regexp(X(1).s, '^_symans_\[\[(\d+)', 'tokens');
while running this code:
clc
clear
th = 60;
c = sym(cosd(th));
s = sym(sind(th));
D = sym([7 5 7]');
T = sym(eye(4));
R = sym([1 0 0; %line number 9
0 c -s;
0 s c]);
T(1:3,1:3) = R;
T(1:3,4) = D;
disp('1T2:');
disp((T));
P = [2 4 6 1]';
disp('P:',T*P);
I believe there's some problem with the last line of my code where I've used 'P:' in the disp function because when I run just 'disp(T*P)', I'm not facing any issues.

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-9-12
编辑:KALYAN ACHARJYA 2019-9-12
You are trying to diplay displaying a description and variable value in the same line using disp, please look at fprintf function. Also see the detail of @Stephen Cobeldick Answer's regarding similar question here
Or easy way in your case:
disp('P:');
disp(T*P);
Result:
P:
9
7 - 3*3^(1/2)
2*3^(1/2) + 10
1

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by