Trying to solve coupled differential equations with euler’s method

I’m trying to simulate the flight of a glider I 3D printed and tested.
My model is the following :
The glider is launched with an initial velocity and angle of attack (θ in the code), the forces at play here are its weight, drag and lift, no thrust at all.
I’ve put in equation the model and here is what I found :

dX/dt = -B(X^2+Y^2)(Cl*sin(θ)+Cd*cos(θ) dY/dt = - g + B(X^2+Y^2)(Cl*cos(θ)-Cd*sin(θ) where X = Vx and Y = Vy, B = 0.5*µ*S/m and Cl, Cd the lift and drag coefficients

Now for the code :

First I import Cl/Cd data from a CSV file and interpolate them.
I define my dX/dt, dY/dt functions
I define my Euler function to solve

import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as interpolate

# Data
rho = 1.2
m = 0.06
S = 0.05
g = 9.81

B = 0.5*rho*S*(1/m)

# Data on angle of attack, lift coefficient, and drag coefficient
angles = []  
CL_raw = []  
CD_raw = []  

file = open("C:/Cours Prépa/TIPE/xf-naca0015-il-50000.csv")
L = file.readlines()
for i in range(11, 100):
    angles.append(float(L[i].split(",")[0]))
    CL_raw.append(float(L[i].split(",")[1]))
    CD_raw.append(float(L[i].split(",")[2]))

# Interpolation of the data
f_CD = interpolate.interp1d(angles, CD_raw)
f_CL = interpolate.interp1d(angles, CL_raw)

# Creating arrays with higher resolution values
angles_interp = np.linspace(min(angles), max(angles), 1000)
CD_interp = f_CD(angles_interp)  # Using interpolation function for CD
CL_interp = f_CL(angles_interp)  # Using interpolation function for CL


# Functions to calculate derivatives dX/dt and dY/dt based on the inclination
def dX_dt(X, Y, θ):
    CD = f_CD(θ)
    CL = f_CL(θ)
    return -B*(X**2 + Y**2)*(CL*np.sin(np.radians(θ)) + CD*np.cos(np.radians(θ)))

def dY_dt(X, Y, θ):
    CD = f_CD(θ)
    CL = f_CL(θ)
    return -g + B*(X**2 + Y**2)*(CL*np.cos(np.radians(θ)) - CD*np.sin(np.radians(θ)))


# Main function for Euler's method
def euler(dt):
    # Initial conditions
    X = [15]  # Initial horizontal velocity in m/s
    Y = [0]   # Initial vertical velocity in m/s
    x = [0]   # Initial horizontal position in m
    y = [10]  # Initial vertical position in m
    θ = [np.rad2deg(np.arctan(Y[0]/X[0]))] # Initial angle of attack
    v = [np.sqrt(X[0]**2 + Y[0]**2)]
    elapsed_time = 0

    i = 0

    # Euler's method
    while y[i] >= 0:
        X.append(X[i] + dX_dt(X[i], Y[i], θ[i])*dt)
        Y.append(Y[i] + dY_dt(X[i], Y[i], θ[i])*dt)
        x.append(x[i] + X[i]*dt)
        y.append(y[i] + Y[i]*dt)
        v.append(np.sqrt(X[i]**2 + Y[i]**2))
        elapsed_time += dt
        θ.append(np.rad2deg(np.arctan(Y[i]/X[i])))
        if θ[i] > angle_limit or θ[i] < -angle_limit:
            print("Stall")
            return x, y, v, elapsed_time, θ
        i += 1

    return x, y, v, elapsed_time, θ

# Simulation parameters
dt = 0.001   # Time step in seconds
angle_limit = 10  # Stall angle limit in degrees


x, y, v, elapsed_time, θ = euler(dt)
print(elapsed_time)
time_array = np.arange(0, elapsed_time, dt)

# Plotting the graph
fig = plt.figure(figsize=(15, 10))

plt.subplot(3, 2, 1)
plt.plot(angles, CD_raw, 'o', label='Raw data')
plt.plot(angles_interp, CD_interp, '-', label='Interpolation')
plt.xlabel('Angle of Attack (degrees)')
plt.ylabel('Drag Coefficient (CD)')
plt.title('Variation of CD with Angle of Attack')
plt.legend()
plt.grid(True)

plt.subplot(3, 2, 2)
plt.plot(angles, CL_raw, 'o', label='Raw data')
plt.plot(angles_interp, CL_interp, '-', label='Interpolation')
plt.xlabel('Angle of Attack (degrees)')
plt.ylabel('Lift Coefficient (CL)')
plt.title('Variation of CL with Angle of Attack')
plt.legend()
plt.grid(True)

plt.subplot(3, 2, 3)
plt.plot(x, y)
plt.ylim([0, 11])
plt.xlabel('x (m)')
plt.ylabel('y (m)')
plt.title('Aircraft Trajectory')
plt.grid(True)

# Plotting the graph of the aircraft's inclination relative to the ground
plt.subplot(3, 2, 4)
plt.plot(time_array, θ)
plt.xlabel('Time')
plt.ylabel('Inclination (degrees)')
plt.title('Aircraft Inclination Relative to Ground')
plt.grid(True)

plt.subplot(3, 2, 5)
plt.plot(time_array, v)
plt.xlabel('Time')
plt.ylabel('Speed magnitude v')
plt.title('Speed Magnitude Over Time')
plt.grid(True)

plt.tight_layout()
plt.show()

When I run the code, the angle of attack suddenly drops no matter what I try.
I tried a lot of initial conditions and time steps etc… but no matter what I do the angle of attack always diverges rapidly, which is not what happens in real testing

Let me know if you have any idea
Thanks

When I run the code, the angle of attack suddenly drops no matter what I try.
I tried a lot of initial conditions and time steps etc… but no matter what I do the angle of attack always diverges rapidly, which is not what happens in real testing

Let me know if you have any idea
Thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật