As we showed, the horizontal displacements ξi of masses i = 1 . . . N satisfy equations of mo- tion md2ξ1 =k(ξ2−ξ1)+F1, dt2 md2ξi =k(ξi+1−ξi)+k(ξi−1−ξi)+Fi, dt2 md2ξN =k(ξN−1−ξN)+FN. dt2 where m is the mass, k is the spring constant, and Fi is the external force on mass i. In Exam- ple 6.2 we showed how these equations could be solved by guessing a form for the solution and using a matrix method. Here we'll solve them more directly. a) Write a python program to solve for the motion of the masses using the fourth-order Runge- Kutta method for the case we studied previously where m = 1 and k = 6, and the driving forces are all zero except for F1 = cos ωt with ω = 2. Plot your solutions for the displace- mentsξi ofallthemassesasafunctionoftimefromt=0tot=20onthesameplot. Write your program to work with general N, but test it out for small values—N = 5 is a reasonable choice. You will need first of all to convert the N second-order equations of motion into 2N first- order equations. Then combine all of the dependent variables in those equations into a single large vector r to which you can apply the Runge-Kutta method in the standard fashion. This is what I have so far. I do not need the graph I just can not figure out how to do f(r, t) (it must be f(r, t) to create an array where we convert the N-second order equation into 2N and then combining the dependent variables.
As we showed, the horizontal displacements ξi of masses i = 1 . . . N satisfy equations of mo- tion
md2ξ1 =k(ξ2−ξ1)+F1, dt2
md2ξi =k(ξi+1−ξi)+k(ξi−1−ξi)+Fi, dt2
md2ξN =k(ξN−1−ξN)+FN. dt2
where m is the mass, k is the spring constant, and Fi is the external force on mass i. In Exam- ple 6.2 we showed how these equations could be solved by guessing a form for the solution and using a matrix method. Here we'll solve them more directly.
a) Write a python program to solve for the motion of the masses using the fourth-order Runge- Kutta method for the case we studied previously where m = 1 and k = 6, and the driving forces are all zero except for F1 = cos ωt with ω = 2. Plot your solutions for the displace- mentsξi ofallthemassesasafunctionoftimefromt=0tot=20onthesameplot. Write your program to work with general N, but test it out for small values—N = 5 is a reasonable choice.
You will need first of all to convert the N second-order equations of motion into 2N first- order equations. Then combine all of the dependent variables in those equations into a single large
This is what I have so far. I do not need the graph I just can not figure out how to do f(r, t) (it must be f(r, t) to create an array where we convert the N-second order equation into 2N and then combining the dependent variables.
![# Question 5
# Exercise 8.9
# Part A
# = k(E2-E1)*t + f1*t
# = k(Eiplus1-Ei)*t + k(Eiminus1-Ei)*t + fi*t
# = k(ENminus1-EN)*t + fn
k*(Eiplus1
import numpy as np
# =
Ei)*t + k*(ENminus1-EN)
m = 1
k = 6
omega = 2
F = np.cos(omega*t)
t_0 = 0
t_max = 20
N = 20000
(t_max-t_0)/N
n = 5
h =
def f(r, t):
one = r[0]
two = r[1]
three = r[2]
four = r[3]
# The 4th-order Runge-Kutta method
ro is a vector for the initial conditions
def rk4(func, r0, time):
r = np. zeros((np. size(time), np.size(r0)))
r[0,:] = r0
#3
# here we want to know both the index and the actual time for each time step
# and thus the enumerate function is called
for i, t in enumerate(time[0:-1]):
dt = time [i+1]
dt2 = dt/2.0
- time[i]
k1 = func (r[i,:], t)
func (r[i,:] + k1*dt2, t + dt2)
k3 = func (r[i,:] + k2*dt2, t + dt2)
k4 = func(r[i,:] + k3*dt, t + dt)
r[i+1,:] = r[i,:] + dt/6.0*(k1 + 2.0*k2 + 2.0*k3 + k4)
k2 =
return r](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9b1b483a-fbb9-4e01-adc3-918d57c456ae%2F6195354b-acd4-459f-98ab-1748d62f6fd0%2F1thwhq_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









