Can symbolic tool box transfer max(f(x), y) into symbolic variable?

조회 수: 1 (최근 30일)
Tao
Tao 2015년 5월 25일
댓글: Walter Roberson 2015년 5월 26일
I was using fmincon for nonlinear optimization, but When I tried to use MATLAB symbolic toolbox to provide joccobian of my constraint function, MATLAB showed terminated saying the symbolic toolbox cannot transfer function max(f(x), 0). In my constraint function, I called a function handle, and in that function there is max(f(x), 0). I used max(f(x), 0) in order to increase the robustness of my code, otherwise there is a high chance that MATLAB will terminate due to the complex number generated by my constraint function, which is wrong. I have no idea how to deal with the problem between symbolic toolbox and max(f(x),0), if anyone of you have solution I would be very grateful.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 26일
I suggest experimenting with a piecewise(), which you can generate inside the symbolic engine by using
min0 = evalin(symengine, 'x -> piecewise(x<0, 0, x)');
then min0(f(x)).
If that doesn't work, then Heaviside it:
syms min0(x)
min0(x) = x*Heaviside(x);
then min0(f(x))
  댓글 수: 2
Tao
Tao 2015년 5월 26일
Thank you Walter, I tried the Heaviside function, and it works but too slow. Since in my main file which I run fmincon, I need to change a variable value in both my objective and constraint function, which means every time I have to recalculate the symbolic gradient and Jaccobian once this variable value is changed. Could you give me any suggestion how to avoid calculating symbolic radient and Jaccobian every time?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by