Instruction: (MATLAB) Do the general command to solve the numerical method Do se
ID: 707536 • Letter: I
Question
Instruction: (MATLAB)
Do the general command to solve the numerical method
Do separate function file for the function
Execute your function file in the command window.
Print screen instructions (1-3) and paste it in the microsoft word.
Utilising MAtlab R2018a version
In a chemical engineering process, water vapor (H20) is heated to sufficiently high temperatures that a significant portion of the water dissociates, or splits apart, to form oxygen (02) and hydrogen (H): H2o- H2+0.5?2. If it is assumed that this is the only reaction involved, the mole fraction x of H2O that dissociates can be represented by K 1-2t* where K-the reaction equilibrium constant andptthe total pressure of the mixture. Ifpt- 3.5 atm and K0.04, determine the value of x using Newton-Rapson method that satisfies the above equation.Explanation / Answer
(1) MATLAB Code:
function xvalue = nwtnrpn(x0,es,imax)
iter = 0;
K = 0.04;
pt = 3.5;
xr=x0;
while(1)
xrold = xr;
fx0=(x0/(1-x0))*sqrt(2*pt/(2+x0))-K; (Function)
dfx0= sqrt(2*pt/(2+x0))*((1/(1-x0)^2)-(x0/(2*(1-x0)*(2+x0)))); (Derivative)
xr = xr - fx0/dfx0;
iter=iter+1;
if xr~=0 & dfx0~=0
end
ea=abs((xr-xrold)*100/xr);
if ea<es | iter>imax, break, end
end
xroot = xr
end
(2) Execution of function file in the command window:
nwtnrpn(0.5,0.001,1000)
(3) Result (answer)
xroot = 0.021041