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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

As we showed, the horizontal displacements ξi of masses = 1 . . . 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 is the mass, 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 = 1 and = 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—= 5 is a reasonable choice.

You will need first of all to convert the second-order equations of motion into 2first- order equations. Then combine all of the dependent variables in those equations into a single large vector 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.

# 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
Transcribed Image Text:# 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY