Numerical integration with constant parameters

33 views (last 30 days)
Xin
Xin on 10 Jun 2013
Edited: Walter Roberson on 17 Feb 2025
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.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 10 Jun 2013
Edited: Andrei Bobrov on 10 Jun 2013
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 Comments
Andrei Bobrov
Andrei Bobrov on 10 Jun 2013
Edited: Andrei Bobrov on 10 Jun 2013
corrected, input values for a, b, c
VBBV
VBBV on 17 Feb 2025
@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

Sign in to comment.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!