필터 지우기
필터 지우기

Inequalities using function handles

조회 수: 3 (최근 30일)
Sundar Aditya
Sundar Aditya 2017년 1월 30일
댓글: Sundar Aditya 2017년 2월 1일
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.

채택된 답변

Steven Lord
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)
  댓글 수: 1
Sundar Aditya
Sundar Aditya 2017년 2월 1일
Thank you, Steven. This works.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by