Inequalities using function handles
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sundar Aditya
il 30 Gen 2017
Commentato: Sundar Aditya
il 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.
0 Commenti
Risposta accettata
Steven Lord
il 30 Gen 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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!