-1

My two first order differentials are as follows

y1' = -sin(y0) + (gamma)*cos(y0)sin(beta * x)

and

y0' = y1

where

(theta)'' = y, (theta)' = y1, theta = y0

My original equation was

(((d^2)*theta)/dt^2)=-sin(theta)+(gamma)cos(theta)sin(Bx)

How do I solve for theta as a function of time and plot from t=0 to t=40. The system starts at rest with theta = 0 and d(theta)/dt = 0.

darren
  • 47
  • 1
  • 9
  • 1
    This is confusing to read. Looks like you're solving a 2nd order ODE here using 4th order RK4. True? Can you edit the original ODE into the question? – duffymo Dec 07 '15 at 00:09
  • Yeah sure I will put it in now – darren Dec 07 '15 at 00:15
  • 1
    Still not clear. I expect to see one independent variable (time = t) and one dependent variable (theta). All others should be constants. What are those arguments for sine? What's that x? Are those really sine and cosine with theta as arguments? (If yes, this is a non-linear ODE.) – duffymo Dec 07 '15 at 00:36
  • the question is labeled as python yet the code segments are clearly not python. – Josep Valls Dec 07 '15 at 00:38
  • got edited into code to highlight the equations but the solution need to be done in python – darren Dec 07 '15 at 00:45
  • and yes the arguments are all as shown above – darren Dec 07 '15 at 00:45

1 Answers1

0

It seems like you are to simulate a forced physical pendulum with an oscillating external force.

theta''+sin(theta) = gamma * cos(theta)*sin(beta*t)

As you have correctly recognized, this needs to be translated into a system of order 1, and then packaged as a vector valued ODE func

def odefunc(t,y):
    y0, y1 = y
    return y1, -sin(y0)+gamma*cos(y0)*sin(beta*t)

if the constants are global variables, or as parameters

def odefunc(t,y,params):
    y0, y1 = y
    beta, gamma = params
    return y1, -sin(y0)+gamma*cos(y0)*sin(beta*t)

where you then have to employ lambda expressions to reduce the arguments to the standard format of the ODE integrator.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51