Why am I getting this error?
Show older comments
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 Comments
Star Strider
on 18 Apr 2018
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.
Star Strider
on 12 Aug 2021
In the absence of new information, my 3½-year-old Answer remains the same.
.
Nicole Haikalis
on 12 Aug 2021
Star Strider
on 12 Aug 2021
As always, my pleasure!
.
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!