C code for polyfit

6 views (last 30 days)
Aziz
Aziz on 25 May 2014
Commented: Ryan Livingston on 28 May 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 Comments
dpb
dpb on 25 May 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 on 28 May 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?

Sign in to comment.

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!