1

I'm making some matrix computation in matlab. What looks strange (to me) is that I get results like

(8700286382685973*cos(q5)*sin(q4))/9007199254740992 + sin(q5)*((43220913799951902644522757965203*cos(q4))/730750818665451459101842416358141509827966271488 - 291404338770025/1125899906842624)

but matlab does not simplify the result. I already tried to use functions like simplify, simple,fix but none of them gave the desired result.

Any suggestion on what function should I use?

Manlio
  • 10,768
  • 9
  • 50
  • 79
  • How do you know that it could be simpler? Besides "I think so"? – duffymo Oct 06 '12 at 15:30
  • Because `43220913799951902644522757965203/730750818665451459101842416358141509827966271488` is almost 0. – Manlio Oct 06 '12 at 15:33
  • OK, so you're left with the first term. Those constants look suspicious to me, too. How did you arrive at this result? What's the back story? – duffymo Oct 06 '12 at 15:36
  • I followed the Denavit-Hartember convention to compute the direct kinematic of a manipulator. However I don't think this is relevant...Even putting those value by hand I expected matlab to simplify the result. – Manlio Oct 06 '12 at 15:47
  • But ALMOST zero is not truly zero, any more than almost pregnant is actually pregnant. This is a symbolic solution. If you wish a numerical answer, then vpa can help a bit. –  Oct 06 '12 at 18:53

3 Answers3

2

Simplify does only "exact" manipulations. What you need is a command that kills small terms in your expression. In Mathematica "Chop" takes care of that. Try to google it.

Lucas
  • 918
  • 1
  • 9
  • 18
1

As @Lucas suggested, you can use vpa and digits in matlab, for example if the expression above is A (sym) then:

 vpa(A,3) % digits is set to 3

 ans = 

  0.966*cos(q5)*sin(q4) + sin(q5)*(5.91e-17*cos(q4) - 0.259)

And then you can either see the numbers for themselves and chop them, or use something like:

 function result = significant(x, n)
 % significant(x, n) rounds number x to n number of significant figures

 s = floor(log10(abs(x)));
 shift = 10^(n-1);
 mant = round(x*shift/(10^s)) / shift;
 result = mant * 10^s; 
bla
  • 25,846
  • 10
  • 70
  • 101
0

Try doing one of these commands before your evaluation:

format longe
format shorte
netskink
  • 4,033
  • 2
  • 34
  • 46