Can you help solving this differential equation using ode15i, please?
Show older comments
function dydz = MS_AA_imp(z, x, dx_dz ,x_p, V, Z,h)
TempK = 25 + 273.15; % Temp in Kelvin
Faraday = 96485.336; % Faraday constant [C/mol]
R_id = 8.314; % R constant [J/(K mol)]
VM_1 = 1.8e-5; % AA molar volume of lysine [m3/mol] ---converted to m3--which was 18 cm3/mol
VM_2 = 1.57e-5; % Na molar volume [m3/mol] * Calculated from rS
VM_3 = 4.47e-6; % Cl molar volume [m3/mol] * calcualted form rS
VM_4 = 1.8e-5; % Water molar volume [m3/mol]
D_14_inf = 6.67e-10; % D14 value under diluted conditions and IEP [m^2/s]---substituted for D14_inf amino acid which I found on literature and used for the
%calculation of Diffusivity at different concentration(imperical relation fourn using experimental value) D= 10^(-9) (0.665-0.393x_i)
D_24 = 1.33E-9; % D24 value under diluted conditions [m^2/s]
D_34 = 2.03E-9; % D34 value under diluted conditions [m^2/s]
x_1 = x(1);
x_2 = x(2);
x_3 = x(3);
x_4 = x(4);
x_5 = x(5); %psi.
h=7; %hydration number at specific pH and ionic strength
%Vol_exclusion = (1 + 4*x_1 + 4*x_1^2 - 4*x_1^3 + x_1^4)/((1-x_1)^3);
hydration= x_1./((x_1).*(1-x_1.*h).*(R_id*TempK)); % new hydration formula
%CT = x_1 / VM_1 + x_2 / VM_2 + x_3 / VM_3 + x_4 / VM_4;
CT = x_1 / VM_1 + x_2 / VM_2 + x_3 / VM_3 + x_4 / VM_4;
%D_14 = D_14_inf * ( 0.21 + 0.79* exp(-4.7*x_1))/ hydration;
D_14 =10e-9 .*(0.665-0.393.*x_1)./(1+x_1.* (h./(1-x_1.* h))); % new D_14 formula
IStr = 0.5* (Z(2).^2 .* x_2/(VM_2 *1000) + Z(3).^2 .* x_3/(VM_3 *1000));
D_23 = ((D_24 + D_34)./2 .* IStr .^(0.55) ./ (abs((Z(2)) * (Z(3))).^(2.3)));
D_23V = D_23 * VM_3 *CT;
D_32V = D_23 * VM_2 *CT;
J_1 = x_p(1) * V; %think about changing to total molar flux instead of using volumetric flux V (x_tot*v=N_tot--but x_tot=1 thus N_tot=v)
J_2 = x_p(2) * V;%know that the volumetric flux here the same as the total molar flux since the concentration
J_3 = x_p(3) * V;
J_4 = x_p(4) * V;
dpsidz = x_5;
%eq1 = Vol_exclusion * dphi_dz(1) + x_1 * Z(1) * Faraday / (R_id .* TempK)* dphi_dz(5) - (J_4 * x_1 - J_1* x_4)/(D_14 * VM_4 * CT);
eq1 = hydration * dx_dz(1) + x_1 * Z(1) * Faraday / (R_id .* TempK)* dx_dz(5) - (J_4 * x_1 - J_1* x_4)/(D_14 * CT);
%eq1 = hydration* diff(x_1) + x_1 * Z_AA * Faraday * diff(psi)/ ( R * TempK) == N_4 * x_1/ D_14;
eq2 = dx_dz(2) + x_2 * Z(2) * Faraday * dx_dz(5) / ( R_id * TempK) - (J_3 * x_2 - J_2 * x_3)/ D_23 - (J_4 * x_2 - J_2 * x_4)/ (D_24 *CT);
eq3 = dx_dz(3) + x_3 * Z(3) * Faraday * dx_dz(5) / ( R_id * TempK) - (J_2 * x_3 - J_3 * x_2)/ D_23 - (J_4 * x_3 - J_3 * x_4)/ (D_34* CT); %D_32V replaced with D_
eq4 = x_1 + x_2 + x_3 + x_4 - 1; % contiuty
%eq5 = Z(1) * x_1/ VM_1 + Z(2)* x_2/ VM_2 + Z(3) * x_3/VM_3;
eq5 = Z(1) * x_1 + Z(2)* x_2 + Z(3) * x_3; % changed from the above line removing VM
dydz = [eq1; eq2; eq3; eq4; eq5];
end
13 Comments
Tadele
on 1 Jan 2023
Tadele
on 1 Jan 2023
Torsten
on 1 Jan 2023
Could you arrange your code such that it can be executed ?
I.e. take the call to ode15i out of the function MS_AA_imp that is called by ode15i. Otherwise you will get an infinite loop.
Tadele
on 1 Jan 2023
You can't run this function independently.
You must write a script in which you call ode15i and denote MS_AA_imp as the function ode15i should use to get its right-hand sides.
I suggest you start with one of the documented examples for ode15i and arrange your code accordingly.
Tadele
on 2 Jan 2023
Tadele
on 2 Jan 2023
Tadele
on 2 Jan 2023
Torsten
on 2 Jan 2023
You have 5 differential equations, but only 4 solution variables. This won't work.
What's the matter with x(5) ?
What is the z-span you want to integrate over ?
What are the initial conditions for x(1) - x(5) ?
You only copied the test example for ode15i, but didn't adapt it to your own problem.
function dxdz = MS_AA_imp(z,x,xp)
TempK = 25 + 273.15; % Temp in Kelvin
Faraday = 96485.336; % Faraday constant [C/mol]
R_id = 8.314; % R constant [J/(K mol)]
VM_1 = 1.8e-5; % AA molar volume of lysine [m3/mol] ---converted to m3--which was 18 cm3/mol
VM_2 = 1.57e-5; % Na molar volume [m3/mol] * Calculated from rS
VM_3 = 4.47e-6; % Cl molar volume [m3/mol] * calcualted form rS
VM_4 = 1.8e-5; % Water molar volume [m3/mol]
D_14_inf = 6.67e-10; % D14 value under diluted conditions and IEP [m^2/s]---substituted for D14_inf amino acid which I found on literature and used for the
%calculation of Diffusivity at different concentration(imperical relation fourn using experimental value) D= 10^(-9) (0.665-0.393x_i)
D_24 = 1.33E-9; % D24 value under diluted conditions [m^2/s]
D_34 = 2.03E-9; % D34 value under diluted conditions [m^2/s]
%x_5 = x(5); %psi.
V=0.000255;
h=7; %hydration number at specific pH and ionic strength
phi_start=[0 0 0];
Cp_guess_MS=[0.001 0.090 0.003];
%Vol_exclusion = (1 + 4*x_1 + 4*x_1^2 - 4*x_1^3 + x_1^4)/((1-x_1)^3);
hydration= x(1)/((x(1)).*(1-x(1).*h).*(R_id*TempK)); % new hydration formula
%CT = x_1 / VM_1 + x_2 / VM_2 + x_3 / VM_3 + x_4 / VM_4;
CT = x(1) / VM_1 + x(2)/ VM_2 + x(3) / VM_3 + (1-sum(x)) / VM_4;
Z=[-1 1 -1];
%D_14 = D_14_inf * ( 0.21 + 0.79* exp(-4.7*x_1))/ hydration;
D_14 =10e-9 *(0.665-0.393*x(1))/(1+x(1)* (h/(1-x(1)* h))); % new D_14 formula
IStr = 0.5* (Z(2)^2 * x(2)/(VM_2 *1000) + Z(3)^2 * x(3)/(VM_3 *1000));
D_23 = ((D_24 + D_34)/2 * IStr ^(0.55) / (abs((Z(2)) * (Z(3)))^(2.3)));
D_23V = D_23 * VM_3 *CT;
D_32V = D_23 * VM_2 *CT;
x_p=[0.001 0.002 0.0001];
x(4)=1-x(1)+x(2)+x(3);
J_1 = x_p(1) * V; %think about changing to total molar flux instead of using volumetric flux V (x_tot*v=N_tot--but x_tot=1 thus N_tot=v)
J_2 = x_p(2) * V;%know that the volumetric flux here the same as the total molar flux since the concentration
J_3 = x_p(3) * V;
J_4 = (1-sum(x_p)) * V;
%dpsidz = x(5);
dxdz = [hydration * xp(1) + x(1) * Z(1) * Faraday / (R_id .* TempK) - (J_4 * x(1) - J_1* x(4))/(D_14 * CT);
xp(2) + x(2) * Z(2) * Faraday / ( R_id * TempK) - (J_3 * x(2) - J_2 * x(3))/ D_23 - (J_4 * x(2) - J_2 * x(4))/ (D_24 *CT);
xp(3) + x(3) * Z(3) * Faraday / ( R_id * TempK) - (J_2 * x(3) - J_3 * x(2))/ D_23 - (J_4 * x(3) - J_3 * x(4))/ (D_34* CT); %D_32V replaced with D_
x(1) + x(2) + x(3) + x(4) - 1;
Z(1) * x(1) + Z(2)* x(2) + Z(3) * x(3)];
end
Tadele
on 2 Jan 2023
Torsten
on 2 Jan 2023
What's the matter with x(5) ? --->>this is anther differential equation with different variable. But I wanted to calculate it as a fitting paramets that will be calculated automatically when othe variables(x1-x4) are solved.
How ?
In the testcode above:
y0 are your initial conditions.
tspan is Z span.
Adapt the call to decic to your problem now.
Tadele
on 3 Jan 2023
Answers (1)
dx_dz = ???
x_p = ???
V = ???
Z = ???
h = ???
tspan = [0, 10]; % ???
x0 = rand(1, 5); % ???
[Z, Y] = ode15s(@(z, x) MS_AA_imp(z, x, dx_dz, x_p, V, Z, h), tspan, x0);
Although the names of the variables do not matter, "dx_dz", "dydz" and "z", "x" is confusing.
Categories
Find more on Chemistry 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!