# How to write a function with an integral?

f[a_, b_] = Integrate[Sin[aPix]Sin[bPix], {x,0,1}];

This function does not work at some points. When I try to evaluate f[1,1], it says "Infinite expression 1/0 encountered."

How can I get around this? It should obviously return 1/2 at that point

• First try f[a_, b_] = Integrate[Sin[a*Pi*x]Sin[b*Pi*x], {x,0,1}]; f[1,1] and then try f[a_, b_] := Integrate[Sin[a*Pi*x]Sin[b*Pi*x], {x,0,1}]; f[1,1] and then CAREFULLY compare those two, character by character. Understanding exactly why those results are so different when the input is so similar will be very important to your becoming more skilled with Mathematica. Wrapping Trace[...] around that and looking at what it shows will be difficult to understand, but it may give you hints about what happened in each of these.
– Bill
Sep 17 '20 at 0:27
• SetDelayed , := work since Integrate[Sin[a*Pi*x] Sin[b*Pi*x], {x, 0, 1}] equal to (b Cos[b Pi] Sin[a Pi] - a Cos[a Pi] Sin[b Pi])/( a^2 Pi - b^2 Pi) so a=b is a removable singularity point. Sep 17 '20 at 1:27

In addition to the answers provided in comments, you can separately consider the case $$a=b$$
f[a_, b_] = Integrate[Sin[a Pi x] Sin[b Pi x], {x, 0, 1}]