a) answer
def
RK4(f):
return lambda t, y,
dt: (
lambda dy1: (
lambda dy2: (
lambda dy3: (
lambda dy4: (dy1 +
2*dy2 + 2*dy3 +
dy4)/6
)( dt * f( t + dt , y + dy3
) )
)( dt * f( t +
dt/2, y + dy2/2
) )
)( dt * f( t +
dt/2, y + dy1/2
) )
)( dt * f(
t ,
y )
)
def theory(t):
return (t**2 +
4)**2
/16
from math import
sqrt
dy = RK4(lambda t, y:
t*sqrt(y))
t, y, dt = 0., 1.,
.1
while t <= 10:
if
abs(round(t)
- t) < 1e-5:
print("y(%2.1f)\t= %4.6f \t
error: %4.6g" % ( t, y,
abs(y -
theory(t))))
t, y = t + dt, y + dy( t, y, dt
)
output:
y(0.0) = 1.000000 error: 0
y(1.0) = 1.562500 error: 1.45722e-07
y(2.0) = 3.999999 error: 9.19479e-07
y(3.0) = 10.562497 error: 2.90956e-06
y(4.0) = 24.999994 error: 6.23491e-06
y(5.0) = 52.562489 error: 1.08197e-05
y(6.0) = 99.999983 error: 1.65946e-05
y(7.0) = 175.562476 error: 2.35177e-05
y(8.0) = 288.999968 error: 3.15652e-05
y(9.0) = 451.562459 error: 4.07232e-05
Ordinary Differential Equations (a) Write a Python function implementing the 4'th order Runge-Kutta method. (b) Solve...
Problem: Write a computer program to implement the Fourth Order Runge-Kutta method to solve the differential equation x=x2 (1) cos(x(1))-4fx(t), x(0)=-0.5 Use h-0.01. Evaluate and print a table of the solution over the interval [O, 1 x(t) 0
Use the Runge Kutta 4th Order (RK-4) Method on the function below to predict the value of y(0.1), given t = 0, y(0)-2, and h-01. Report your answer to 3 decimal places. dy/dt = e + 3y Answer: Use the Runge-Kutta 4th Order (RK-4) Method on the function below to predict the value of y(0.2), given y(0.1) from the previous question, and h = 0.1. Report your answer to 3 decimal places. -t dy/dt -e +3y Answer
Solve the ordinary differential equation below over the interval 0 sts 2s using two different methods: the Euler method and the second-order Runge-Kutta method (midpoint version). Begin by writing the state space representation of the equation. Use a time step of 1 s, and place a box around the values of x and x at t- 2 s obtained using each method. Show your work. 20d's +5dr +20x = 0 dt d x(0) = 1, x'(0) = 1 Solve the...
(3) Consider the expressions (a) Write down the Runge-Kutta method for the numerical solution to a differential equation Oy (b) Show that if f is independent of y, i.e. f(x, y) g(x) for some g, then the Runge-Kutta method on the interval n n + h] becomes Simpson's Rule for the numerical approximation of the integral g(x) dr. In this case, what is the global error, in terms of O(hk) for some k>0? (3) Consider the expressions (a) Write down...
IMPORTANT NOTES: Using the Classical Fouth-order Runge-Kutta method to solve all the following problems, with step size h = 0.01, and t = [0:1] Please use MATLAB to solve the problem. Thanks! 1. Consider the equation of motion governing large deflections of a simple pendulum do + mulsin Mu. ED) where m-mass of the bob - Ikg. I-length, c-damping constant, acceleration due to gravity, MO external torque, e - angular deflection, and t-time. MO) (a) Linearize the equation for small...
im having trouble doing this problem with matlab code and we can not use ode45 in our code unfortunitely. thank you! T L =undeformed length k =stiffness om The mass m is suspended from an elastic cord with an extensional stiffness k and undeformed length L. If the mass is released from rest at 0 = 60° with the cord unstretched, find the length r of the cord when the position =0 is reached for the first time. The differential...
Solve Example 6.2 on page 111 of textbook, using (1) the 4th order Runge Kutta method and (2) Simulink method, respectively. Please submit your MATLAB code m file and slx file You can use the results from the code attached below (from the textbook by ODE45 solver) as a reference Example 6.2 ode45 ex.m % This program solves a system of 3 differential equations % by using ode45 function % y1 (0)=0, y2 (0)=1.0, y3 (0)=1.0 clear; clc initial [0.0...
Need help with this MATLAB problem: Using the fourth order Runge-Kutta method (KK4 to solve a first order initial value problem NOTE: This assignment is to be completed using MATLAB, and your final results including the corresponding M- iles shonma ac Given the first order initial value problem with h-time step size (i.e. ti = to + ih), then the following formula computes an approximate solution to (): i vit), where y(ti) - true value (ezact solution), (t)-f(t, v), vto)...
use matlab Assignment: 1) Write a function program that implements the 4th Order Runge Kutta Method. The program must plot each of the k values for each iteration (one plot per k value), and the approximated solution (approximated solution curve). Use the subplot command. There should be a total of five plots. If a function program found on the internet was used, then please cite the source. Show the original program and then show the program after any modifications. Submission...
Find an approximate solution to the pendulum problem such that d2 theta /dt2 +g/l theta = 0. Use an approximate solver in matlab to find the solution to the exact equation d2 theta/dt2 +g/l * sin( theta) = 0. Compare the two solutions when the initial angle is 10, 30, and 90. Find a way to quantify the difference. One approximate method for solving differential equations is Runge-Kutta, which in Matlab goes by the name ode45. I have made a...