Inequalities using function handles
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to integrate a function h(x,y) over a region, but the value of h depends on two other functions f(x,y) and g(x,y) in the following manner:
if f(x,y)<=g(x,y), then h(x,y)=h1(x,y)
else h(x,y)=h2(x,y)
I have created function handles for f and g, and would like to implement a condition like 'if f(x,y)<= g(x,y)', so that I can define the appropriate function handle for h in this regime. Any ideas on how this can be done? Thanks.
0 个评论
采纳的回答
Steven Lord
2017-1-30
Assuming x and y are the same size, that all the functions involved are vectorized and in scope:
function z = h(x, y)
fxy = f(x, y);
gxy = g(x, y);
z = NaN(size(x));
condition1 = fxy <= gxy;
z(condition1) = h1(x(condition1), y(condition1));
z(~condition1) = h2(x(~condition1), y(~condition1));
If you've define f, g, h1, and h2 as anonymous functions in the workspace from which you're calling h, you should pass them into h as input.
function z = h(x, y, f, g, h1, h2)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!