Derivative operation with YALMIP

56 views
Skip to first unread message

optimizer

unread,
Aug 16, 2018, 8:14:18 AM8/16/18
to YALMIP
Hi, let us assume i have a matrix as:

x=sdpvar(3,1);
mat_x=diag(x);

Then:
sdisplay(mat_x)

ans =

  3×3 cell array

    {'internal(1)'}    {'0'          }    {'0'          }
    {'0'          }    {'internal(2)'}    {'0'          }
    {'0'          }    {'0'          }    {'internal(3)'}

Do i have an operation to perform partial derivative of mat_x respect to an sdpvar, let assume for example internal(1) so i obtain:

derive(mat_x,internal(1))=

3×3 cell array

    {'1'}    {'0'          }    {'0'          }
    {'0'          }    {'0'}    {'0'          }
    {'0'          }    {'0'          }    {'0'}

Thank you

Johan Löfberg

unread,
Aug 16, 2018, 8:17:19 AM8/16/18
to YALMIP
only vectors, so you would have to reshape your way around that

n = 3;
x
= sdpvar(3,1);
X
= diag(x);
reshape
(full(jacobian(X(:),x)),n,n,n)


Message has been deleted

optimizer

unread,
Aug 16, 2018, 8:38:44 AM8/16/18
to YALMIP
This approach works even for non diagonal matrix?

For example:
n=9;
x=sdpvar(n,1);
x_mat=[x(1)+x(3)          -x(3)                          0                           0                                   0                                   0;
            -x(3)                  +x(2)+x(3)+x(4)        -x(4)                      0                                   0                                   0;
             0                       -x(4)                          x(4)+x(5)              -x(5)                              0                                   0;
             0                       0                                   -x(5)                  x(5)+x(6)+x(7)            -x(7)                                0;
             0                       0                                   0                        -x(7)                              x(7)+x(8)+x(9)            -x(9);
             0                       0                                   0                           0                                   -x(9)                          x(9)];    
Thank you

Johan Löfberg

unread,
Aug 16, 2018, 8:40:01 AM8/16/18
to YALMIP
it works for arbitrary dimensions, you just have to make sure to reshape back correctly

optimizer

unread,
Aug 16, 2018, 8:43:14 AM8/16/18
to YALMIP
I never used reshape but i this case i should go with:

reshape(full(jacobian(x_mat(:),x)),6,6,n)

right?

Johan Löfberg

unread,
Aug 16, 2018, 8:44:36 AM8/16/18
to YALMIP
I guess. You will have to look and see 

optimizer

unread,
Aug 16, 2018, 8:47:41 AM8/16/18
to YALMIP
Yes it seems good to me, thank you so much.
Problem solved. Have a nice day!
Reply all
Reply to author
Forward
0 new messages