Create a numerical methods calculator. You can choose; A programming language (J
ID: 3804856 • Letter: C
Question
Create a numerical methods calculator. You can choose; A programming language (Java. C++) if you choose to write code, your program should output the values of x, y, f(x, y) and so on at each stage Mathematical software (Matlab. Maple. Mathematica. or other mathematical software) 2. if you choose to use mathematical software, your program should output the values of and so on at each stage Your solution should be the following: Given the differential equation dy/dx = dy/x - y and initial condition y(6) = 0.8, approximate the value of y(7. 1) using Euler's Method, Improved Euler's Method, and Runge-Kutta. For each method, choose a step size that gives four correct digits following the decimal point How many steps are required to obtain this level of precision? The actual solution is y(7.1) = 3.700936.. Your solution must be able to carry out Euler's Method, Improved Euler's Method, and Runge-Kutta Your solution should display all the points (x, y) found along the way, not just the final point. Your solution should also display other values found while carrying out each method: a. Euler's Method: display the slope f(x, y) at each stage b. Improved Euler's: display the values of 1 at each stage c. Runge-Kutta: display the values of k_1, k_2, k_3, k_4 at each stage d. You can display other values as well, if you wish (for example, the intermediate y-value in the Improved Euler method that we refer to as). You should be able to relatively easily change the initial condition, step size, and target value. You should be able to relatively easily change the differential equation.Explanation / Answer
MATLAB :
% It calculates ODE using Runge-Kutta 4th order method
% Author Ido Schwartz
clc; % Clears the screen
clear all;
%% Runge kutta
h=0.1; % step size
x = 6:h:7.1; % Calculates upto y(3)
y = zeros(1,length(x));
y(1) = 0.8; % initial condition
F_xy = @(t,r) t*r/(t-r); % change the function as you desire
for i=1:(length(x)-1) % calculation loop
k_1 = F_xy(x(i),y(i))
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1)
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2))
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h % main equation
end
OUTPUT:
k_1 =
0.9231
k_2 =
0.9837
k_3 =
0.9878
y =
Columns 1 through 9
0.8000 0.8987 0 0 0 0 0 0 0
Columns 10 through 12
0 0 0
k_1 =
1.0539
k_2 =
1.1255
k_3 =
1.1305
y =
Columns 1 through 9
0.8000 0.8987 1.0116 0 0 0 0 0 0
Columns 10 through 12
0 0 0
k_1 =
1.2088
k_2 =
1.2940
k_3 =
1.3002
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 0 0 0 0 0
Columns 10 through 12
0 0 0
k_1 =
1.3940
k_2 =
1.4966
k_3 =
1.5044
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 0 0 0 0
Columns 10 through 12
0 0 0
k_1 =
1.6183
k_2 =
1.7437
k_3 =
1.7538
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 0 0 0
Columns 10 through 12
0 0 0
k_1 =
1.8943
k_2 =
2.0503
k_3 =
2.0638
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 1.6729 0 0
Columns 10 through 12
0 0 0
k_1 =
2.2409
k_2 =
2.4398
k_3 =
2.4584
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 1.6729 1.9183 0
Columns 10 through 12
0 0 0
k_1 =
2.6879
k_2 =
2.9498
k_3 =
2.9769
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 1.6729 1.9183 2.2155
Columns 10 through 12
0 0 0
k_1 =
3.2861
k_2 =
3.6467
k_3 =
3.6892
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 1.6729 1.9183 2.2155
Columns 10 through 12
2.5836 0 0
k_1 =
4.1301
k_2 =
4.6615
k_3 =
4.7362
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 1.6729 1.9183 2.2155
Columns 10 through 12
2.5836 3.0562 0
k_1 =
5.4245
k_2 =
6.3016
k_3 =
6.4607
y =
Columns 1 through 9
0.8000 0.8987 1.0116 1.1414 1.2917 1.4668 1.6729 1.9183 2.2155
Columns 10 through 12
2.5836 3.0562 3.7009
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.