C code for polyfit
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2014-5-25
...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
2014-5-28
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?
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!