Inequalities using function handles

3 Ansichten (letzte 30 Tage)
Sundar Aditya
Sundar Aditya am 30 Jan. 2017
Kommentiert: Sundar Aditya am 1 Feb. 2017
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.

Akzeptierte Antwort

Steven Lord
Steven Lord am 30 Jan. 2017
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)

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by