Removing round off error in polynomial symbolic toolbox

I am trying to remove the round-off error in polynomials in a matrix and using symbolic toolbox. I am getting values e-17 or higher.
This is currently what I am using to simplify and get down to 4 digits.
J=simplify(J);
J=vpa(J,4);
This is one of the cells in the matrix:
6.123e-17*d2 - 1.0*d3*(6.123e-17*cos(q1) - 6.123e-17*cos(q1)*cos(q2) + sin(q1)*sin(q2)) - 1.0*d2*cos(q1) + d3*(1.0*cos(q2) + 3.749e-33)
This is the result I want:
1.0*d3*(sin(q1)*sin(q2)) - 1.0*d2*cos(q1) + d3*(1.0*cos(q2))
I've tried using round(J) and the function doesn't seem to be able to round the coeffs of polynomials and get the following for that matrix cell:
round(0.000000000000000061232339957279221655641939602547*d2 - 1.0*d3*(0.000000000000000061232339957279221655641939602547*cos(q1) - 0.000000000000000061232339957279221655641939602547*cos(q1)*cos(q2) + sin(q1)*sin(q2)) - 1.0*d2*cos(q1) + d3*(1.0*cos(q2) + 3.7493994566438135525323252303531e-33))

Answers (1)

You appear to be creating a rotation matrix of some kind. In that matrix, you cannot justify that
0.000000000000000061232339957279221655641939602547 * d2
is going to approximate to 0: for points far enough away from the center of rotation, 0.000000000000000061232339957279221655641939602547 * d2 can be arbitrarily large.
Therefor what you need to do is use better equations.
Do not use even one numeric coefficient: use only rational symbolic coefficients and named irrational numbers, such as sym('178/1000')*sym('pi') instead of sym(0.178 * pi) or sym('0.178*pi').

Asked:

on 5 Oct 2017

Answered:

on 5 Oct 2017

Community Treasure Hunt

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

Start Hunting!