Boundary value problem with a changing parameter
古いコメントを表示
Hi!
I'm trying to solve a boundary value problem for a set of odes, with a parameter changing with x.
I have the code set up as below.
But the code would only run if I set AbsTol and Reltol to 1E-1. Also, I'm not getting the expected results.
Could someone please help me out?
Really appreciate!
F=96485; R=8.3144621; T=25+273.15; Z_OH=-1; Z_H=1; LA=1E-4; LC=1E-4; d=1E-5; D_H=5.94/10^10; D_OH=3.47/10^10;
%%%%%%%%%%%%%%%%%%%%
options=bvpset('AbsTol',1e-1,'Reltol',1e-1);
y0=[0.021;258.1;226.0552;486.6069;0;0];
solinit=bvpinit([0,LA+LC+d],y0);
sol =bvp4c(@odefun,@odebc,solinit,options);
%%%%%%%%%%%%%%%%%%%%
p=(linspace(0,LA+LC+d))'; y=(deval(p,sol))';
function [dy]= odefun(x,y) global F R T Z_OH Z_H D_OH D_H LA LC d % y(1)=Electric potential,y(2)=Electric field, y(3)=OH-concentration % y(4)=Na+ concentration, y(5)=dy(3)/dx, y(6)=dy(4)/dx
if x>=0 && x<=(LA-(5E-6))
FixedCharge=2000;
elseif x>(LA-(5E-6)) && x<=(LA+(5E-6))
FixedCharge=1000*(tanh(x*5E5)-tanh((x-LA)*5E5));
elseif x>=(LA+(5E-6)) && x<=(LA+d-(5E-6))
FixedCharge=0;
elseif x>=(LA+d-(5E-6)) && x<(LA+d+(5E-6))
FixedCharge=-1000*(tanh((x-LA-d)*5E5)-tanh((x-LA-LC-d)*5E5));
else
FixedCharge=-2000;
end
Kw=1E-8;
dy = zeros(6,1);
dy(1)=-y(2); dy(3)=y(5); dy(4)=y(6);
dy(2)=(D_H*Kw/(D_OH*(y(3)^3))*(2*(y(5)^2)-y(3)*dy(5))+D_H/D_OH*Z_H*F/R/T*Kw/(y(3)^2)*y(5)*y(2)-dy(5)+Z_OH*F/R/T*y(5)*y(2))/(D_H/D_OH*Z_H*F/R/T*Kw/y(3)-Z_OH*F/R/T*y(3)); dy(5)=(dy(6)+Kw*2*(y(5)^2)/(y(3)^3)-Z_OH*F/R/T*((y(6)-y(5)-Kw/(y(3)^2)*y(5))*y(2)+(y(4)+Kw/y(3)-y(3)+FixedCharge)*dy(2)))/(1+Kw/(y(3)^2)); dy(6)=Z_H*F/R/T*(y(6)*y(2)+y(4)*dy(2)); end
function [bc]= odebc(ya,yb) % Boundary condition
bc=[ya(1)-0.021
yb(1)-1
ya(3)-226.0552
yb(3)-4.4237E-11
ya(4)-486.6069
yb(4)-2260.6];
end
3 件のコメント
Torsten
2018 年 3 月 16 日
Use the capability of BVP4C to solve multipoint boundary value problems:
https://de.mathworks.com/help/matlab/ref/bvp4c.html#bt5uooc-23
This will cope with the discontinuities of your ODEs because of the FixedCharge parameter.
Best wishes
Torsten.
Luka
2018 年 3 月 16 日
Luka
2018 年 3 月 18 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Function Handles についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!