Im working with algae growth linked to the light. I don't know how to write the integral on matlab inside the the light intensity formulation.

1 view (last 30 days)
function u = bioreactors
clc
clear all
% Forward Euler method is used for solving the following boundary value problem:
% U(0,t) = 0
% U(L,t) = u (end-1,t)
% U(z, 0) = U0(z)=0
% it is assumed that the concentration of C,N,P are costant
% Problem parameters
alpha1 = 5*10^(-4);
mu0 = 0.5;
mue = 0.035;
Hl = 5;
T = 10^3; % [s]
nz = 100; nt = 100;
KP = 0.7 ;
HP= 7;
P = 0.2 ;
PC = 0.1;
K = 0.50;
KN = 0.35 ;
HN = 14.5*10^(-6);
N = 0.3;
NC = 0.2;
KC = 0.5;
HC = 5 ;
C = 0.4 ;
PHs3 = 0.4 ;
PHs4 = 0.5;
Z = 10;
lambda = 2 ;
%Check of the problem's parameters
if any([P-PC N-NC] <=0 )
error('Check problem parameters')
end
if any([alpha1 mu0 Hl Z T nz-2 nt-2 KP P PC HC KN N NC KC HC C HN ] <= 0)
error('Check problem parameters')
end
% Stability
dz=Z/nz ;
dt = T/nt;
r = alpha1*dt/((dz)^2);
st = 1;
while (2*r) > st
nt = nt+1;
end
% Initialization
z = linspace(0,Z,nz+1); t = linspace(0,T,nt+1);
f1= (KP*(P-PC))/(HP+(P-PC));
f2 = (KN*(N-NC))/(HN+(N-NC));
pH = (6.35 - log10(C)) /2 ;
f3 = 1/(1+exp(lambda*(pH-PHs3)));
f4 = 1/(1+exp(lambda*(pH-PHs4)));
I0 = 100*max(sin ((t-0.4*3600)/(6.28)) , sin (0));
%I = ???% Dont know how to write it on matlab.
% Finite-difference method
for j=2:nt+1
u(1) = 0; % Condizione al contorno di Dirichlet
g = (mu0.*I(j))/(Hl+I(j)); decay = g(j)*f1*f2*f3-mue*f4;
u(2:end-1)=(1-2*r-decay*dt)*u(2:end-1)+r*(u(1:end-2)+u(3:end));
u(end) = u(end); % Condizione al contorno di Neumann
plot(u,z,'r*:');
set(gca,'YDir','reverse');
xlabel('u'); ylabel('z');
title(['t=',num2str(t(j))]);
axis([0 0.05 0 10]);
pause(0.01);
end
The integral is in the page 9 of the attachment "algae". The light intensity(I) formulation can be found at page 2, formulation number (3), it is a value which changes through the space z and the time.
As a result i should see a plot in which the mass of microorganism changes over the space and the time, something like this:
On Z=0 there is the light while in Z=5 there is no light so that's why the mass of microorganisms is equal to 0, they are photosynthetic algae.
  2 Comments
Alfonso
Alfonso on 18 Nov 2023
Edited: Alfonso on 18 Nov 2023
Yes, i want just to have the growth of microorganisms over the space and time. If you dont have some parameters just choose a value random, then i'll change it with real ones.

Sign in to comment.

Answers (2)

Torsten
Torsten on 18 Nov 2023
Moved: Torsten on 18 Nov 2023
Where is your discretization of d^2w/dz^2 ? Where do you implement the boundary conditions dw/dz = 0 at z = 0 and z = L ?
You have to discretize equation (1) of the article in space and use an ode-integrator (usually ode15s) to integrate the values in the grid points over time.
Look up "method-of-lines" for more details.
I suggest you do this first without the integral term. After you succeeded, add the three ordinary differential equations for N,P and C and use "trapz" to compute the integral term.
  1 Comment
Alfonso
Alfonso on 18 Nov 2023
Edited: Alfonso on 18 Nov 2023
i've already done the discretization of the equation (1) which is u(2:end-1)=(1-2*r-decay*dt)*u(2:end-1)+r*(u(1:end-2)+u(3:end)); but inside this formula there is the "decay" term which has "g" which depends by the "I" term which has an integral that I don't know how to insert inside matlab, this is the problem.
For the boundary condition i put:
  • For z=0 --> u(1)=0, Dirichlet
  • For z=L --> u(end)=u(end-1), Noemann equal to 0
You can find everything inside the for cycle. In fact, I just used a for cycle which is simpler to define the discretized w over the time, i'm a student so i'm not so good in doing this work.
But the problem that i don't know how to solve is that the I changes its values also during the space and my for cycle takes into account only the time and not the space.
Regarding N, P, C i want first to make the code going, then i'll go through their equations, so for now you see just some values of them without any formulas.

Sign in to comment.


Torsten
Torsten on 19 Nov 2023
Moved: Torsten on 19 Nov 2023
My suggestion:
z = linspace(0,Z,nz+1); t = linspace(0,T,nt+1);
I0 = @(t) 100*max(sin ((t-0.4*3600)/(6.28)) , sin (0));
w(:,1) = ... % w at time t = 0
for j = 1:nt
I_in = I0(t(j))*exp(-k*z.').*exp(-rs)*cumtrapz(z.',w(:,j));
g = mu0*I_in./(H_l+I_in);
integral_term = f1 * f2 * f3 * trapz(z.',g.*w(:,j));
w(2:nz,j+1) = w(2:nz,j) + dt*...
w(1,j+1) = w(2,j+1);
w(nz+1,j+1) = w(nz,j+1);
end
  27 Comments

Sign in to comment.

Categories

Find more on Programming 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!