0% found this document useful (0 votes)
5 views2 pages

expt3Bissectionin

The document presents a MATLAB code implementing the bisection method to solve for the specific volume of a non-ideal gas under given conditions. It calculates parameters a and b based on constants, applies the bisection method to find the volume, and checks for convergence. The final output indicates that the method converged in 45 iterations, resulting in a mass of 1068.22 kg of methane that can be held in the tank.

Uploaded by

ifyouwantcs
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)
5 views2 pages

expt3Bissectionin

The document presents a MATLAB code implementing the bisection method to solve for the specific volume of a non-ideal gas under given conditions. It calculates parameters a and b based on constants, applies the bisection method to find the volume, and checks for convergence. The final output indicates that the method converged in 45 iterations, resulting in a mass of 1068.22 kg of methane that can be held in the tank.

Uploaded by

ifyouwantcs
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/ 2

%Bisection method to solve equation for non-ideal gas

%Source Code by Shivani Kumari(123MM0672)


clc
clear all
% Constants
R = 0.518; % kJ/(kg·K)
Tc = 191; % K
Pc = 4600; % kPa

% Parameters a and b
a = 0.427 * R^2 * Tc^2.5 / Pc;
b = 0.0866 * R * Tc / Pc;

% Given values
T = -40 + 273.15; % Convert temperature to Kelvin
P = 65000; % Pressure in kPa
V_tank = 3; % Tank volume in m³

% Non-ideal gas equation function


f = @(V) P - (R * T / (V - b)) + (a / (V * (V + b) * sqrt(T)));

% Bisection Method parameters


tol = 1e-6; % Tolerance for convergence
max_iter = 1000; % Maximum number of iterations
V_low = b + 1e-6; % Lower bound of V (just above b)
V_high = 1; % Upper bound of V (initial guess)
iter = 0;

% Bisection Method loop


while iter < max_iter
V_mid = (V_low + V_high) / 2;
if abs(f(V_mid)) < tol
break;
elseif f(V_mid) * f(V_low) < 0
V_high = V_mid;
else
V_low = V_mid;
end
iter = iter + 1;
end

% Check for convergence


if iter == max_iter
error('Bisection method did not converge.');
else
fprintf('Converged in %d iterations.\n', iter);
end

% Specific volume V and mass calculation


V_specific = V_mid; % Specific volume (m³/kg)
mass = V_tank / V_specific; % Mass in kg

% Output the result


fprintf('The amount of methane that can be held in the tank is %.2f kg.\n',
mass);

Output:
Converged in 45 iterations.
The amount of methane that can be held in the tank is 1068.22 kg.

You might also like