Scroll to Top

Virtual Math Learning Center

Virtual Math Learning Center Texas A&M University Virtual Math Learning Center

Solving Equations Symbolically in Python

Author: David Manuel

In this video, it is shown how to solve equations symbolically using Python and save the results as variables to use the results in furthur calculations. We also learn how to recognize when Python is giving a small imaginary part due to round off errors. The example given in the video solves a trigonometric equations, and it is shown how to convert the radian answers into degrees.

Transcript 04

Problem: Suppose former A&M punter Braden Mann wants to punt a ball 50 m and the ball leaves his foot with an initial velocity of 30 m/s. To determine the angle the ball needs to be kicked, it can be shown that the answer can be found by solving the equation \[50\tan(\theta)-\dfrac{13.61}{\cos(\theta)^2} = 0.\]

Python Code: 
from sympy import *

theta=symbols('theta')
LHS=50*tan(theta)-13.61/(cos(theta))**2
thsol=solve(LHS,theta)
angle1=re(thsol[2])
angle2=re(thsol[3])
print(angle1*180/pi.evalf(),angle2*180/pi.evalf())

Open Python Notebook File

See more videos from this section