필터 지우기
필터 지우기

Using quad or quad2d to evalute a 1-D integral of 2-D function

조회 수: 3 (최근 30일)
David C
David C 2011년 11월 16일
Hi,
I'm trying to evaluate a 1-D integral (single integral, not double integral). The integrand happens to be a function that takes 2 arguments, call it f(x,y). I am fixing one of the arguments as a constant. So I would like to:
Integrate f(x,2) from x=1 to x=10. Is there a way to do this using quad or quad2d? If not, what would you suggest I use to evaluate this integral?
Thanks, David

채택된 답변

Mike Hosea
Mike Hosea 2011년 11월 16일
You need to "bind" one of the arguments to whatever value you choose. This is done with an "anonymous" function.
fx = @(x)f(x,2)
is a function that takes one input argument, x, and returns f(x,2). I have called it fx here, but of course you could call it any valid variable name. So, fx(pi) = f(pi,2). We don't have to name this function. We can just pass it to the integrator, so the answer to your question is
quadgk(@(x)f(x,2),1,10)
Of course this works with quad as well, but why do people use quad anymore when they have quadgk?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by