generated C/C++ code from `pinv`-command gives different result than the command `pinv` itself
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am using Matlab Coder for my Arduino. Inside my Matlab function I use the Matlab-command `pinv`. This Matlab-function is then converted into C/C++ code (let's call it `pinvC`) using the Code Generator from Matlab.
However, I noticed the following. The result of Matlab-command `pinv` inside Matlab function is different to the result of `pinvC`. What is causing this? How can I solve it?
0 Kommentare
Antworten (1)
James Tursa
am 14 Nov. 2018
How much different? The MATLAB code is calling into BLAS and LAPACK library routines to accomplish this. But the Coder is not using that same library code to generate its results, hence the difference.
2 Kommentare
Mike Hosea
am 20 Nov. 2018
James is correct. Different stability properties induced by PINV per se does not seem likely, but different PINV implementations will issue different numerical perturbations, which might be magnified by how you use PINV.
You might try an experiment perturbing the output of PINV in MATLAB by some units in the last place to explore what your algorithm does with it in MATLAB, i.e. with no code generation involved. Something like:
X = pinv(A);
X = X + randi([-10,10],size(X)).*eps(X)
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!