EXP02_MATLAB(1)
EXP02_MATLAB(1)
clc
clear all
R = 0.518; % kJ/(kg·K)
Tc = 191; % K
Pc = 4600; % kPa
OUTPUT:
Newton-Raphson:
Tc = 191; % K
Pc = 4600; % kPa
T = 233; % K
P = 65000; % kPa
R = 0.518; % kJ/kg/K
% Calculate a and b
a = 0.427 * R^2 * Tc^2.5 / Pc;
b = 0.0866 * R * T / P;
% Initial guess
ans1 = 0;
while ans1 == 0
x0 = input('Enter the initial guess : ');
if abs(f(x0) / df(x0)) < 1
ans1 = 1;
else
fprintf('\nEnter a new guess:\n');
end
end
% Newton-Raphson Method
for i = 1:n
x1 = x0 - f(x0) / df(x0);
if abs(x1 - x0) < acc
break;
end
x0 = x1;
end
% Accuracy check
if abs(x1 - x0) > acc
fprintf('\nNumber of iterations are not sufficient to achieve desired
accuracy.\n');
else
fprintf('\nRoot (v) of the equation using Newton-Raphson Method = %.6f
m³/kg\n', x1);
end
Enter the number of iterations: 20
Enter the accuracy of the root: 0.001
Enter the initial guess (v): 0.003