0
Homework physics help
This is actually a physics assignment simulating a throw. Can someone please help me to plot a function based on the solution of the equation? I want to plot a function where the 'y' symbol is the variable. Please ask questions if u don't understand my problem. import sympy as sp import matplotlib.pyplot as plt import numpy as np from scipy import constants as constant x = sp.Symbol('x') t = sp.Symbol('t') y = sp.Symbol('y') y0 = 2.0 x0 = 0 v0 = 20 v0x = v0*np.sin(30) v0y = v0*np.cos(30) ax = 0 ay = -(constant.g) eq1 = sp.Eq(0.5*ax*t**2 + v0x*t + x0,x) eq2 = sp.Eq(0.5*ay*t**2 + v0y*t + y0,y) solve = sp.solve((eq1,eq2), (x, t))
4 Answers
+ 1
I found that the result of your equation is a 2d list with each element being a function of y.
You can use sympy.plotting to generate subplots for each equation and combine them to a single plot like this.
Maybe there is an easier way, but I am not an expert :)
https://code.sololearn.com/c61vJw2tYyx0/?ref=app
0
I think, It looks like youâre working on projectile motion â nice start! Youâve defined the equations correctly for horizontal and vertical motion.
Since you want to plot y as a function of x, youâll first need to eliminate t (time) from your equations. You can do this by solving the first equation for t, then substituting that result into the second equation.
After substitution, youâll get an expression for y(x) that you can turn into a numerical function using lambdify for plotting.
Get expert physics assignment help at Studyunicorn.com from real professionals. We provide accurate solutions, clear explanations, and timely support to boost your grades and understanding. Trusted by students worldwide.
https://www.studyunicorn.com/physics-homework-help
0
The main issue in your script is that you are asking SymPy to solve for both x and t, but x is meant to be the output, not an unknown. Instead, solve for t from eq1, then substitute that t into y(t) to get y as a function of x.
Once you have y(x), you can convert it to a NumPy function and plot it.
Below is a complete working example you can use:
import sympy as sp
import matplotlib.pyplot as plt
import numpy as np
from scipy import constants as constant
# Symbols
x = sp.Symbol('x')
t = sp.Symbol('t')
# Initial conditions
y0 = 2.0
x0 = 0
v0 = 20
v0x = v0 * np.cos(np.deg2rad(30))
v0y = v0 * np.sin(np.deg2rad(30))
ax = 0
ay = -constant.g
# Kinematic equations
eq1 = sp.Eq(0.5*ax*t**2 + v0x*t + x0, x)
eq2 = 0.5*ay*t**2 + v0y*t + y0
# Solve eq1 for time t
t_sol = sp.solve(eq1, t)[0] # choose the positive root
# substitute t(x) into y(t)
y_of_x = sp.simplify(eq2.subs(t, t_sol))
# create numerical function
y_func = sp.lambdify(x, y_of_x, "numpy")
# generate x values
x_vals = np.linspace(0, (2*v0y/constant.g)*v0x, 300)
# plot
plt.plot(x_vals, y_func(x_vals))
plt.xlabel("x (m)")
plt.ylabel("y (m)")
plt.title("Projectile Motion Path")
plt.grid(True)
plt.show()
Explanation
t_sol gives you time as a function of x.
Substituting into eq2 creates y(x), which is then plotted.
This yields the trajectory curve of the thrown object.
If you need further clarification on physics concepts, coding structure, or assignment writing, resources like Essay writing help at Assignmentsgenius.com can offer academic help online. Just be sure to use such help responsibly and ensure you understand the material. Visit here: https://www.assignmentsgenius.com



