"If else" statements

2 visualizaciones (últimos 30 días)
EnjoyLife
EnjoyLife el 8 de Nov. de 2020
Respondida: Image Analyst el 8 de Nov. de 2020
How to do the if else statement for the [X] below because my coding keeps showing error at line 32? Can someone help me in this? Thank you vey much.
%Base
base='What is the volume flowrate of base (L/h)?';
V_base=input(base) %volume flowrate of base (L/h)
base_pH='what is the pH of the base?'
pH_base=input(base_pH) %base pH
C_base_H=10^-pH_base; % conc of H+ in base (mol/L)
C_base_OH=10^(-14+pH_base); %conc of OH- in base (mol/h)
x_base=C_base_OH-C_base_H;
%acid
acid='what is the volume flowrate of acid (L/h)?'
V_acid=input(acid) %volume flowrate of acid (L/h)
acid_pH='What is the pH of the acid?'
pH_acid=input(acid_pH) %acid pH
C_acid_H=10^-pH_acid; % conc of H+ in acid (mol/L)
C_acid_OH=10^(-14+pH_acid); %conc of OH- in acid (mol/h)
x_acid=C_acid_OH-C_acid_H;
V=4000; %volume CSTR (L)
syms x(t)
ode=diff(x,t)==(V_base*x_base+V_acid*x_acid-(V_acid+V_base)*x)/V;
cond=x(0)==0;
xSol(t)=dsolve(ode,cond);
t=[1:60]; % time, hour
[X]=[xSol(t)];
if [X]>0
[pH]=-log((X/2)+sqrt(1+((4*10^-14)/X.^2))-1);
elseif [X]<0
[pH]=-log((-X/2)+sqrt(1+((4*10^-14)/X.^2))+1);
else [X]=0
[pH]=-log(sqrt(10^-14));
end
figure
plot(t,pH)
title('pH over time in CSTR')
xlabel('time,hour')
ylabel('pH of outlet stream')

Respuestas (1)

Image Analyst
Image Analyst el 8 de Nov. de 2020
I don't have the symbolic toolbox so I can't run it, but one error I see right off the bat is that you're not using a doubl equals
else [X]=0
should be
else X == 0
Additionally, you don't need square brackets around variables.
And if X is a multi-element array, you'll need to use any(X) or all(X) depending if you want to go in there if 1 or more values are 0, or if you need all values to be zero.

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by