MATLAB Answers

0

Problem with 'disp' function while using 'sym'

Asked by iamShreyans on 12 Sep 2019
Latest activity Commented on by iamShreyans on 13 Sep 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by KALYAN ACHARJYA on 12 Sep 2019
Edited by KALYAN ACHARJYA on 12 Sep 2019
 Accepted Answer

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

  1 Comment

Thanks a lot for the help!

Sign in to comment.