how can I pass parameters for ode15i?

2 views (last 30 days)
Tadele
Tadele on 14 Feb 2023
Moved: Torsten on 14 Feb 2023
Dear experts,
Can you please help on passing parameter for ode15i
exmple code
function dxdz = MS_AA_imp(z,x,xp, x_p, N_tot, Z)
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_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]
h=9.8;
hydration= x(1)/((x(1))*(1-x(1)*h)*(R_id*TempK));
CT = 1/(x(1)*VM_1 + x(2)*VM_2 + x(3)*VM_3 + x(4)*VM_4);
D_14 =10e-9 *(0.665-0.393*x(1))/(1+x(1)* (h/(1-x(1)* h)));
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)));
N_1 = x_p(1) * N_tot;
N_2 = x_p(2) * N_tot;
N_3 = x_p(3) * N_tot;
N_4 = (1-sum(x_p)) * N_tot;
%equations to be solved
dxdz = [hydration * xp(1) + x(1) * Z(1) * Faraday / (R_id .* TempK)*xp(5) - (N_4 * x(1) - N_1* x(4))/(D_14 * CT);
xp(2) + x(2) * Z(2) * Faraday*xp(5) / ( R_id * TempK) - (N_3 * x(2) - N_2 * x(3))/ (D_23*CT) - (N_4 * x(2) - N_2 * x(4))/ (D_24 *CT);
xp(3) + x(3) * Z(3) * Faraday*xp(5) / ( R_id * TempK) - (N_2 * x(3) - N_3 * x(2))/ (D_23*CT) - (N_4 * x(3) - N_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
I want to pass parameters
x_p, N_tot, Z % as xp_guess_MS, N_tot and Z
for ode15i solver as I tried below which shows me error when I change the t span. Can you please help cheking how I pass those parameters for the solver? and is the ode15i procidure i followed correct?
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_24 = 1.33E-9; % D24 value under diluted conditions [m^2/s]
Z=[-1 1 -1];
z_pol=1.23e-5;
x_p_guess=[0.000147 0.000147 0.000147]
x_p_guess_MS = [x_p_guess 1- sum(x_p_guess)];
Jv=3.69e-6;
Cp_guess_tot = 1/ (sum([x_p_guess (1-sum(x_p_guess))].*[VM_1 VM_2 VM_3 VM_4]))
N_tot =Jv*Cp_guess_tot;
phi_start = [0.0001457 0.000179 0.000179 0.99]
[y0, yp0] = decic(@MS_AA_imp, 0, [phi_start 0], [0 0 0 0 0], [1 1 0 0 0], [],[], x_p_guess_MS, N_tot, Z);
[zsol_MS, ysol_MS] = ode15i(@(z,x,xp)MS_AA_imp(z,x,xp,x_p_guess_MS, N_tot, Z), [0 z_pol], y0, yp0);
C_surf = ysol_MS(end,:)
plot(zsol_MS,ysol_MS(:,1))
Thank you so much in advance!

Answers (1)

Torsten
Torsten on 14 Feb 2023
Moved: Torsten on 14 Feb 2023
The code you posted does not error.
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_24 = 1.33E-9; % D24 value under diluted conditions [m^2/s]
Z=[-1 1 -1];
z_pol=1.23e-5;
x_p_guess=[0.000147 0.000147 0.000147];
x_p_guess_MS = [x_p_guess 1- sum(x_p_guess)];
Jv=3.69e-6;
Cp_guess_tot = 1/ (sum([x_p_guess (1-sum(x_p_guess))].*[VM_1 VM_2 VM_3 VM_4]));
N_tot =Jv*Cp_guess_tot;
phi_start = [0.0001457 0.000179 0.000179 0.99];
[y0, yp0] = decic(@MS_AA_imp, 0, [phi_start 0], [0 0 0 0 0], [1 1 0 0 0], [],[], x_p_guess_MS, N_tot, Z);
[zsol_MS, ysol_MS] = ode15i(@(z,x,xp)MS_AA_imp(z,x,xp,x_p_guess_MS, N_tot, Z), [0 z_pol], y0, yp0);
C_surf = ysol_MS(end,:);
plot(zsol_MS,ysol_MS(:,1))
function dxdz = MS_AA_imp(z,x,xp, x_p, N_tot, Z)
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_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]
h=9.8;
hydration= x(1)/((x(1))*(1-x(1)*h)*(R_id*TempK));
CT = 1/(x(1)*VM_1 + x(2)*VM_2 + x(3)*VM_3 + x(4)*VM_4);
D_14 =10e-9 *(0.665-0.393*x(1))/(1+x(1)* (h/(1-x(1)* h)));
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)));
N_1 = x_p(1) * N_tot;
N_2 = x_p(2) * N_tot;
N_3 = x_p(3) * N_tot;
N_4 = (1-sum(x_p)) * N_tot;
%equations to be solved
dxdz = [hydration * xp(1) + x(1) * Z(1) * Faraday / (R_id .* TempK)*xp(5) - (N_4 * x(1) - N_1* x(4))/(D_14 * CT);
xp(2) + x(2) * Z(2) * Faraday*xp(5) / ( R_id * TempK) - (N_3 * x(2) - N_2 * x(3))/ (D_23*CT) - (N_4 * x(2) - N_2 * x(4))/ (D_24 *CT);
xp(3) + x(3) * Z(3) * Faraday*xp(5) / ( R_id * TempK) - (N_2 * x(3) - N_3 * x(2))/ (D_23*CT) - (N_4 * x(3) - N_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

Categories

Find more on Particle & Nuclear Physics 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!