Definite and Indefinite Integrals
In this example, we show how to compute indefinite and definite integrals in Python. Suppose we have an AC voltage, v(t) = Vcos(omega*t). We will calculate three things: the indefinite integral of v(t)^2, the definite integral of v(t)^2 over one period (from 0 to 2pi/omega), then finally the rms (or root mean square) value of the voltage, which is sqrt(omega/2pi * the definite integral. First, we define V, omega, and t as symbolic variables using the symbols command. Then we define v(t) and use the integrate command to find the indefinite integral. As with derivatives, we can use either COMMAND(VARIABLE) or VARIABLE.COMMAND, and our option is the variable of integration, in this case, t. Even if the problem did not require it, it is always a good idea to print the output for your intermediate steps to make it easier to debug code. For the definite integral, we use the same syntax, but notice that our domain of t values occurs in a tuple (we put parentheses around the entire thing). This is the same syntax as when we plot a function over a given domain. Finally, we compute the rms value of the voltage by typing in the expression and notice it is independent of omega, the frequency.