Python Forum
Need Help solving second order differential equations
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help solving second order differential equations
#1
So I have been working on a code to solve a coupled system of second order differential equations, in order to obtain the numerical solution of an elastic-pendulum. I've written the code needed to get the results and plot them, but I keep getting the following error: "TypeError: <lambda>() missing 1 required positional argument: 'd'". I really appreciate any help. Here's the code:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import math

ci = [0.01, 0., 0., 0.0156613949, 0.00237, 0.]


def solver(t, pinit):
    return odeint(lambda a,b,d : [a[1], -4*math.pi*math.pi*a[0]*(math.sqrt(a[0]*a[0]+b[0]*b[0]+d[0]*d[0])- 3/4)/math.sqrt(a[0]*a[0]+b[0]*b[0]+d[0]*d[0]),b[1], -4*math.pi*math.pi*b[0]*((a[0]**(2)+b[0]**(2)+d[0]**(2))**(1/2) - 3/4)/(a[0]**(2)+b[0]**(2)+d[0]**(2))**(1/2), d[1],-4*math.pi*math.pi*d[0]*(math.sqrt(a[0]**(2)+b[0]**(2)+d[0]**(2)) - 3/4)/math.sqrt(a[0]**(2)+b[0]**(2)+d[0]**(2)) - math.pi*math.pi], pinit, t)


time = np.arange(0, 500.0, 0.01)
solution = solver(time, ci)
plt.plot(solution[:,0], solution[:,2])
plt.show()
Reply


Messages In This Thread
Need Help solving second order differential equations - by SkewedZone - Jun-25-2019, 03:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  plot differential equation sympy dan_adi 0 2,990 Oct-13-2020, 10:44 AM
Last Post: dan_adi
  construction of Neural Network for solving Differential equations arshad 0 1,617 Jun-04-2020, 09:20 AM
Last Post: arshad
  Fitting experimental data with differential equations : Optimization madoko 6 6,849 Jan-17-2019, 11:30 AM
Last Post: scidam
  Solving nth degree simultaneous equations hegdep 3 3,662 Sep-28-2017, 08:33 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020