Iterative plotting help !

1 view (last 30 days)
Lu
Lu on 25 Feb 2012
Any kind soul is able to help me optimize this code? I was not able to perform an iterative plot with this =/
I_s = 82;
Cell = [1170000 3510000 7280000 10530000 16380000 24310000 87360000 105560000 111280000 116220000 122330000 166660000 172900000 176800000 185120000 190450000 210210000 212810000 219180000 221130000 226850000 228020000 231530000 234910000 235430000 243620000]'
time = [8.4 11.4 14.4 17.4 20.4 32.4 35.4 38.4 41.4 44.4 56.4 59.4 62.4 65.4 68.4 80.4 83.4 86.4 89.4 92.4 104.9 107.9 110.4 113.4 125.4]'
function [] = microalgae(I_s,Cell,time)
%Integration Summary of this function goes here
% Detailed explanation goes here
%Plot of empirical data
plot(time,Cell,'og')
xlabel('Time(s)')
ylabel('Cell number')
legend on
hold on
%Calculation of residence time--------------------------------------------
%Define variables
Q = 6.5*10^-6; %Gas flow rate (m^3/s)
d_r = 0.08; %Diameter of riser (m)
d = 0.1; %Diameter of reactor (m)
n = 10^-3; %apparent viscosity of the liquid medium (Pa s)
H = 0.3; %Height of reactor (m)
H_d = 0.11; %Height of draft tube (m)
H_b = 0.04; %Height of bottom sectior (m)
C_number=Cell(1); %Initial cell number
t_final=time(end); %Final Time allowed for microalgae growth
t=0; %Initialize while loop
%Calculations
A = (pi/4)*d^2; %Cross-sectional area of reactor (m^2)
A_r = (pi/4)*d_r^2; %Cross-sectional area of riser (m^2)
A_d = A-A_r; %Cross-sectional area of downcomer
U = Q/A_r; %Superficial gas velocity (m/s)
u_lr = 0.66*U^(0.33)*(A_d/A_r)^(0.78);%Liquid circulation velocity (m/s) [Bello et al.(1985)]
e_g = 0.465*U^(0.65)*(1+A_d/A_r)^(-1.06)*n^(-0.103);%Gas holdup [Popovic and Robinson,1984] in reactor
J_lr = u_lr/(1-e_g);%Linear liquid velocity in riser (m/s)
Q_l = J_lr*A_r*(1-e_g);%Liquid flow rate in reactor
J_ld = Q_l/A_d;%Linear liquid velocity in downcomer
H_s = H*(1+e_g)-H_d-H_b;%Height of separator section
t_r = ((H_d+H_b)/J_lr)/3600;%Residence time in riser (h)
t_d = ((H_d+H_b)/J_ld)/3600;%Residence time in downcomer (h)
t_s = ((H_s*A*(1-e_g))/Q_l)/3600;%Residence time in separator (h)
t_cycle = t_r + t_d + t_s;%Residence time per cycle flow (h)
%Defining regions for the trapezoidal integration
r_riser = linspace(0,40,100);
r_downcomer = linspace(42,50,100);
r_separator = linspace(0,50,100);
while t < t_final
%Numerical Integration
I_riser = 2.*pi.*r_riser.*I_s.*(exp(-0.079.*(50-r_riser))+6*10^(-9)*C_number^(-2.5))./(exp(3.5*10^(-10).*C_number.*(50-r_riser))+6*10^(-9)*C_number^(-2.5));
I_ave_riser = trapz(I_riser,r_riser)/(pi*(40)^2);%Average light intensity in riser section
I_downcomer = 2.*pi.*r_downcomer.*I_s.*(exp(-0.079.*(50-r_downcomer))+6*10^(-9)*C_number^(-2.5))./(exp(3.5*10^(-10).*C_number.*(50-r_downcomer))+6*10^(-9)*C_number^(-2.5));
I_ave_downcomer = trapz(I_downcomer,r_downcomer)/(pi*((50)^2-(42)^2));%Average light intensity in downcomer section
I_separator = 2.*pi.*r_separator.*I_s.*(exp(-0.079.*(50-r_separator))+6*10^(-9)*C_number^(-2.5))./(exp(3.5*10^(-10).*C_number.*(50-r_separator))+6*10^(-9)*C_number^(-2.5));
I_ave_separator = trapz(I_separator,r_separator)/(pi*(50)^2);%Average light intensity in separator section
I_ave_cycle = (I_ave_riser*t_r+I_ave_downcomer*t_d+I_ave_separator*t_s)/t_cycle;%Total average light intensity per circulation cycle
t = t+t_cycle; %step increment of t_cycle
B = 0.005173*I_ave_cycle + 1.719;
C = 0.1135*I_ave_cycle + 34.58;
D = -3.994*10^(-5)*(I_ave_cycle)^2 + 0.03629*(I_ave_cycle)+ 10.79;
C_number = Cell(1)+ (B)./(1+exp((C-t)/(D)));
plot(C_number,t,'r')
drawnow
end
  1 Comment
Walter Roberson
Walter Roberson on 25 Feb 2012
What is the difference in output between what you observe and what you expect?
Have you used the profiler to figure out what parts of the code are slowest?

Sign in to comment.

Answers (2)

Lu
Lu on 25 Feb 2012
any help?

Image Analyst
Image Analyst on 25 Feb 2012
Two problems right off the bat. Number 1 is your main program doesn't even actually call the microalgae() function. Second is that your time and Cell arrays aren't the same length. There may be other problems after those are fixed.

Categories

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