Please login with a confirmed email address before reporting spam
Posted:
1 decade ago
16.10.2011, 13:10 GMT-4
Hi Roger,
if you want to use a script, it should look somehow like this:
% define growth function and save as growth.m, let's say bacteria double in every time step
function G=growth(x)
G=2*x;
end
% setup simple script for the calculation of the population in every time step and save as dynamic.m
H(1) = 1; % set initial value
dt = 0.001; % set time increment
N = 1000; % set number of time steps
for i = 1:N
H(i+1) = H(i) + dt*growth(H(i));
end
Once you have these two files, you may run your calculation by the command 'dynamic' and plot the solution with the command 'plot(H)'. Even though the upper formulation is much more adjustable, COMSOL can handle these equations because you can rewrite your step-by-step formulation into an ordinary differential equation given as
dX/dt = growth(X).
Define a growth-function in COMSOL and enter this equation as global equation, the result should be the same.
I hope this helps,
Alex
Hi Roger,
if you want to use a script, it should look somehow like this:
% define growth function and save as growth.m, let's say bacteria double in every time step
function G=growth(x)
G=2*x;
end
% setup simple script for the calculation of the population in every time step and save as dynamic.m
H(1) = 1; % set initial value
dt = 0.001; % set time increment
N = 1000; % set number of time steps
for i = 1:N
H(i+1) = H(i) + dt*growth(H(i));
end
Once you have these two files, you may run your calculation by the command 'dynamic' and plot the solution with the command 'plot(H)'. Even though the upper formulation is much more adjustable, COMSOL can handle these equations because you can rewrite your step-by-step formulation into an ordinary differential equation given as
dX/dt = growth(X).
Define a growth-function in COMSOL and enter this equation as global equation, the result should be the same.
I hope this helps,
Alex
Please login with a confirmed email address before reporting spam
Posted:
1 decade ago
18.10.2011, 06:01 GMT-4
Thank you very much Alex, your answer has been of great help!
Actually, in my model, I defined the growth function using an ODE in comsol, just as you said at the end of your post:
growth_H is defined as dH/dt=a*H (were a is related to the concentration of a nutrient, which also varies with time)
Then, should the external matlab script look something like this?
function H=bacteria(growth_H)
H(0)=1;
dt=3600;
T=86400*10;
for i=0:dt:T
H(i+1)=H(i)+growth_XH(i);
end
Is it correct to call the comsol ODE value like growth_XH from Matlab?
Also, in comsol, I should call the script from functions/MATLAB and add the function bacteria(growth_H), right?
Thank you again
Thank you very much Alex, your answer has been of great help!
Actually, in my model, I defined the growth function using an ODE in comsol, just as you said at the end of your post:
growth_H is defined as dH/dt=a*H (were a is related to the concentration of a nutrient, which also varies with time)
Then, should the external matlab script look something like this?
function H=bacteria(growth_H)
H(0)=1;
dt=3600;
T=86400*10;
for i=0:dt:T
H(i+1)=H(i)+growth_XH(i);
end
Is it correct to call the comsol ODE value like growth_XH from Matlab?
Also, in comsol, I should call the script from functions/MATLAB and add the function bacteria(growth_H), right?
Thank you again