C code for polyfit

7 Ansichten (letzte 30 Tage)
Aziz
Aziz am 25 Mai 2014
Kommentiert: Ryan Livingston am 28 Mai 2014
1) In the matlab code below, I was expecting that when I generate code, it would give me C code for the polyfit function but it did not. Can you please tell me why? Is there any way for it to give me the C code for polyfit solving for the coefficients for the second order equation below?
function y = fcn(u) %#codegen
x = [100, 300, 500]; y = [0.0019, 0.000967, 0.00067]; z = polyfit (x,y, 2); y = z*100000; u = 1;
end
  2 Kommentare
dpb
dpb am 25 Mai 2014
...but it did not. [expand to standalone C] Can you please tell me why?
'Cuz polyfit uses much intelligence in solving the system as it is general for any polynomial, not just linear or quadratic. That means a matrix inversion (in effect, not in reality) routine, etc., etc., etc., ...
If you needs must have it in C, probably shortest route is to derive the solution from the sums of squares terms specifically for the quadratic form and backsolve them.
Ryan Livingston
Ryan Livingston am 28 Mai 2014
In R2014a polyfit should be supported for code generation. Search for polyfit here:
What MATLAB release are you using? What errors did you get when trying to generate code?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by