There must be Error using fprintf
Unable to convert 'sym' value to 'double'.
Error (line 65)
fprintf('There must be %4.2f moles of NH3 produced to raise the blood pH back to a normal 7.4. \n',Z(1));
Why am I receiving this error??
Code:
% Assume: Open, Reactive, Dynamic
% Basis/Given:
Ka=5.6*10^-10; %M
Vblood= 5000; %mL
pHi=7.2;
pHf=7.4;
mAo=(60/100)*Vblood; %ug
MWnh4=18039000 %um/mol
nAo=mAo/MWnh4
nHo=10^(-pHi)*Vblood;
nHf=10^(-pHf)*Vblood;
% HA: nHAq=nHAf-nHAo
% H: -nHc=nHf-nHo
% A: nAi-nAc=nAf
%%Calculate:
syms nHAo Kap nHo nAo
E1=Kap==Vblood*Ka;
E1a=Kap ==((nHo*nAo)/nHAo);
E1b=nAo==mAo/MWnh4;
E1c=nHo==10^(-pHi)*Vblood;
X=solve(E1,E1a,E1b,E1c,nHAo,Kap,nHo,nAo);
nHAo=X.nHAo;
%n.Hi-n.Hc=n.Hf-n.Ho
%-n.Ac=n.Af-n.A0
%n.HAg=n.HAf-n.HAo
%Kap=(n.hf*n.Af)/n.HAf
%n.Hc=n.Ac
%n.Ac=n.HAg
Kap=Vblood*Ka;
nAo=mAo/MWnh4;
nHo=10^(-pHi)*Vblood;
M=[1,-1,0,0,0,0;
0,0,-1,-1,0,0;
0,0,0,0,1,-1;
0,0,0,-nHf,0,Kap;
0,1,-1,0,0,0;
0,0,1,0,-1,0];
b=[nHf-nHo;
-nAo;
-nHAo;
0;
0;
0];
Z=M\b;
Z(1)
%%Finalize:
fprintf('There must be %4.2f moles of NH3 produced to raise the blood pH back to a normal 7.4. \n',Z(1));

4 个评论

I can’t run this in R2018a.
You did not define ‘pHo’ in the code you posted, so there are no solutions for ‘X’, ‘nHAo’ does not exist, and the rest of the code fails.
Since I don’t have the necessary information to run your code, my best guess is that ‘Z(1)’ contains a symbolic variable, and that’s the reason that double can’t convert it.
@Nicole Haikalis — I have no idea what you edited.
In the absence of new information, my 3½-year-old Answer remains the same.
.
@Star Strider Thank you for your help! I was able to finally figure it out.
As always, my pleasure!
.

请先登录,再进行评论。

 采纳的回答

With the pHo->pHi change, and removing the the quotes from and adding the ‘double equal’ to these lines:

E1= Kap==Vblood*Ka;
E1a= Kap ==((nHo*nAo)/nHAo);
E1b= nAo==(60/100)*Vblood;
E1c= nHo==10^(-pHi)*Vblood;

it works, and produces:

There must be -1730.34 moles of NH3 produced to raise the blood pH back to a normal 7.4. 

1 个评论

I’ll let you sort that.
The best way to treat metabolic acidosis is to use bicarbonate, not ammonia. Ammonia causes a number of adverse effects, most notably hepatic encephalopathy.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by