matlab different results same algorithm
显示 更早的评论
Hi everybody, on university pc I execute the same algorithm on matlab 2012b and matlab 2016a, why on matlab 2012b I get the right result on matlab2016a I get the wrong one? 2016a:

2012b:

I simply have two files : MAIN_InitScript.m contains this :
JOINT = [1 2 0 pi/2 0 0]; %(m , m, rad, rad, m, rad)
[p,phi,R,A] = cindir(JOINT,'XYZ')
cindir.m contains this :
function [p,phi,R,A] = cindir(q, euleroAngle)
syms ai alphai di tethai
Ai= [ cos(tethai) -sin(tethai)*cos(alphai) sin(tethai)*sin(alphai) ai*cos(tethai)
sin(tethai) cos(tethai)*cos(alphai) -cos(tethai)*sin(alphai) ai*sin(tethai)
0 sin(alphai) cos(alphai) di
0 0 0 1];
DH= [ 0 pi/2 q(1) pi/2
0.35 pi/2 q(2) pi/2
0.467 0 0.8735 q(3)
0.4005 pi 0 q(4)
0 0 q(5) 0
0 0 0 q(6) ];
Ab0=subs(Ai,[ai alphai di tethai],[0 pi/2 0 pi/2]);
Ane=subs(Ai,[ai alphai di tethai],[0 0 0.1334 pi]);
A01=subs(Ai,[ai alphai di tethai],DH(1,:));
A12=subs(Ai,[ai alphai di tethai],DH(2,:));
A23=subs(Ai,[ai alphai di tethai],DH(3,:));
A34=subs(Ai,[ai alphai di tethai],DH(4,:));
A45=subs(Ai,[ai alphai di tethai],DH(5,:));
A56=subs(Ai,[ai alphai di tethai],DH(6,:));
A=struct('Ab0',Ab0,'A01',A01,'A12',A12,'A23',A23,'A34',A34,'A45',A45,'A56',A56,'Ane',Ane);
Abe= double(Ab0*A01*A12*A23*A34*A45*A56*Ane);
R= double(Abe(1:3,1:3));
p= double(Abe(1:3,4));
[phi theta psi]=dcm2angle(R,euleroAngle);
phi=[phi;theta;psi];
end
Matlab 2012b produces the right precision for the output that I need, matlab 2016a doesn't do that. In my friend pc with matlab 2016a produces the right output, in another friend with mac and matlab 2015b same algorithm produces same output as 2012b that's why I'm getting crazy to figure out why.
6 个评论
Adam
2016-12-8
What are we looking at? The resolution of that image makes it difficult to see it all, but apart from 2012b having trailing 0s I don't see an immediate difference in what you are showing. Depending on the context -pi and pi are the same thing so flipping from one to the other can be just the result of very minor computational errors that are irrelevant, just like getting 1e-16 instead of 0.
Francesco Falanga
2016-12-8
编辑:Francesco Falanga
2016-12-8
Adam
2016-12-8
What kind of greater accuracy are you talking about for R? What we see there is just trailing 0s. Is there actually a significant in one of the decimal places after that?
Different machines may well have slightly different ways of doing floating point math calculations. Such low-level stuff is not my expertise though, I just accept it as a fact!
per isakson
2016-12-8
The absence of trailing 0s for R of R2016a indicates floating point integers, meaning exactly -1 and 0, respectively.
Francesco Falanga
2016-12-8
编辑:Francesco Falanga
2016-12-8
per isakson
2016-12-8
编辑:per isakson
2016-12-8
- "what do you mean for trailing 0s?"   I used the expression because Adam used it in the first comment and you seemed to understand it.
- I tried to make you aware that -1 indicates higher precision than does -1.0000 and that's because the former is an integer. Furthermore, -1 is the exact result in this case. Thus, R2016a is more accurate than R2012b (in this particular case).
回答(2 个)
John D'Errico
2016-12-8
编辑:John D'Errico
2016-12-8
1 个投票
Congratulations! You win the prize for being the 314159'th person to have done this! Sadly, first prize is a free trip to Newark, New Jersey. Second prize is a free trip to anywhere else. :) (I grew up living not far from Newark, so I can say that.)
Seriously, this is something frequently reported. And as frequently, the resolution is you did not actually solve the same problem in both instances. You may think that you did, but usually, not so. What usually happens is the person copied the numbers in some array using ascii text versions of those numbers. But in fact, they did not transmit the exact numbers as stored internally. That is best done using a .mat file.
Another common error that people make is not having the same IDENTICAL version of their code on both machines. Yes, they think they do, but often not the case. And sometimes people have functions out there they don't even know they have. For example, sometimes students write a function, calling it some name that overloads an existing toolbox code. Or perhaps you have modified some fundamental MATLAB tool and not realized that you did so. (Yes, this happens.)
There are other reasons this happens. For example, does your code rely on randomness in some way? You may not realize it, but some algorithms use a random start point.
Can we know what you did wrong? (Really, almost always, that is the case.) That is completely impossible so far, since you have not provided a hint as to what you did! Where do these matrices come from? What code produced them? What inputs does that code have? You see, unless we can view your code, and even better, test it on the same EXACT problem you have, we cannot know what you did.
So if you truly want help in resolving this question, attach your code to your question, or to a comment. Attach any necessary arrays as a .mat file, so that we can verify exactly what you did. If you don't do so, then we can only throw out idle speculation as to what you did wrong.
(Free trip fine print: The trip is free, but the winner must pay for any travel, lodging, meals, tolls, etc. The first prize winner is also not allowed to substitute second prize for first prize.)
Jan
2016-12-8
Do I understand correctly, that you are talking about the number of digits displayed in the command window? Then the command format will help you:
R = [-1, 0, rand]
format short
R
format longg
R
format longeng
R
2 个评论
Francesco Falanga
2016-12-8
@frank: I still do not get an idea of what you are talking of. Do you mean the "accuracy" or a calculation or is really the "precision" the problem. Note: The precision of a variable is "single" or "double", while the accuracy of an algorithm means the influence of rounding errors. I still do not see anything unexpected.
Posting the values as screen shot does not help to reproduce the problem. You've posted the code, but it is still not clear, where you observe a problem.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!