[go: up one dir, main page]

0% found this document useful (0 votes)
16 views5 pages

Graph 2

The document contains MATLAB code for solving a system of differential equations using the Runge-Kutta method (RK4). It initializes parameters and conditions, iteratively computes values for variables V, Z, and G, and outputs the results in a formatted table. Additionally, it includes plotting commands to visualize the relationships of V, Z, and G against 1/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)
16 views5 pages

Graph 2

The document contains MATLAB code for solving a system of differential equations using the Runge-Kutta method (RK4). It initializes parameters and conditions, iteratively computes values for variables V, Z, and G, and outputs the results in a formatted table. Additionally, it includes plotting commands to visualize the relationships of V, Z, and G against 1/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/ 5

alpha = 0.

6381;
gamma =3;

% 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.32;
Z_vals(1) = 0.3;
G_vals(1) =2;

% 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.3200 0.3000 2.0000


1.10 0.2777 0.2148 1.9071
1.20 0.2659 0.1128 1.5766
1.30 0.1866 0.1317 1.9268
1.40 0.1360 0.1181 2.0718
1.50 0.1010 0.0980 2.1486
1.60 0.0757 0.0788 2.1959
1.70 0.0571 0.0622 2.2274
1.80 0.0432 0.0486 2.2492
1.90 0.0327 0.0377 2.2648
2.00 0.0249 0.0291 2.2761
2.10 0.0189 0.0223 2.2845
2.20 0.0144 0.0171 2.2907
2.30 0.0110 0.0131 2.2953
2.40 0.0083 0.0100 2.2988
2.50 0.0064 0.0077 2.3015
2.60 0.0049 0.0059 2.3035
2.70 0.0037 0.0045 2.3050
2.80 0.0028 0.0034 2.3062
2.90 0.0022 0.0026 2.3071
3.00 0.0017 0.0020 2.3077
3.10 0.0013 0.0015 2.3083
3.20 0.0010 0.0011 2.3087
3.30 0.0007 0.0009 2.3090
3.40 0.0006 0.0007 2.3092
3.50 0.0004 0.0005 2.3094
3.60 0.0003 0.0004 2.3095
3.70 0.0003 0.0003 2.3096
3.80 0.0002 0.0002 2.3097
3.90 0.0002 0.0002 2.3098
4.00 0.0001 0.0001 2.3098
4.10 0.0001 0.0001 2.3098
4.20 0.0001 0.0001 2.3099
4.30 0.0001 0.0001 2.3099
4.40 0.0000 0.0000 2.3099

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

% 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

You might also like