How to round of these values to 0 - Robotics Stack Exchange most recent 30 from robotics.stackexchange.com 2020-01-25T22:38:28Z https://robotics.stackexchange.com/feeds/question/14365 https://creativecommons.org/licenses/by-sa/4.0/rdf https://robotics.stackexchange.com/q/14365 0 How to round of these values to 0 Ln_r1 https://robotics.stackexchange.com/users/18222 2017-10-02T17:21:12Z 2017-11-07T11:32:17Z <p>How to shorten these values?</p> <p><a href="https://i.stack.imgur.com/W4ZvF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W4ZvF.png" alt="enter image description here"></a></p> <p>They are the result of a matrix like this. <a href="https://i.stack.imgur.com/rqwMi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rqwMi.png" alt="enter image description here"></a></p> <p>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)</p> <p>In some cases they may go on to be values like 1.574.</p> <p>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?</p> <p>PS.: ST stands for sin(Theta) SA for Sin(Alpha) CA for cos(Alpha) and so on..</p> <p>PPS. : I tried eval function, not working at all.</p> <p>Edit 1: The code I am using is as follows:</p> <pre><code>init_lib; clc; load_robot; 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); </code></pre> <p>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.</p> https://robotics.stackexchange.com/questions/14365/how-to-round-of-these-values-to-0/14366#14366 2 Answer by N. Staub for How to round of these values to 0 N. Staub https://robotics.stackexchange.com/users/18235 2017-10-02T18:14:19Z 2017-11-07T11:32:17Z <p>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.</p> <p>Alternatively on matlab you can use round on a matrix and it's rounding every single entry individually. </p> https://robotics.stackexchange.com/questions/14365/how-to-round-of-these-values-to-0/14367#14367 0 Answer by fibonatic for How to round of these values to 0 fibonatic https://robotics.stackexchange.com/users/1487 2017-10-03T03:34:23Z 2017-10-03T03:34:23Z <p>The best solution that comes to my mind in vpa(). It stands for <a href="https://nl.mathworks.com/help/symbolic/vpa.html" rel="nofollow noreferrer">variable precision arithmetic</a>. 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.</p>