# Plotting a function of sdpvar

512 views

### Yoke Peng Leong

Jun 5, 2017, 8:17:21 PM6/5/17
to YALMIP
What is the best way to plot a function of sdpvar?

For example:

x = sdpvar(2,1);
fx = 10*x(1) - 2*x(2);

I want to plot fx for x(1) in between -1 and 1 and x(2) in between -2 and 2.

### Johan Löfberg

Jun 6, 2017, 3:55:36 AM6/6/17
to YALMIP
Not really intended use of YALMIP

Message has been deleted

### Yoke Peng Leong

Jun 7, 2017, 5:16:44 PM6/7/17
to YALMIP
Of course plotting itself is not the intend nor using yalmip as a symbolic tool.

But, how do you plot the result of yalmip then?

For example, if I run solvesos and obtained the coefficients of a polynomial like fx, how do you create the plots of the resulting solution? Is there a way to replace sdpvar with value in bulk (like in vector form) instead of point by point using 'replace'?

### Johan Löfberg

`sdpvar x y[p,c] = polynomial([x y],4);solvesos([sos(p), replace(p,[x y],[pi 2]) == 3],[],[],c);f = sdisplay(replace(p,c,value(c)));f = f{1};f = replace(f,'*','.*');f = replace(f,'^','.^');f = eval(['@(x,y)' f]);[X,Y] = meshgrid(-1:0.01:1,-1:0.01:1);F = f(X,Y);mesh(X,Y,F);`