Solves of the equation: dx/dt = ax(t) + by(t) dy/dt = ax(t) + by(t) with initial conditions x(0) = x0, y(0) = y0
from cmath import * from matplotlib.pyplot import * # 2023-01-28 EWS # parameter input print("systems of differential\nequations") print("dx/dt=a*x+b*y") print("dy/dt=c*x+d*y") a=float(input("a? ")) b=float(input("b? ")) c=float(input("c? ")) d=float(input("d? ")) m=float(input("x0? ")) n=float(input("y0? ")) # characteristic roots p=((a+d)+sqrt((a+d)**2-4*(a*d-b*c)))/2 q=((a+d)-sqrt((a+d)**2-4*(a*d-b*c)))/2 # set up result screen axis((0,10,0,10)) axis("off") # determine solutions # best used for real solutions if p!=q: r=(b*n+m*(p-d))/(p-q) s=m-r u=(c*m+n*(p-a))/(p-q) v=n-u text(0,9,"x=re**(pt)+se**(qt)") text(0,8.5,"r="+str(r)) text(0,8,"p="+str(p)) text(0,7.5,"s="+str(s)) text(0,7,"q="+str(q)) text(0,6,"y=ue**(pt)+se**(vt)") text(0,5.5,"u="+str(u)) text(0,5,"p="+str(p)) text(0,4.5,"v="+str(v)) text(0,4,"q="+str(q)) else: r=(b*n+m*(p-d)) s=m u=(c*m+n*(p-a)) v=n text(0,9,"x=rte**(pt)+se**(pt)") text(0,8.5,"r="+str(r)) text(0,8,"p="+str(p)) text(0,7.5,"s="+str(s)) text(0,6,"y=ute**(pt)+se**(vt)") text(0,5.5,"u="+str(u)) text(0,5,"p="+str(p)) text(0,4.5,"v="+str(v)) show()