# How to round of these values to 0

How to shorten these values?

They are the result of a matrix like this.

When I individually run sin(theta1) and such functions, it would give me the correct value as a zero or a one (the angles I am working with are 0 or 90 degrees)

In some cases they may go on to be values like 1.574.

I know there is a round off function in MATLAB, but then I would have to add that function to every element individually. Is there any easier way to achieve this?

PS.: ST stands for sin(Theta) SA for Sin(Alpha) CA for cos(Alpha) and so on..

PPS. : I tried eval function, not working at all.

Edit 1: The code I am using is as follows:

init_lib;
clc;

syms q1 q2 q3 q4 q5;

%DH Parameters for the robot:
robot.DH.theta= '[pi/2 pi/2 0 q(4) q(5)]';
robot.DH.d='[q(1) q(2) q(3) 0.1 0.020]';
robot.DH.a='[0 0 0 0 0]';
robot.DH.alpha= '[pi/2 pi/2 0 pi/2 0]';

% We input the joint parameters:
q = [q1 q2 q3 q4 q5];

%Storing the evaulated values of 'q'
Theta=eval(robot.DH.theta);
d=eval(robot.DH.d);
a=eval(robot.DH.a);
alpha=eval(robot.DH.alpha);

A01=dh(Theta(1), d(1), a(1), alpha(1));
A12=dh(Theta(2), d(2), a(2), alpha(2));
A23=dh(Theta(3), d(3), a(3), alpha(3));
A34=dh(Theta(4), d(4), a(4), alpha(4));
A45=dh(Theta(5), d(5), a(5), alpha(5));
A05 = A01*A12*A23*A34*A45;
disp(A05);


Where, dh is a function that comes from a predefined library. It basically substitutes the four values into a generalized form of the matrix I posted as the second image.

As you are using the symbolic toolbox, you should declare your angles as symbolic so that the cosine of ${\pi/2}$ is zero instead of numerically estimated to something close to zero. Also so you can convert your expression to a function via the matlabFunction() native function from matlab.

Alternatively on matlab you can use round on a matrix and it's rounding every single entry individually.

• Hey Staub thank you for your suggestion, I got the answer when I by passed all the eval functions and everything and I directly substituted theta = [pi/2 pi/2 0 q4 q5] as you had suggested. – Ln_r1 Nov 25 '17 at 18:12
• however I don't understand why it calculates numerically when I do it the way I have written at present, since q(1), q (2)...q(5) points to symbolic values q1 q2 .. q5 respectively. Am I missing some key concept here? – Ln_r1 Nov 25 '17 at 18:16
• Basically, the issue was in your cos/sin of 0 ad $\pi/2$ if you don't give them as symbolic somehow matlab starts to do a numerical approximation as it does for any number. Hence despite having your parameters q1,... symbolic matlab was puzzled by the rest of your expression – N. Staub Nov 27 '17 at 7:36

The best solution that comes to my mind in vpa(). It stands for variable precision arithmetic. If you have a symbolic expression X (I believe a matrix with symbolic entries should work as well), then vpa(X,d) will return all the constants within X as a number with at most d significant digits.

• Hi Thank you for your suggestion, however I am getting 6.123e-16 in place of the huge fraction. So this still has not solved my problem. – Ln_r1 Oct 4 '17 at 11:55
• @Ln_R How did you insert the values for q4 and q5 into the expression. You might done something there such that MATLAB is converting it to a double after which further calculations can have errors of that magnitude. – fibonatic Oct 4 '17 at 16:39
• q4 and q5 were put in as symbolic terms (using syms). I'm sorry I wasn't clear but q4 and q5 are not supposed to be substituted with values. I have edited my question with the entire code to give you a better idea. – Ln_r1 Oct 6 '17 at 14:05