Matlab polyfit to Yalmip

25 views
Skip to first unread message

Paras Salunkhe

unread,
Apr 9, 2015, 11:11:57 AM4/9/15
to yal...@googlegroups.com
Hi,

 I have a polynomial generated in Matlab using the polyfit command. I want to convert this polynomial as a sdpvar polynomial. Any way how I can do that?

Thanks,
-Paras

Johan Löfberg

unread,
Apr 9, 2015, 12:53:04 PM4/9/15
to yal...@googlegroups.com
No direct command, but with the coefficients, it is just straightforward coding, vectorized or what ever you want to do

X = 0:0.1:1;Y = sin(X);
c
= polyfit(X,Y,3);
p
= fliplr(c)*monolist(x,3);
p
= c*(x.^(3:-1:0)');
p = 0;for i = 0:3;p = p + c(i+1)*x.^(3-i);end
sdisplay(p)
-0.000133237237+1.0042*x-0.0188*x^2-0.1440*x^3




Mark L. Stone

unread,
Apr 9, 2015, 4:23:16 PM4/9/15
to yal...@googlegroups.com
You have a typo in the final method.  Should be c(i+1), not c(i) .

Johan Löfberg

unread,
Apr 10, 2015, 1:19:30 AM4/10/15
to yal...@googlegroups.com
Right, thanks
Reply all
Reply to author
Forward
0 new messages