Matlab computer program for solving IVP with Runge kutta
==============================
% Runge Kutta 4 with h and ab [SCRIPT]
%
f=@(t,x) x^2*cos(x)-4*t*x; % differential equation
a=0; %interval
b=1;
x0=-0.5; % initial condition
h=0.01; % step size
t=a:h:b; % generating time vector
n=length(t); % storing length of vector t
x=[x0 zeros(1,n-1)]; % initializing vector x
for i=1:n-1
k1=h*f(t(i),x(i)); % fourth order runge kutta equations
k2=h*f(t(i)+0.5*h,x(i)+0.5*k1);
k3=h*f(t(i)+0.5*h,x(i)+0.5*k2);
k4=h*f(t(i)+h,x(i)+k3);
k=(1/6)*(k1+2*k2+2*k3+k4);
x(i+1)=x(i)+k;
end
% plot(t,x) %plotting result
[t' x'] % displaying results
=====================
Output data format:
[t x]
=============
0 -0.5000
0.0100 -0.4977
0.0200 -0.4952
0.0300 -0.4926
0.0400 -0.4898
0.0500 -0.4868
0.0600 -0.4837
0.0700 -0.4803
0.0800 -0.4769
0.0900 -0.4733
0.1000 -0.4695
0.1100 -0.4656
0.1200 -0.4615
0.1300 -0.4573
0.1400 -0.4530
0.1500 -0.4486
0.1600 -0.4440
0.1700 -0.4393
0.1800 -0.4345
0.1900 -0.4296
0.2000 -0.4246
0.2100 -0.4196
0.2200 -0.4144
0.2300 -0.4091
0.2400 -0.4038
0.2500 -0.3984
0.2600 -0.3929
0.2700 -0.3874
0.2800 -0.3818
0.2900 -0.3761
0.3000 -0.3704
0.3100 -0.3647
0.3200 -0.3589
0.3300 -0.3531
0.3400 -0.3472
0.3500 -0.3413
0.3600 -0.3355
0.3700 -0.3296
0.3800 -0.3237
0.3900 -0.3177
0.4000 -0.3118
0.4100 -0.3059
0.4200 -0.3000
0.4300 -0.2941
0.4400 -0.2882
0.4500 -0.2824
0.4600 -0.2765
0.4700 -0.2707
0.4800 -0.2649
0.4900 -0.2592
0.5000 -0.2535
0.5100 -0.2478
0.5200 -0.2422
0.5300 -0.2366
0.5400 -0.2311
0.5500 -0.2256
0.5600 -0.2202
0.5700 -0.2148
0.5800 -0.2095
0.5900 -0.2042
0.6000 -0.1990
0.6100 -0.1939
0.6200 -0.1888
0.6300 -0.1838
0.6400 -0.1789
0.6500 -0.1740
0.6600 -0.1692
0.6700 -0.1645
0.6800 -0.1599
0.6900 -0.1553
0.7000 -0.1508
0.7100 -0.1464
0.7200 -0.1421
0.7300 -0.1378
0.7400 -0.1337
0.7500 -0.1296
0.7600 -0.1256
0.7700 -0.1216
0.7800 -0.1178
0.7900 -0.1140
0.8000 -0.1103
0.8100 -0.1067
0.8200 -0.1032
0.8300 -0.0997
0.8400 -0.0963
0.8500 -0.0931
0.8600 -0.0898
0.8700 -0.0867
0.8800 -0.0837
0.8900 -0.0807
0.9000 -0.0778
0.9100 -0.0750
0.9200 -0.0722
0.9300 -0.0695
0.9400 -0.0669
0.9500 -0.0644
0.9600 -0.0620
0.9700 -0.0596
0.9800 -0.0573
0.9900 -0.0550
1.0000 -0.0529
Plot:
Problem: Write a computer program to implement the Fourth Order Runge-Kutta method to solve the differential...
2. a. Show that the fourth order Runge Kutta method, when applied to the differential equation y' - Ay, can be written in the form i.e. show that w+1 Q(hA)w, where (10) b. Show that the backward Euler method, when applied to the differential equation y'- Xy, can be written in the form (12) wi. i.e. show that w+1-Q(hA)w; where (13) 2. a. Show that the fourth order Runge Kutta method, when applied to the differential equation y' - Ay,...
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...
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)...
Ordinary Differential Equations (a) Write a Python function implementing the 4'th order Runge-Kutta method. (b) Solve the following amusing variation on a pendulum problem using your routine. A pendulum is suspended from a sliding collar as shown in the diagram below. The system is at rest when an oscillating motion y(t) = Y sin (omega t) is imposed on the collar, starting at t = 0. The differential equation that describes the pendulum motion is given by: d^2 theta/dt^2 =...
Use fourth-order Runge-Kutta method Using MATLAB Solve x - 2t = 0, (0)0,(0) = 0.1, [0, 3] by any convenient method. Graph the solution on Using MATLAB Solve x - 2t = 0, (0)0,(0) = 0.1, [0, 3] by any convenient method. Graph the solution on
(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...
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...
Implement the 4th order Runge-Kutta algotithm in MATLAB. Use the script you produced to integrate the following function x(t)--10t + e-t , x(0)--1; t.-0 t, = 1 Vary At and observe the difference in your results. Let At 0.2 sec., 0.1 sec., 0.05 sec. and 0.01 sec. Now integrate the function analytically and compare your result with the results obtained numerically Implement the 4th order Runge-Kutta algotithm in MATLAB. Use the script you produced to integrate the following function x(t)--10t...
Given (dy/dx)=(3x^3+6xy^2-x)/(2y) with y=0.707 at x= 0, h=0.1 obtain a solution by the fourth order Runge-Kutta method for a range x=0 to 0.5
Numerical Methods Consider the following IVP dy=0.01(70-y)(50-y), with y(0)-0 (a) [10 marks Use the Runge-Kutta method of order four to obtain an approximate solution to the ODE at the points t-0.5 and t1 with a step sizeh 0.5. b) [8 marks Find the exact solution analytically. (c) 7 marks] Use MATLAB to plot the graph of the true and approximate solutions in one figure over the interval [.201. Display graphically the true errors after each steps of calculations. Consider the...