i wrote a simple code to solve a steady state fermentation problem. It looks a lot because of so much variables.
function y = f (x)
mumax = 1.10; %h-1
Ksx = 1.32; %gl^-1
Pix=1.39; %gl^-1
Pmx=49.9; %gl^-1
Kix=304; %gl^-1
Pis=47.1; %gl^-1
Pms=95.5; %gl^-1
Kis=140; %gl^-1
qsmax=3.42; %gg^-1h^-1
Kss=2.05; %gl^-1
alp=0.39;
qpmax=3.02; %gg^-1h^-1
Ksp=2.05; %gl^-1
Kip=140; %gl^-1
Pip=47.1; %gl^-1
Pmp=95.5; %gl^-1
F=240;
S=40;
V=120;
D=0.5;
mu= (mumax*x(2)) / (Ksx+x(2));
y=[x(1)*(-D+mu*(1-(x(3)-Pix)/(Pmx-Pix))*(Kix/(Kix+x(2))));
D*(S-x(2))-(qsmax*(x(2)/(Kss+x(2)))*(1-((x(3)-Pis)/(Pms-Pis)))*(Kis/(Kis+x(2))))*x(1);
-x(3)*D+x(1)*(-D+mu*(1-(x(3)-Pix)/(Pmx-Pix))*(Kix/(Kix+x(2))))*alp+qpmax*(x(2)/(Ksp+x(2)))*(1-(x(3)-Pip)/(Pmp-Pip))*x(1)*(Kip/(Kip+x(2)));];
endfunction
[x, fval, info] = fsolve (@f, [2; 10; 30])
I defined D as 0.5 but actually i need the solutions for D in the interval between 0 and 1 and then plotting all x(1),x(2),x(3) vs D.
I tried something like
for i=0:0.1:1
D=num2str(i)
but its not working maybe i put it in a wrong way? Best would be to save all into one matrix to plot it easily.
There’s this workaround from the MATLAB help on fsolve for dealing with more than one input argument. Define D as a parameter:
then you can create an anonymous function to pry off the parameter for fsolve. try something like
If you want to test a lot of values for D (or if you are doing time evolution) then you would not build Q in this manner, but playing with fsolve like this should get the job done.