Please write simple python code of y''+2y'-3y = 0, y(0) = 2, y'(0)=1 with modified euler method and 4th order Runge-Kutta Kutta method
'''
y'' + 2y' -3y = 0, y(0) = 2, y'(0)=1
let y' = z
giving 2 ODEs to solve simulteneously
z' + 2z - 3y = 0 and y' = z for y(0) = 2, z(0) = 1
assuming a step size h and time vector tmin<=t<=tmax
'''
import matplotlib.pyplot as plt1;import matplotlib.pyplot as plt2
# function to form and return the two 1st-order ODE simulteneous
equations
def f(y,z):
dydt = z;
dzdt = 3*y - 2*z;
return dydt,dzdt
# funcion to map the output of funtion f() to only y
def fy(y,z):
[dydt,dzdt] = f(y,z)
return dydt
# funcion to map the output of funtion f() to only z
def fz(y,z):
[dydt,dzdt] = f(y,z)
return dzdt
# setting the necessary constants
h = 0.1
tmin = 0; tmax = 1;
n = int((tmax-tmin)/h);
y0 = 2; z0 = 1;
# ---------- SOLVING THE ODEs SIMULTENEOUSLY --------
# modified euler
# setting initial conditions
t = [];y=[];z=[]
t.append(tmin);
y.append(y0);
z.append(z0);
for i in range(n):
'''
# ensure y arguments are always on the left, z arguments on the
right of either fy or fz
# the x or t components of modified euler method are left out since
they do not originally appear in the ODE
'''
ytemp = y[i] + (h/2)*( fy(y[i],z[i]) + fy( y[i]+ h*fy(y[i],z[i]),
z[i]+h*fz(y[i],z[i]) ))
ztemp = z[i] + (h/2)*( fz(y[i],z[i]) + fz( y[i]+ h*fy(y[i],z[i]),
z[i]+h*fz(y[i],z[i]) ))
# update the y and z vectors
y.append(ytemp)
z.append(ztemp)
# update the time vector
ttemp = t[i]+ h;
t.append(ttemp)
plt1.figure(1)
plt1.plot(t,y,'g-')
#plt1.plot(t,z,'r-')
plt1.xlabel('t');plt1.ylabel('y(t)'),plt1.title('Modified
Euler')
plt1.grid()
#------------------------------------------------------------------
# 4th order Runge-Kutta Kutta method
# setting initial conditions
y = [];z = []; t=[]
t.append(tmin);
y.append(y0);
z.append(z0);
for i in range(n):
'''
# the K's are identified with y or z for each cartegory
# ensure y arguments are always on the left, z arguments on the
right of either fy or fz
# the x or t components of 4th order Runge-Kutta Kutta method are
left out since they do not originally appear in the ODE
'''
yK1 = h*fy(y[i],z[i])
zK1 = h*fz(y[i],z[i])
yK2 = h*fy(y[i]+yK1/2,z[i]+zK1/2)
zK2 = h*fz(y[i]+yK1/2,z[i]+zK1/2)
yK3 = h*fy(y[i]+yK2/2, z[i]+zK2/2)
zK3 = h*fz(y[i]+yK2/2, z[i]+zK2/2)
yK4 = h*fy(y[i]+yK3,z[i]+zK3)
zK4 = h*fz(y[i]+yK3,z[i]+zK3)
ytemp = y[i] + yK1/6 + yK2/3 + yK3/3 + yK4/6
ztemp = z[i] + zK1/6 + zK2/3 + zK3/3 + zK4/6
# update the y and z vectors
y.append(ytemp)
z.append(ztemp)
# update the time vector
ttemp = t[i]+ h;
t.append(ttemp)
plt2.figure(2)
plt2.plot(t,y,'g-')
#plt2.plot(t,z,'r-')
plt2.xlabel('t');plt2.ylabel('y(t)'),plt2.title('4th order
Runge-Kutta Kutta')
plt2.grid()
plt1.show();plt2.show()
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~
Please write simple python code of y''+2y'-3y = 0, y(0) = 2, y'(0)=1 with modified euler...
answer fast please
2. For y'=(1+4x)/7, and y(0)=0.5 a) Use the Euler method to integrate from x=0 to 0.5 with h=0.25. (10 pts) b) Use the 4th order Runge-Kutta method to numerically integrate the equation above for x=0 to 0.25 with h=0.25. (15 pts) Euler Method 91+1 = y + oh where $ = = f(ty 4th Order Runge-Kutta Method 2+1= ++ where $ = (ką + 2k2 + 2kg + ks) ky = f(tuy) k2 = f(t+1,91 +{kxh) kz...
Help with these questions please.
A mathematical model has been described by an engineer into the following differential equation: dy dx y(0) 2.5 Demonstrate an Euler method simulation of y versus x with a tabular algorithm using Ax 0.5 and 0.0 X 3.0. Demonstrate a 4th-order Runge Kutta method simulation of y versus x with a tabular algorithm using What can you say about y(x) and the methods used? a. b. Ax 0.5 and 0.0 3.0 x c.
A mathematical...
9) Using Euler method, solve this with following initial conditions that t = 0 when y = 1, for the range t = 0 to t = 1 with intervals of 0.25 dr + 2x2 +1=0.3 dt 1o) Using second order Taylor Series method, solve with following initial conditions to-0, xo-1 and h-0.24 11) x(1)-2 h-0.02 Solve the following system to find x(1.06) using 2nd, and 3rd and 4th order Runge-Kutta (RK2, RK3 and RK4)method +2x 2 +1-0.3 de sx)-cox(x/2)...
Assignment 2 Q.1 Find the numerical solution of system of differential equation y" =t+2y + y', y(0)=0, at x = 0.2 and step length h=0.2 by Modified Euler method y'0)=1 Q.2. Write the formula of the PDE Uxx + 3y = x + 4 by finite difference Method . Q.3. Solve the initial value problem by Runga - Kutta method (order 4): y" + y' – 6y = sinx ; y(0) = 1 ; y'(0) = 0 at x =...
Hey
Can someone write me a c++ pogramm using 4th order runge kutta
method? h=0.1
y' = 3y, y(0) = 1
The differential equation : dy/dx = 2x -3y , has the initial conditions that y = 2 , at x = 0 Obtain a numerical solution for the differential equation, correct to 6 decimal place , using , The Euler-Cauchy method The Runge-Kutta method in the range x = 0 (0.2) 1.0
MATLAB HELP 3. Consider the equation y′ = y2 − 3x, where y(0) =
1. USE THE EULER AND RUNGE-KUTTA APPROXIMATION SCRIPTS
PROVIDED IN THE PICTURES
a. Use a Euler approximation with a step size of 0.25 to
approximate y(2).
b. Use a Runge-Kutta approximation with a step size of 0.25 to
approximate y(2).
c. Graph both approximation functions in the same window as a
slope field for the differential equation.
d. Find a formula for the actual solution (not...
2. The explicit Euler and 4th order Runge-Kutta schemes for solving the following ordinary differential equation do f(6 dt are given by Atf() and 1 At (ki k2 k ka + ( ) k2=f( + At- k2 ka f At 2 respectively (a) Perform stability analysis on the model problem do _ dt for BOTH the explicit Euler and 4th order Runge-Kutta schemes and show that the respective stability regions are given by (Euler) AAt 4 (AAt)2 2 (AAt)3 (AAt)4...
ME 32200 Programming course (MATLAB)
4. Please finish the following Matlab code for solving the ODE: dy = y(1+1) dt I.C. y(0) = 0 with the multi-step 4th order Milne's Method, and apply 4th order Runge Kutta method to the first 4 points (1 boundary point and the next 3 points). (Hint: 4th order Milne's Method Predictor: 7i+ = Y-3 +h(2f;- fi- +25,-2) Corrector: y = y + + +0. +45j + fi-) Where f; = f(t;,y,) and Fit =...
1 st s2, y(1)1 The exact solution is given by yo) - = . 1+Int Write a MATLAB code to approximate the solution of the IVP using Midpoint (RK2) and Modified Euler methods when h [0.5 0.1 0.0s 0.01 0.005 0.001]. A) Find the vector w mid and w mod that approximates the solution of the IVP for different values of h. B) Plot the step-size h versus the relative error of both in the same figure using the LOGLOG...