Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,990 Was thanked: 1128 time(s) in 724 post(s)
|
Hi Laurence evaluation of expressions is one of the biggest mysteries of SMath. I have never seen (or better: understood) a consistent description of what the interaction of numeric and symbolic evaluation is meant to work. In your case the assignment to the variable disp delays the evaluation to the point where disp is going to be displayed. Immediate evaluation of KG^{-1}*P works but delayed does not (Why?). You can enforce immediate evaluation upon assignment to disp by using the function eval(): disp:eval(KG^{-1}*P)results in disp=mat(0.183,-0.527,-0.078,-0.41,1*10^{-16},-3.91*10^{-17},-1*10^{-16},-6.09*10^{-17},8,1)(mm unit refused to be displayed in the post preview, therefore I removed it from the result) Equally well you can generate the precision problem by switching to symbolic optimization in the immediate evaluation of KG^{-1}*P. You get something ugly like: KG^{-1}*P=mat(-154029677706911/1227751447183550,371846259893873/1635302861611220,150994944000000/282161279734733,395987199384982/508161646518145,-1949477283233400/115154739031931000000000000000,71907646210181/9860498487058500000000000000,-1453125/2091995697675820000000,185335047104285/8598781694818370000000000000000,8,1)Want to know what the decimal representation of this is? Do not hope for just switching back to numeric optimization. Instead copy the result and evaluate that numerically: mat(-154029677706911/1227751447183550,371846259893873/1635302861611220,150994944000000/282161279734733,395987199384982/508161646518145,-1949477283233400/115154739031931000000000000000,71907646210181/9860498487058500000000000000,-1453125/2091995697675820000000,185335047104285/8598781694818370000000000000000,8,1)=mat(-0.13,0.23,0.54,0.78,-1.69*10^{-14},7.29*10^{-15},-6.95*10^{-16},2.16*10^{-17},8,1)@#This is the garbage result that you had to face when displaying the variable disp. Just to emphasize the problem: numeric evaluation of exactly the same expression results in KG^{-1}*P=mat(0.183,-0.527,-0.078,-0.41,1*10^{-16},-3.91*10^{-17},-1*10^{-16},-6.09*10^{-17},8,1)Seems like a severe bug in the symbolic engine. This makes me recommend to my students not to use symbolic features at all. However, than you would have to embrace every expression with eval() before assignment. This looks really ugly in otherwise nice smath sheets. Still the general rule seems to apply: The more questionable the results are, the more evals you should spread over your sheet. Once I made the proposal to introduce different assignment operators for delayed and immediate evaluation, say :<- and := respectively. Also, symbolic and numeric evaluation (aka "optimization" ) should be visually distinct, say = and -> (as in Mathcad) You may have noted that many examples and bug reports have expressions with comments like "symbolic" just to indicate what could be visible from a consistent notation. However, this seems to be a matter of taste or not easy to implement. It seems to me that the default assignment type is symbolic/delayed. How about switching the default to immediate evaluation? Half the traffic in the forum could be saved. Those who want trouble really hard, could perhaps be given a function symb() ;-) Best regards, Martin Kraska Edited by user 30 September 2012 03:18:57(UTC)
| Reason: Not specified |