using matlab solve numerically dy/dt = sin t, y(0)=0 for 0<=t<=4π
the exact solution is y(t) = 1 - cos t. Compare the exact and numerical solution.
MATLAB CODE
% NUMERICAL METHOD : Runge-Kutta 4th order method
clear all
format short
clc;
f=@(t,y)sin(t); % y'=f(t,y)
y(1)=0; % index has been taken as i instead of 0
h=0.1;
a=0;b=4*pi; % Range of t a<=t<=b
t=a:h:b;
N=(b-a)/h;
for n=1:(length(t)-1)
k1 = h*f(t(n),y(n));
k2 = h*f(t(n)+0.5*h,y(n)+0.5*k1);
k3 = h*f((t(n)+0.5*h),(y(n)+0.5*k2));
k4 = h*f((t(n)+h),(y(n)+k3));
y(n+1) = y(n) + (1/6)*(k1+2*k2+2*k3+k4) ;
end
T=t;
y'; % displays all y values
%%% Exact Solution
k=1;
for t = 0:0.1:4*pi;
y_e=1-cos(t);
yext(k)=y_e;
k=k+1;
end
yext';
Comparison_t_y_ext=[T' y' yext']
Comparison_t_y_ext =
0 0 0
0.1000 0.0050 0.0050
0.2000 0.0199 0.0199
0.3000 0.0447 0.0447
0.4000 0.0789 0.0789
0.5000 0.1224 0.1224
0.6000 0.1747 0.1747
0.7000 0.2352 0.2352
0.8000 0.3033 0.3033
0.9000 0.3784 0.3784
1.0000 0.4597 0.4597
1.1000 0.5464 0.5464
1.2000 0.6376 0.6376
1.3000 0.7325 0.7325
1.4000 0.8300 0.8300
1.5000 0.9293 0.9293
1.6000 1.0292 1.0292
1.7000 1.1288 1.1288
1.8000 1.2272 1.2272
1.9000 1.3233 1.3233
2.0000 1.4161 1.4161
2.1000 1.5048 1.5048
2.2000 1.5885 1.5885
2.3000 1.6663 1.6663
2.4000 1.7374 1.7374
2.5000 1.8011 1.8011
2.6000 1.8569 1.8569
2.7000 1.9041 1.9041
2.8000 1.9422 1.9422
2.9000 1.9710 1.9710
3.0000 1.9900 1.9900
3.1000 1.9991 1.9991
3.2000 1.9983 1.9983
3.3000 1.9875 1.9875
3.4000 1.9668 1.9668
3.5000 1.9365 1.9365
3.6000 1.8968 1.8968
3.7000 1.8481 1.8481
3.8000 1.7910 1.7910
3.9000 1.7259 1.7259
4.0000 1.6536 1.6536
4.1000 1.5748 1.5748
4.2000 1.4903 1.4903
4.3000 1.4008 1.4008
4.4000 1.3073 1.3073
4.5000 1.2108 1.2108
4.6000 1.1122 1.1122
4.7000 1.0124 1.0124
4.8000 0.9125 0.9125
4.9000 0.8135 0.8135
5.0000 0.7163 0.7163
5.1000 0.6220 0.6220
5.2000 0.5315 0.5315
5.3000 0.4456 0.4456
5.4000 0.3653 0.3653
5.5000 0.2913 0.2913
5.6000 0.2244 0.2244
5.7000 0.1653 0.1653
5.8000 0.1145 0.1145
5.9000 0.0725 0.0725
6.0000 0.0398 0.0398
6.1000 0.0167 0.0167
6.2000 0.0035 0.0035
6.3000 0.0001 0.0001
6.4000 0.0068 0.0068
6.5000 0.0234 0.0234
6.6000 0.0498 0.0498
6.7000 0.0856 0.0856
6.8000 0.1306 0.1306
6.9000 0.1843 0.1843
7.0000 0.2461 0.2461
7.1000 0.3155 0.3155
7.2000 0.3916 0.3916
7.3000 0.4739 0.4739
7.4000 0.5615 0.5615
7.5000 0.6534 0.6534
7.6000 0.7487 0.7487
7.7000 0.8466 0.8466
7.8000 0.9460 0.9460
7.9000 1.0460 1.0460
8.0000 1.1455 1.1455
8.1000 1.2435 1.2435
8.2000 1.3392 1.3392
8.3000 1.4314 1.4314
8.4000 1.5193 1.5193
8.5000 1.6020 1.6020
8.6000 1.6787 1.6787
8.7000 1.7486 1.7486
8.8000 1.8111 1.8111
8.9000 1.8654 1.8654
9.0000 1.9111 1.9111
9.1000 1.9477 1.9477
9.2000 1.9748 1.9748
9.3000 1.9922 1.9922
9.4000 1.9997 1.9997
9.5000 1.9972 1.9972
9.6000 1.9847 1.9847
9.7000 1.9624 1.9624
9.8000 1.9304 1.9304
9.9000 1.8892 1.8892
10.0000 1.8391 1.8391
10.1000 1.7806 1.7806
10.2000 1.7143 1.7143
10.3000 1.6408 1.6408
10.4000 1.5610 1.5610
10.5000 1.4755 1.4755
10.6000 1.3853 1.3853
10.7000 1.2913 1.2913
10.8000 1.1943 1.1943
10.9000 1.0954 1.0954
11.0000 0.9956 0.9956
11.1000 0.8958 0.8958
11.2000 0.7970 0.7970
11.3000 0.7003 0.7003
11.4000 0.6065 0.6065
11.5000 0.5167 0.5167
11.6000 0.4317 0.4317
11.7000 0.3524 0.3524
11.8000 0.2796 0.2796
11.9000 0.2139 0.2139
12.0000 0.1561 0.1561
12.1000 0.1068 0.1068
12.2000 0.0664 0.0664
12.3000 0.0353 0.0353
12.4000 0.0138 0.0138
12.5000 0.0022 0.0022
Using matlab solve numerically dy/dt = sin t, y(0)=0 for 0<=t<=4π the exact solution is y(t...
Use a MATLAB built-in solver to numerically solve: dy/dx = -yx^2 + 1.5y for 0 lessthanorequalto x lessthanorequalto 3 with y(0) = 2 Make a plot of the numerical solution as a solid red line and the exact solution as green circles as shown. The exact solution is y = 2e^-(2x63 - 9x)/6 Use a MATLAB built-in function to numerically calculate the area of the solution. Use the text command to plot the area with 2-digits of precision as shown.
4. * Using your calculations from 3., plot the exact solution to dy = 1-y, dt y(0) = 1/2, for 0 <ts1, along with the numerical solution given by Euler's method and the trapezoid method, both with stepsize h = 0.1. Give the approximation of y(t = 1) for each numerical method. To distinguish your solutions: (i) Plot the Euler solution using crosses; do not join them with line segments. (ii) Plot the trapezoid solution using squares; again do not...
Matlab Code for these please. 4. Using inbuilt function in MATLAB, solve the differential equations: dx --t2 dt subject to the condition (01 integrated from0 tot 2. Compare the obtained numerical solution with exact solution 5. Lotka-Volterra predator prey model in the form of system of differential equations is as follows: dry dt dy dt where r denotes the number of prey, y refer to the number of predators, a defines the growth rate of prey population, B defines the...
only using matlab Osts 10 Problem 3 Numerically integrate the 2nd order linear differential equation on the interval y(t) = 2e" - 2e-41 and compare it to the solution a) Plot the numerical solution and the true solution for y(t) (20 pts) b) Plot the numerical solution and the true solution for dy/dt (10 pts)
Use the Laplace transform to solve dy cost + So y(t) cos(t – t)dt, y(0) = 1 dt
solve it with matlab 25.24 Given the initial conditions, y(0) = 1 and y'(0) = 1 and y'(0) = 0, solve the following initial-value problem from t = 0 to 4: dy + 4y = 0 dt² Obtain your solutions with (a) Euler's method and (b) the fourth- order RK method. In both cases, use a step size of 0.125. Plot both solutions on the same graph along with the exact solution y = cos 2t.
Please solve this problem by hand calculation. Thanks Consider the following system of two ODES: dx = x-yt dt dy = t+ y from t=0 to t = 1.2 with x(0) = 1, and y(0) = 1 dt (a) Solve with Euler's explicit method using h = 0.4 (b) Solve with the classical fourth-order Runge-Kutta method using h = 0.4. The a solution of the system is x = 4et- 12et- t2 - 3t - 3, y= 2et- t-1. In...
Solve the initial value problem. (6+av+x]dx + (8yx? + sin y) dy = 0, y(t) == The solution is (Type an equation using x and y as the variables. Type an implicit solution. Type an exact answer in terms of t.)
solve the following using laplace transform dy dt 3y(t) = e4t; y(0) = 0
Solve the following IVPs using Laplace Transform: 1) dy dt 3y(t) = e4t; y(0) = 0