Question

In: Computer Science

Prompt: Produce a 4th order Runge Kutta code in PYTHON that evaluates the following second order...

Prompt: Produce a 4th order Runge Kutta code in PYTHON that evaluates the following second order ode with the given initial conditions, (d^2y/dt^2) +4(dy/dt)+2y=0, y(0)=1 and y'(0)=3. After your code can evaluate the 2nd order ode, add a final command to plot your results. You may only use python.

Solutions

Expert Solution

import numpy as np
import matplotlib.pyplot as plt
def ode(y):
return np.array([y[1],(-2*y[0]-4*y[1])])

tStart=0
tEnd=5
h=.1
t=np.arange(tStart,tEnd+h,h)
y=np.zeros((len(t),2))
y[0,:]=[1,3]

for i in range(1,len(t)):
k1=ode(y[i-1,:])
k2=ode(y[i-1,:]+h*k1/2)
k3=ode(y[i-1,:]+h*k2/2)
k4=ode(y[i-1,:]+h*k3)
y[i,:]=y[i-1,:]+(h/6)*(k1+2*k3+2*k3+k4)
plt.plot(t,y)
plt.grid()
plt.gca().legend(('y(t)',"y'(t)"))
plt.show()


Related Solutions

use Runge Kutta 4th order method y'=y-1.3333*exp(0.6x) a) h=2.5 and compare the value to the exact...
use Runge Kutta 4th order method y'=y-1.3333*exp(0.6x) a) h=2.5 and compare the value to the exact value b) h=1.25 and compare the value to the exact value Thks!
Use 3 steps of the Runge-Kutta (fourth order) method to solve the following differential equation to...
Use 3 steps of the Runge-Kutta (fourth order) method to solve the following differential equation to t = 2.4, given that y(0) = 2.3. In your working section, you must provide full working for the first step. To make calculations easier, round the tabulated value of y at each step to four decimal places. a) Provide the four K-values that are calculated at the first step, with four decimal places. b) Provide your answer for y(2.4) with four decimal places....
Problem Four (12 Marks) Use Runge Kutta method of order four to approximate the solution of...
Problem Four Use Runge Kutta method of order four to approximate the solution of the initial value problem ?′ + 2? = ??3?, 0 ≤ ? ≤ 1, ?(0) = 0, ???ℎ ℎ = 0.5 Hint: Compute ?(0.5) ??? ?(1)
Please make a little adjust for the following script then make it work for Runge Kutta...
Please make a little adjust for the following script then make it work for Runge Kutta method Consider the initial value problem du/dt=t^5   u(0)=0 0<=t<=1 Q1. how we change the below script to make it to solve the above IVP and the answer should be near 4 here is the script f =@(t ,y)(t^5); % define f by f(t,y)=y^5 for k =1:10 [ tlist , ylist ]= RKfour174 (f ,0 ,1 ,0, 2^k); error1 (k)= max ( abs ( ylist...
Q 4. With the aid of fourth order Runge-Kutta method, solve the competing species model [20...
Q 4. With the aid of fourth order Runge-Kutta method, solve the competing species model [20 points] defined by dx =x(2 − 0.4x − 0.3y), x(0) = 4 dt dy =y(1 − 0.1y − 0.3x), y(0) = 3 dt where the populations x(t) and y(t) are measured in thousands and t in years. Use a step size of 0.2 for 0 ≤ t ≤ 2 and plot the trajectories of the populations with Matlab or GNU Octave.
With the aid of fourth order Runge-Kutta method, solve the competing species model defined by dx/dt...
With the aid of fourth order Runge-Kutta method, solve the competing species model defined by dx/dt =x(2 − 0.4x − 0.3y), x(0) = 2 dy/dt =y(1 − 0.1y − 0.3x), y(0) = 4 where the populations x(t) and y(t) are measured in thousands and t in years. Use a step size of 0.2 for 0 ≤ t ≤ 2 and plot the trajectories of the populations with Matlab or GNU Octave.
Using Runge-Kutta method of order 4 to approximate y(1) with step size h = 0.1 and...
Using Runge-Kutta method of order 4 to approximate y(1) with step size h = 0.1 and h = 0.2 respectively (keep 8 decimals): dy/dx = x + arctan y, y(0) = 0. Solutions: when h = 0.1, y(1) = 0.70398191. when h = 0.2, y(1) = 0.70394257.
Request to solve the second order differential equation by range Range kutta 4th order method 8d^2y/dx^2-x^2+2y^2=0...
Request to solve the second order differential equation by range Range kutta 4th order method 8d^2y/dx^2-x^2+2y^2=0 with initial conditions y(0)=1 and dy/dx(0)=0 compute y at 1 (Numerical Method)
Write a user-defined MATLAB function that uses classical fourth order Runge-Kutta method to solve a first...
Write a user-defined MATLAB function that uses classical fourth order Runge-Kutta method to solve a first order ODE problem dydx = f(x, y) in a given interval a ? x ? b with initial condition y(a) = y0 and step size of h. For function name and arguments, use [x,y] = myrk4(f, a, b, h, y0) Check your function to find the numerical solution for dydx=?1.2y+7e^(?0.3x) in the interval 0 ? x ? 4 with initial condition y(0)=3. Run your...
1)Select all that applies to the Fourth-order Runge-Kutta (RK4) method K subscript 1 equals f left...
1)Select all that applies to the Fourth-order Runge-Kutta (RK4) method K subscript 1 equals f left parenthesis t subscript k comma y subscript k right parenthesis K subscript 2 equals f left parenthesis t subscript k plus h over 2 comma space y subscript k plus h over 2 space K subscript 1 right parenthesis K subscript 3 equals f left parenthesis t subscript k plus h over 2 comma space y subscript k plus h over 2 space K...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT