Clear Filters
Clear Filters

ODE45 running infinitely without solving

2 views (last 30 days)
I tried to code an ode45 function to find the concentration wrt to thickness of membrane but the ode45 function is taking too long without actually solving the code
ts = 100e-06; %in m
ta = 100e-09; %in m
z0 = ta + ts ; %z = ta+ts
zend = ta + ts + del_d ; %z = ta+ts+delta_d
[zdsol,cdsol]=ode45(@(z,c) decp(z,c), [z0,zend],c0);
And this is the function
function dc = decp(z,c)
x1_dsd = -6.92e-12;
x2_dsd = -9.95e-11;
x3_dsd = 1.51e-9;
dsd_d= x1_dsd*c^2 + x2_dsd*c + x3_dsd;
dc = ((0.02+6*c)/dsd_d);
end
With Js and Jw being constants
Please help !

Accepted Answer

Walter Roberson
Walter Roberson on 5 May 2020
Edited: Walter Roberson on 5 May 2020
try ode23s. if your system is stiff then ode45 can take a long long time.
Also I worry that your c0 is associated with time 0; it needs to be associated with time z0 instead.
Your denominator dsd_c has zeros near time 1e-11 which could be a problem
  5 Comments
Walter Roberson
Walter Roberson on 5 May 2020
we need the rest of your code to test with
Ajmal R S
Ajmal R S on 5 May 2020
Here is the full code.
clc;
clear all;
A = 0.5;
B = 0.4;
S = 200e-06;
Jw= 6;
Js= 0.02;
c0 = 1;
v = 20; %cross flow velocity feed and draw in cm/s
x1_rho = 0.04;
x2_rho = 1;
rho_d = x1_rho*c0 + x2_rho; %in cgs
x1_mu = 0.02;
x2_mu = 0.06;
x3_mu = 0.89;
mu_d = x1_mu*c0^2 + x2_mu*c0 + x3_mu; %in cgs
L = 8.55; %channel length in cm
dh = 0.42; %hydrauic diameter in cm made it 0.2 to meet conditions in ref.
Re = (rho_d*1000*v*10^-2*dh*10^-2)/(mu_d*10^-3);
x1_dsd = 6.92e-12;
x2_dsd = -9.95e-11;
x3_dsd = 1.51e-9;
dsd_d= x1_dsd*c0^2 + x2_dsd*c0 + x3_dsd; %given in section 3.2 in m2/s
Sc = (mu_d*10^-3)/(rho_d*1000*dsd_d);
Sh = 1.85*(Re*Sc*(dh/L))^0.33;
k_d = (Sh*dsd_d)/(dh*10^-2); %in m/s
del_d = dsd_d/k_d; %in m
ts = 100e-06; %in m
ta = 100e-09; %in m
zend = ta + ts ; %z = ta+ts
z0 = ta + ts + del_d ; %z = ta+ts+delta_d
[zdsol,cdsol]=ode23s(@(z,c) decp(z,c), [z0,zend],c0);
And the function
function dc = decp(z,c)
x1_dsd = 6.92e-12;
x2_dsd = -9.95e-11;
x3_dsd = 1.51e-9;
dsd_d= x1_dsd*c^2 + x2_dsd*c + x3_dsd;
dc = ((0.02+6*c)/dsd_d);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!