0% found this document useful (0 votes)
15 views6 pages

RK 4 Graph

The document contains MATLAB code that implements the Runge-Kutta 4th order method to solve a system of differential equations defined by functions f1, f2, and f3. It initializes parameters and variables, performs iterations to compute values of V, Z, and G over a specified range, and outputs the results in a formatted table. Additionally, it includes code to plot graphs of V, Z, and G against the reciprocal of xi.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

RK 4 Graph

The document contains MATLAB code that implements the Runge-Kutta 4th order method to solve a system of differential equations defined by functions f1, f2, and f3. It initializes parameters and variables, performs iterations to compute values of V, Z, and G over a specified range, and outputs the results in a formatted table. Additionally, it includes code to plot graphs of V, Z, and G against the reciprocal of xi.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

alpha = 0.

717;
gamma = 1.4;

% Differential Equations
f1 = @(xi, V, G, Z) (3*Z*V-(V-alpha)*(V*(V-1)-(2*Z/gamma)*((alpha-1)/
(alpha*(V-alpha)))))/(-Z+(V-alpha)^2);

f2 = @(xi, V, G, Z) G*((V*(V - 1) - 3*V*(V - alpha)-(2*Z/gamma)*((alpha-1)/


alpha*(V-alpha))))/(-Z+(V-alpha)^2);
f3 = @(xi, V, G, Z) ((2*Z^2 / gamma)*(((alpha-1)/alpha*(V-
alpha) ) +gamma)+V*(V-1)*(gamma-1)*Z-2*Z*((V-alpha)^2)*(((alpha-1)/alpha*(V-
alpha))+1)-3*V*(V-alpha)*(gamma-1)*Z)/(-Z+(V-alpha)^2);
% Step size
h = 0.1;
xi_vals = 1:h:100;
N = length(xi_vals);

% Initial Conditions
V_vals = zeros(1, N);
Z_vals = zeros(1, N);
G_vals = zeros(1, N);

V_vals(1) = 0.6;
Z_vals(1) = 0.1;
G_vals(1) =6;

% RK4 Iteration
for i = 1:N-1
xi = xi_vals(i);
V = V_vals(i);
Z = Z_vals(i);
G = G_vals(i);

k1_V = h * f1(xi, V, G,
Z);

k1_G = h * f2(xi, V, G, Z);


k1_Z = h * f3(xi, V, G, Z);

k2_V = h * f1(xi + h/2, V + k1_V/2, G + k1_G/2, Z + k1_Z/2);


k2_G = h * f2(xi + h/2, V + k1_V/2, G + k1_G/2, Z + k1_Z/2);
k2_Z = h * f3(xi + h/2, V + k1_V/2, G + k1_G/2, Z + k1_Z/2);

k3_V = h * f1(xi + h/2, V + k2_V/2, G + k2_G/2, Z + k2_Z/2);


k3_G = h * f2(xi + h/2, V + k2_V/2, G + k2_G/2, Z + k2_Z/2);
k3_Z = h * f3(xi + h/2, V + k2_V/2, G + k2_G/2, Z + k2_Z/2);

k4_V = h * f1(xi + h, V + k3_V, G + k3_G, Z + k3_Z);

1
k4_G = h * f2(xi + h, V + k3_V, G + k3_G, Z + k3_Z);
k4_Z = h * f3(xi + h, V + k3_V, G + k3_G, Z + k3_Z);

V_vals(i+1) = V + (k1_V + 2*k2_V + 2*k3_V + k4_V)/6;


G_vals(i+1) = G + (k1_G + 2*k2_G + 2*k3_G + k4_G)/6;
Z_vals(i+1) = Z + (k1_Z + 2*k2_Z + 2*k3_Z + k4_Z)/6;
end

%Table
fprintf('\n%-6s %-10s %-10s %-10s\n', 'xi', 'V', 'Z', 'G');

xi V Z G

fprintf('------------------------------------------\n');

------------------------------------------

for i = 1:N
fprintf('%-6.2f %-10.4f %-10.4f %-10.4f\n', xi_vals(i), V_vals(i),
Z_vals(i), G_vals(i));
end

1.00 0.6000 0.1000 6.0000


1.10 0.5098 0.0795 5.7531
1.20 0.4346 0.0632 5.5562
1.30 0.3434 0.0572 7.6325
1.40 0.2828 0.0480 8.7673
1.50 0.2356 0.0393 9.6118
1.60 0.1976 0.0318 10.2836
1.70 0.1666 0.0255 10.8343
1.80 0.1409 0.0203 11.2932
1.90 0.1196 0.0161 11.6798
2.00 0.1018 0.0127 12.0078
2.10 0.0869 0.0100 12.2874
2.20 0.0743 0.0078 12.5268
2.30 0.0636 0.0061 12.7323
2.40 0.0546 0.0048 12.9090
2.50 0.0469 0.0037 13.0614
2.60 0.0404 0.0029 13.1928
2.70 0.0348 0.0023 13.3064
2.80 0.0300 0.0018 13.4047
2.90 0.0259 0.0014 13.4897
3.00 0.0224 0.0011 13.5634
3.10 0.0193 0.0008 13.6272
3.20 0.0167 0.0006 13.6826
3.30 0.0145 0.0005 13.7306
3.40 0.0125 0.0004 13.7723
3.50 0.0109 0.0003 13.8084
3.60 0.0094 0.0002 13.8398
3.70 0.0082 0.0002 13.8671
3.80 0.0071 0.0001 13.8907
3.90 0.0061 0.0001 13.9113
4.00 0.0053 0.0001 13.9292
4.10 0.0046 0.0001 13.9447
4.20 0.0040 0.0001 13.9582
4.30 0.0035 0.0000 13.9699
4.40 0.0030 0.0000 13.9801

2
94.10 0.0000 0.0000 14.0480
94.20 0.0000 0.0000 14.0480
94.30 0.0000 0.0000 14.0480
94.40 0.0000 0.0000 14.0480
94.50 0.0000 0.0000 14.0480
94.60 0.0000 0.0000 14.0480
94.70 0.0000 0.0000 14.0480
94.80 0.0000 0.0000 14.0480
94.90 0.0000 0.0000 14.0480
95.00 0.0000 0.0000 14.0480
95.10 0.0000 0.0000 14.0480
95.20 0.0000 0.0000 14.0480
95.30 0.0000 0.0000 14.0480
95.40 0.0000 0.0000 14.0480
95.50 0.0000 0.0000 14.0480
95.60 0.0000 0.0000 14.0480
95.70 0.0000 0.0000 14.0480
95.80 0.0000 0.0000 14.0480
95.90 0.0000 0.0000 14.0480
96.00 0.0000 0.0000 14.0480
96.10 0.0000 0.0000 14.0480
96.20 0.0000 0.0000 14.0480
96.30 0.0000 0.0000 14.0480
96.40 0.0000 0.0000 14.0480
96.50 0.0000 0.0000 14.0480
96.60 0.0000 0.0000 14.0480
96.70 0.0000 0.0000 14.0480
96.80 0.0000 0.0000 14.0480
96.90 0.0000 0.0000 14.0480
97.00 0.0000 0.0000 14.0480
97.10 0.0000 0.0000 14.0480
97.20 0.0000 0.0000 14.0480
97.30 0.0000 0.0000 14.0480
97.40 0.0000 0.0000 14.0480
97.50 0.0000 0.0000 14.0480
97.60 0.0000 0.0000 14.0480
97.70 0.0000 0.0000 14.0480
97.80 0.0000 0.0000 14.0480
97.90 0.0000 0.0000 14.0480
98.00 0.0000 0.0000 14.0480
98.10 0.0000 0.0000 14.0480
98.20 0.0000 0.0000 14.0480
98.30 0.0000 0.0000 14.0480
98.40 0.0000 0.0000 14.0480
98.50 0.0000 0.0000 14.0480
98.60 0.0000 0.0000 14.0480
98.70 0.0000 0.0000 14.0480
98.80 0.0000 0.0000 14.0480
98.90 0.0000 0.0000 14.0480
99.00 0.0000 0.0000 14.0480
99.10 0.0000 0.0000 14.0480
99.20 0.0000 0.0000 14.0480
99.30 0.0000 0.0000 14.0480
99.40 0.0000 0.0000 14.0480
99.50 0.0000 0.0000 14.0480
99.60 0.0000 0.0000 14.0480
99.70 0.0000 0.0000 14.0480
99.80 0.0000 0.0000 14.0480
99.90 0.0000 0.0000 14.0480
100.00 0.0000 0.0000 14.0480

% Plotting of Graphs

17
figure;
plot(1./xi_vals, V_vals, '-o', 'DisplayName', 'V');
xlabel('1/\xi');
ylabel('V-Values');
legend();
title('Graph of V vs 1/\xi');
grid on;

figure;

plot(1./xi_vals, Z_vals, '-s', 'DisplayName', 'Z');


xlabel('1/\xi');
ylabel('Z-Values');
legend();
title('Graph of Z vs 1/\xi ');
grid on;

18
figure;
plot(1./xi_vals, G_vals, '-d', 'DisplayName', 'G');
xlabel('1/\xi');
ylabel('G-Values');
legend();
title('Graph of G vs 1/\xi');
grid on;

19
20

You might also like