Integrating a multivariate function w.r.t. a single variable
이전 댓글 표시
Hello,
I am defining a function using
f = @(x,y) (expression in x and y)
This definition I believe it is correct as I can call f(0,0) for example and I get the numerical value.
What I need to do next is integrate f(x,y) with respect to y between a and b and call this g(x). I need then to be able to pass g(x) to fsolve in order to compute the roots. How do I do this? I tried dblquad, but it integrates w.r.t. both variables at once. quad gives me and error as I am not sure what's the correct syntax for this.
Thanks, Alex
채택된 답변
추가 답변 (3개)
Walter Roberson
2013년 2월 13일
1 개 추천
You cannot do this with numeric integration.
If you have the symbolic toolbox, then expression the function symbolically and do symbolic integration with int(). Then if you need, you can use matlabFunction to turn the symbolic result into a function handle of a numeric function.
댓글 수: 2
Adrian Martinez
2021년 6월 5일
Can you please show an example of how to do this?
f = @(x,y) (x.^2-y.^2).*cos(x./(1+y.^2));
% Some limits of integration
a = 0;
b = 3;
syms x y
% Define g as the integral of f(x,y) dy from a to b
g(x) = int(f(x,y), y, a, b)
x0 = -100;
vpasolve(g, x0)
G = matlabFunction(g)
fsolve(G, x0)
In some cases, the int() step would be able to calculate a closed form expression, so G will not always end up with an integral() in it.
Youssef Khmou
2013년 2월 13일
Hi, try this :
syms x y
h=exp(-x^2-y^2)
F1=int(h,x)
F2=int(h,y)
Based on F1 and F2 you make function handle :
Fx=@(x) 1/2/exp(x^2)*pi^(1/2) % truncated ERF(Y)
Y=fsolve(Fx,0.1)
댓글 수: 2
Walter Roberson
2013년 2월 13일
How do you get from the "F1 and F2" to the Fx ? And where do the limits of integration over y come in?
Youssef Khmou
2013년 2월 13일
Hi,i used the undefined integration or "primitive" , for F1 you get :
F1 =
1/2/exp(y^2)*pi^(1/2)*erf(x)
you have an analytic integration w.r.t. x, so its function of y , now manually you set a function handle Fy :
Fy=@(x) 1/2/exp(y^2)*pi^(1/2)
and then solve it with "fslove" as Alexandru said he wants to use "fslove" .
Yang Zhang
2015년 3월 15일
0 개 추천
Use Symbolic Math Toolbox to your problem.
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!