Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm working on solving differential equations through Fourier series, I made a function to help me calculate the coefficients that looks like this:

bn[α_, T_, f_] := (2/T)*Integrate[f*Sin[((2*Pi*n)/T)*t], {t, α, T + α}]

And it was workng pretty well, until I tried to evaluate this:

bn[0, L, Piecewise[{{0, 0 < t < L/3}, {w, L/3 < t < 2*(L/3)}, {0, 2*(L/3) < t < L}}]]

And it gives me the error:

Integrate::pwrl: Unable to prove that integration limits {L} are real. Adding assumptions may help. >>

Any idea on what is causing/how to avoid the error? I tried using assumptions, but I guess I'm doing it wrong because it doens't help.

bn[α_, T_, f_] := 
  Integrate[(2/T)*f*Sin[((2*Pi*n)/T)*t], {t, α, α + T}, Assumptions -> Element[T, Reals]]

Edit

You mean enter the code like it is now? Sorry for the inconvenience, but the advanced help for the site sort of suggested that I used LaTeX.

share|improve this question
    
I changed the format as you suggested. I think... Is it good now? –  Fernando Contreras Dec 2 '13 at 4:39
    
Thanks for the code addition. It does works well for non-piecewise defined functions f. I will pick at this later. Thanks for the post and the edit. You will get response in time I expect. My initial thought is to add code to deal with the piecewise defined cases in pieces. –  J. W. Perry Dec 2 '13 at 4:51
    
The problem is that it works for functions that have numeric limits such as: bn[-\[Pi], 2 \[Pi], \[Piecewise] { {-\[Pi], -\[Pi] < t < 0}, {\[Pi], 0 < t < \[Pi]} }] It does give me the expected result, I get stuck when I try to use variable periods T. –  Fernando Contreras Dec 2 '13 at 5:21
add comment

1 Answer 1

up vote 4 down vote accepted
bn[a_, T_, f_] := 2/T Integrate[f Sin[(2 π n)/T t], {t, a, T + a},  Assumptions -> T ∈ Reals]
bn[0, L, Piecewise[{{0, 0 < t < L/3}, {w, L/3 < t < 2 L/3}, {0, 2 L/3 < t < L}}]]

Mathematica graphics

share|improve this answer
    
I don't know if I'm interpreting that correctly: The output says that for any L>0, the result would be the one on the top left, times 2/L, right? –  Fernando Contreras Dec 2 '13 at 5:36
1  
@FernandoContreras Yes, run it. The result is a Piecewise function. Take a look at the Piecewise[] doc page –  belisarius Dec 2 '13 at 5:40
    
Ok, I'll take a look at the Piecewise doc, however the result seems odd. Since I couldn't let really stop working I solved it by hand and I get a completely different result. I'll get back at you when I figure out the problem. –  Fernando Contreras Dec 2 '13 at 5:44
    
@FernandoContreras Ok. The result seems good to me AFAIS –  belisarius Dec 2 '13 at 5:52
    
Ok, I analyzed the results I got in paper vs the code vs step by step in mathematica. Your answer is correct, as it makes the code work, however it still gives me a different result from the one that I'm getting on paper (and my book agrees with). Seems like the problem has to do with the Integration itself, not the piecewise. I suppose it has to do with assumptions I'm making that mathematica isn't, but I don't know why. It'd boil down to an integrate of: C Integrate[Sin[D t],{t,L/3,2L3] With C, and D being constants related to the weight distributed over a stick of length L. –  Fernando Contreras Dec 2 '13 at 7:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.