Using Yalmip in Embeded Matlab Function of Simulink

680 views
Skip to first unread message

Sanaz Sabzevari

unread,
Apr 4, 2018, 4:49:32 AM4/4/18
to YALMIP
Hi Johan,

Thanks a lot for all of your precise response.

I have a question regarding the usage of Yalmip in Simulink by embedded Matlab function. I can not use addpath(genpath ... in the embedded Matlab function. On the other hand, some errors pop up due to mosek and all the solver that is not defined. What should I do for using Yalmip in embedded Matlab function?

Johan Löfberg

unread,
Apr 4, 2018, 4:56:14 AM4/4/18
to YALMIP

If you’re trying to compile code with YALMIP inside, it will require some work

https://yalmip.github.io/faq/compilesolver/

 

And as it says in the Simulink example, the YALMIP call has to be done in an interpreted function if you are using Simulink

https://yalmip.github.io/example/simulink/

 

Sanaz Sabzevari

unread,
Apr 6, 2018, 7:05:00 AM4/6/18
to YALMIP
Super thanks,

but when I use the interpreted Matlab Fnc, it makes the running very slowly. And practically I can not use it. 

Also, the Mosek license is limited to 30 days. So How could I extend it?

Thanks very much indeed.

Johan Löfberg

unread,
Apr 6, 2018, 7:09:02 AM4/6/18
to YALMIP
The performance of YALMIP (if done correctly using optimizer object) and the underlying solver will not be significantly faster if you use anything else than an interpreted approach, as the major part will be in the core component of the solver anyway.

If your general simulink scheme runs slowly when you have to keep parts interpreted, well then you simply cannot use YALMIP in it.

Mosek is supported by sup...@mosek.com

Sanaz Sabzevari

unread,
Apr 6, 2018, 10:35:15 AM4/6/18
to YALMIP
No, for using Yalmip I use Interpreted Matlab Fnc as an example. But the other parts have not had a real problem.

I wanna know that is there any alternative ways for using Yalmip in Simulink?

Thanks

Johan Löfberg

unread,
Apr 6, 2018, 12:36:22 PM4/6/18
to YALMIP
No

rowida meligy

unread,
Apr 24, 2018, 9:27:06 PM4/24/18
to YALMIP
i need to use YALMIP in a simulink file to find optimal set point at each time step that maximizing output signal. how can i do this?

i wrote

function out = myfunction1(u)


x = sdpvar(1);

out = optproblem(30>=x>=160,u);

out=maximize(out)


but i doesnt work

Johan Löfberg

unread,
Apr 25, 2018, 2:02:11 AM4/25/18
to YALMIP
To begin with, your function looks really weird to use in a simulink scheme as the input u must be an sdpvar for the model to make sense.

Here it is explained how to do YALMIP in Simulink

rowida meligy

unread,
Apr 25, 2018, 7:44:39 AM4/25/18
to YALMIP
this is my function

function out = myfunction1(tin,e)

yalmip('clear')

T = sdpvar(1);

a=.0017;

b=1.49005*1000-1.4900*1000*tin*tin+2*.0017*1000*tin;

c=(-.0017*1000*tin*tin)-e

Objective=a*T^2+b*T+c;

Constraints = [T-tin <=20, 20 <= T <= 170];

P = optproblem(Constraints,Objective);

out=maximize(P)


but it doesnt work "Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported"


Johan Löfberg

unread,
Apr 25, 2018, 7:54:02 AM4/25/18
to YALMIP
it doesn't make sense to output a structure as you do now.

The only reasonable would be

diagnostics=maximize(P);
out = value(T)

or perhaps
diagnostics=maximize(P);
out = value(P)

However, note that
1. I already to told you how to use YALMIP efficiently in YALMIP
2. You are solving a nonconvex QP, so you can easily run into problems
3. Use the standard command optimize and optimizer. optproblem and maximize aren't used by anyone and aren't really supported

rowida meligy

unread,
Apr 25, 2018, 4:23:28 PM4/25/18
to YALMIP
Thanks alot, finally it works now.

I just want to ask how to make optimization function work every 20 minutes and not each sample time

Johan Löfberg

unread,
Apr 25, 2018, 4:34:21 PM4/25/18
to YALMIP
I have no idea what that question means
Reply all
Reply to author
Forward
0 new messages