C code for polyfit

조회 수: 6 (최근 30일)
Aziz
Aziz 2014년 5월 25일
댓글: Ryan Livingston 2014년 5월 28일
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
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
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개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by