Reputation: 15
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?
Upvotes: 0
Views: 1594
Reputation: 1105
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'
.
Upvotes: 1