Need help with complicated Legendre function to be integrated

9 views (last 30 days)
I am trying to figure out how to integrate a complicated function that has legendre polynomials in it. Mu is the variable by which I am attempting to integrate, from 0 to Muo. I am not sure why the legendres are turning into arrays instead of scalars, which I believe is the main problem. Also, the dGam is an array as well, which might not be right. I'm thinking that I need to differentiate Phi first, then plug in the value of Mu, but I am not sure what the derivative would be, and wolframaplha wasn't much help. Any advice would be greatly appreciated. Thank you!
------
m = 2; %choosing the index
muo = 5; %length of blade
nGam = 2; %order of gamma
B = quad(@Bfun,0.0001,muo,[],[],m,muo,nGam)
---------
function y = Bfun(mu,m,muo,nGam)
x = 2*mu/muo - 1; %change of variable (-1<x<1)
P1 = legendre(m+1,x); %Legendre polynomial
P1 = P1(m+2,:) %Selecting first order
P2 = legendre(m-1,x); %Legendre polynomial
P2 = P2(m,:) %Selecting first order
Phi2 = (P1 - P2)/(sqrt(2*(2*m-1))); %eqn for Phi2
dPhi2 = gradient(Phi2); %deriving Phi2
dPhi = 2/muo * dPhi2; %deriving Phi
dGam = [(nGam*(mu./sqrt(1 + mu.^2)).^nGam)./(nGam + mu.^3)]' %deriving gamma
y = -1* mu .* dPhi * dGam %sending final function
end
  1 Comment
Walter Roberson
Walter Roberson on 31 May 2011
If you post the original formula, there is a possibility that I could figure it out in Maple.

Sign in to comment.

Answers (3)

Mike Hosea
Mike Hosea on 1 Jun 2011
I haven't looked at your example in any kind of detail, but I wonder if you're aware that QUAD requires your function to operate elementwise on an array of mu values? If this is inconvenient, you can meet the requirement in a trivial way with arrayfun. Try it this way (and then debug from there, if need be):
integrand = @(mu)Bfun(mu,m,muo,nGam); % scalar mu only
vintegrand = @(mu)arrayfun(integrand,mu); % vector mu supported
B = quad(vintegrand,0.0001,muo)
Notice that this also "binds" the values of m, muo, and nGam in the definition of the integrand function rather than passes them in as arguments to quad. If you do it that way, you can use quadgk if you want. -- Mike

Andrew
Andrew on 3 Jun 2011
I was able to figure out a way to do it using symbolic variables. However when I tried to calculate the integral it said:
---------------
Warning: Explicit integral could not be found.
B =
int(-(2*10^(1/2)*mu^3*(((2*mu)/5 - 1)^2 + ((2*mu)/5 - 1)*((4*mu)/5 - 2) - 1))/(25*(mu^2 + 1)*(mu^3 + 2)), mu = 0..5)
---------------
I copied the above line into WolframAlpha and it was able to integrate fine. Is there anyway matlab would be able to do this integral? Thanks!
  3 Comments
Andrew
Andrew on 3 Jun 2011
Yeah, I tried the simplify, but it didn't work. Unfortunately I don't have maple, and I'm trying to use matlab. Do you know if there's any way to turn the symbolic equation into a numerical equation and then use quad( ) to evaluate it?
Walter Roberson
Walter Roberson on 3 Jun 2011
fun = matlabFunction(-(2*10^(1/2)*mu^3*(((2*mu)/5 - 1)^2 + ((2*mu)/5 - 1)*((4*mu)/5 - 2) - 1))/(25*(mu^2 + 1)*(mu^3 + 2)));

Sign in to comment.


Andrew
Andrew on 3 Jun 2011
I tried this:
quad(@(mu)Bfun(m,muo,nGam),0,5)
but it gave the following error message:
---------- ??? Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> quad at 81 if ~isfinite(y(1)) ----------

Categories

Find more on Numerical Integration and Differential Equations 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!