Numerical integration with constant parameters

33 次查看(过去 30 天)
how to do numerical integration with constant parameters?
for example:
f=(sin(thea)*dot([sin(thea)*cos(phia) sin(thea)*sin(phia) cos(thea)],[a*cos(thea) b*sin(thea) c*sin(thea)*cos(phia))*(3*cos(thea)*cos(thea)-1)/2
I want to do integration with thea and phia from 0-pi and 0-2*pi, respectively.
a b c are constant parameters.
What kind of functions should I use? Because like quad, dblquad can not deal with symbolic.
Thanks so much.

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2013-6-10
编辑:Andrei Bobrov 2013-6-10
f = @(thea,phia,a,b,c)sin(thea)*dot([sin(thea)*cos(phia) sin(thea)*sin(phia) cos(thea)],[a*cos(thea) b*sin(thea) c*sin(thea)*cos(phia)])*(3*cos(thea)*cos(thea)-1)/2;
a = 1; b = 1; c = 1;
dblquad(@(thea,phia)f(thea,phia,a,b,c),0,pi.0,2*pi);
OR for symbolic
syms thea phia a b c
f = sin(thea)*dot([sin(thea)*cos(phia) sin(thea)*sin(phia) cos(thea)],[a*cos(thea) b*sin(thea) c*sin(thea)*cos(phia)])*(3*cos(thea)*cos(thea)-1)/2;
fm = matlabFunction(f);
a = 1; b = 1; c = 1;
dblquad(@(thea,phia)fm(thea,phia,a,b,c),0,pi.0,2*pi);
  3 个评论
VBBV
VBBV 2025-2-17
@Xin Use a comma , instead of dot . in dblquad function for integration limits
syms thea phia a b c
f = sin(thea)*dot([sin(thea)*cos(phia) sin(thea)*sin(phia) cos(thea)],[a*cos(thea) b*sin(thea) c*sin(thea)*cos(phia)])*(3*cos(thea)*cos(thea)-1)/2;
fm = matlabFunction(f);
a = 1; b = 1; c = 1;
dblquad(@(thea,phia)fm(thea,phia,a,b,c),0,pi,0,2*pi) % use a comma for integration limits
ans = -2.5826

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by