C code for polyfit
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
dpb
il 25 Mag 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
il 28 Mag 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?
Risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!