Numerical integration with constant parameters

조회 수: 32 (최근 30일)
Xin
Xin 2013년 6월 10일
편집: Walter Roberson 2025년 2월 17일
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
Andrei Bobrov
Andrei Bobrov 2013년 6월 10일
편집: Andrei Bobrov 2013년 6월 10일
corrected, input values for a, b, c
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