Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Here, we will aim to provide you with a number of exercises and solutions with a varying degree of difficulty. There will also occur exercises that requires you to use functions that has not yet been described in Symbolic mathematics.

Info

If you have a suggestion on a topic you would like to see some more exercises (or tutorials) on, please send us a mail or leave a post on our Forum. We are more than happy to recieve feedback.



Panel
borderColor#dfe1e5
bgColor#eff9ff
borderWidth2
titlePage content

Table of Contents


Integration

Exercise 1: Single definite integral

Expand
titleExercise: Single definite integral

This example is taken from the 2018 exam in TMA4100 - Calculus 1, check out the exam and the solution for hand calculations (only in norwegain). This is task 2.

Compute the intregral


Expand
titleSolution: Single definite integral


Code Block
languagepy
titleSolution
from sympy import *

# First we define our variable
x = Symbol('x')
# We then compute the answer to our given interval
ans = integrate(x*log(x**2), (x, 1, 4))     # log() without specifying the base equals ln()
# Finally, we print the answer
print(ans)


# Output:
-15/2 + 8*log(16)	# log() is here the natural logarithm



Exercise 2: Double definite integral

Expand
titleExercise: Double definite integral

Compute the integral


Expand
titleSolution: Double definite integral


Code Block
from sympy import *

# First we define our variables
x, y = symbols('x y')

# To make our code more readable, we will define the function we will integrate first.
f = x**3*exp(y)

# The integrate function is able to take multiple integrations as parameteres.
# The different integrations are listed according to the integration order: dy -> dx
ans = integrate(f, (y, x**2, 9), (x, 0, 3))

print(ans)
print(float(ans))   # Since the answer includes a constant, we have to specify if we want it as a float



# Output:
-1/2 + 65*exp(9)/4
131674.6138231



Exercise 3: Triple definite integral

Expand
titleExercise: Triple definite integral

Compute the integral


Expand
titleSolution: Triple definite integral


Code Block
languagepy
titleSolution
from sympy import *

# First we define our variables
x, y, z = symbols('x y z')

# The integrate function is able to take multiple integrations as parameteres.
# The different integrations are listed according to the integration order: dz -> dx -> dy.
ans = integrate(1, (z, 24*x, 1), (x, -sqrt(1-y**2), sqrt(1-y**2)), (y, -1, 1))

print(ans)
print(float(ans))   # Since the answer (in this case) is a constant, we have to specify if we want it as a float


# Output:
pi
3.141592653589793






BibTeX Display Table