Gradient of a function in C++

24 views
Skip to first unread message

Hoomaan Moradi

unread,
Mar 24, 2023, 1:00:43 PM3/24/23
to CasADi
Hello All,
Does anybody know how we can convert DM to double in C++?
Additionally, How can we compute the gradient of a CasADi function and obtain its value at a certain point in C++?
Thank you in advance

Joel Andersson

unread,
Mar 24, 2023, 5:06:25 PM3/24/23
to CasADi
Hi,
If the "DM" is a scalar (i.e. a 1-by-1 matrix), you can simply use assignment (there is a conversion operator defined):

  DM aaa = 3.2; // double to casadi::DM
  double a = aaa; // casadi::DM to double

For your second question, please reread the user guide. You have to create a function object corresponding to the gradient and then evaluate it numerically.

Joel

Reply all
Reply to author
Forward
0 new messages