2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ I changed the format as you suggested. I think... Is it good now? $\endgroup$ Dec 2 '13 at 4:39
  • $\begingroup$ 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. $\endgroup$ Dec 2 '13 at 4:51
  • $\begingroup$ 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. $\endgroup$ Dec 2 '13 at 5:21
4
$\begingroup$
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

$\endgroup$
5
  • $\begingroup$ 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? $\endgroup$ Dec 2 '13 at 5:36
  • 1
    $\begingroup$ @FernandoContreras Yes, run it. The result is a Piecewise function. Take a look at the Piecewise[] doc page $\endgroup$ Dec 2 '13 at 5:40
  • $\begingroup$ 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. $\endgroup$ Dec 2 '13 at 5:44
  • $\begingroup$ @FernandoContreras Ok. The result seems good to me AFAIS $\endgroup$ Dec 2 '13 at 5:52
  • $\begingroup$ 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. $\endgroup$ Dec 2 '13 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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