简体   繁体   中英

function max of symbolic values - matlab

I have to calculate some limits:

syms x1 x2 a
x0 = [0, 1];
x_dir = [1, 0];

f = max(0,x1) + (x1^2)*abs(x2)
f_lim = (1/a) * (f(x0 + a*x_dir) - f(x0))
f_lim_left = limit(f_lim, a, 0, 'left');
f_lim_right = limit(f_lim, a, 0, 'right');

I just can't use max function on symbolic values, because I am not allowed by MATLAB. But, it's obvious what I am trying to do: to get a piece of code that's independent of variables (x0, x_dir), so I can change them easily. I've tried using double or using feval(symengine,'max',x,-y) as found on net, but no luck. Any workaround, guys?

You can define f as

f(x1,x2) = feval(symengine,'max',x1,0) + (x1^2)*abs(x2);

and then compute its directional derivative with respect to x1 by finite differences as

f_lim_x1(x1, x2) = (f(x1+a, x2)-f(x1,x2))/abs(a);

You can also look at the limit function

limit(f, x1, x0, direction)

where direction can be either 'left' or 'right' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM