#πŸ”’ Dynamic problem help

14 messages Β· Page 1 of 1 (latest)

cyan hare
#

Hi I had an assignment to plot and make a solution for the following problem although my code isnt working entirely and idk why.

The assignment:
An airplane flies in a straight line at 300 km/h in the negative x-direction. The two engines A and B produce a propulsive force TA=40kN and TB=20kN respectively. This will cause the airplane to make a turn. The airplane has a mass of 200Mg and a radius of gyration around the center of mass G

of 15 meters.

Use the methods we learned in the tutorials to calculate the motion of the airplane with solve_ivp. Do this for 10 seconds with time steps of 0.1 seconds. Take the starting position of the airplane as the origin. Save the calculated positions, angles and velocities as x_num, y_num, theta_num and vx_num, vy_num, omega_num.

spring narwhalBOT
#

@cyan hare

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cyan hare
#

SOLUTION code i got rn:
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt

m = 200000
r = 15
I = m * r**2
TA = 40000
TB = 20000
d = 8
v0 = -300 / 3.6
def equations(t, state):
x, y, vx, vy, theta, omega = state
Fx_body = TA + TB
Fy_body = 0
M = (TA - TB) * d
Fx = Fx_body * np.cos(theta)
Fy = -Fx_body * np.sin(theta)

return [vx, vy, Fx / m, Fy / m, omega, M / I]

state0 = [0, 0, v0, 0, 0, 0]
t_span = (0, 10)
t_eval = np.arange(0, 10.1, 0.1)
resultaat = solve_ivp(equations, t_span, state0, t_eval=t_eval)
x_num, y_num, vx_num, vy_num, theta_num, omega_num = resultaat.y
TEST code i got rn
from solution import resultaat, x_num, y_num, vx_num, vy_num, theta_num, omega_num
t_eval = resultaat.t
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 4))
plt.subplot(1, 3, 1)
plt.plot(t_eval, x_num, label='x')
plt.plot(t_eval, y_num, label='y')
plt.title('positie (m)')
plt.xlabel('tijd (s)')
plt.legend()

plt.subplot(1, 3, 2)
plt.plot(t_eval, vx_num, label='vx')
plt.plot(t_eval, vy_num, label='vy')
plt.title('snelheid (m/s)')
plt.xlabel('tijd (s)')
plt.legend()

plt.subplot(1, 3, 3)
ax = np.gradient(vx_num, 0.1)
ay = np.gradient(vy_num, 0.1)
plt.plot(t_eval, ax, label='x')
plt.plot(t_eval, ay, label='y')
plt.title('versnelling (m/sΒ²)')
plt.xlabel('tijd (s)')
plt.legend()

plt.tight_layout()
plt.show()

#

and this being the error
Traceback (most recent call last):
File "/user_code/.local/lib/python3.12/site-packages/numpy/testing/_private/utils.py", line 1679, in assert_allclose
assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
File "/user_code/.local/lib/python3.12/site-packages/numpy/testing/_private/utils.py", line 885, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=1e-07, atol=1e-05
De waarden van x_num kloppen nog niet
Mismatched elements: 100 / 101 (99%)
Max absolute difference among violations: 29.96834437
Max relative difference among violations: 0.0353268
ACTUAL: array([ 0. , -8.331833, -16.660667, -24.9865 , -33.309333,
-41.629167, -49.946 , -58.259833, -66.570667, -74.8785 ,
-83.183333, -91.485167, -99.784 , -108.079833, -116.372667,...
DESIRED: array([ 0. , -8.334833, -16.672667, -25.0135 , -33.357333,
-41.704167, -50.054 , -58.406833, -66.762667, -75.1215 ,
-83.483333, -91.848167, -100.216 , -108.586833, -116.960666,...
Traceback (most recent call last):
File "/user_code/.local/lib/python3.12/site-packages/numpy/testing/_private/utils.py", line 1679, in assert_allclose
assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
File "/user_code/.local/lib/python3.12/site-packages/numpy/testing/_private/utils.py", line 885, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=1e-07, atol=1e-05
De waarden van vx_num kloppen nog niet
Mismatched elements: 100 / 101 (99%)
Max absolute difference among violations: 5.9810651
Max relative difference among violations: 0.06928634
ACTUAL: array([-83.333333, -83.303333, -83.273333, -83.243333, -83.213333,
-83.183333, -83.153333, -83.123333, -83.093333, -83.063333,
-83.033333, -83.003333, -82.973334, -82.943334, -82.913334,...
DESIRED: array([-83.333333, -83.363333, -83.393333, -83.423333, -83.453333,
-83.483333, -83.513333, -83.543333, -83.573333, -83.603333,
-83.633333, -83.663333, -83.693333, -83.723333, -83.753333,...

#

Rn with this code i do have enough points to fix this but i would like to know what is wrong with the code

candid mirage
#

This is way over my head but if d means diameter it should be 16.

candid mirage
#

gotcha, I don't have any other input but it will be easier for others to read if you put the code in a codeblock

#

!code

spring narwhalBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

cyan hare
#

ah i see

#

alr

spring narwhalBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.