Solve differential equations with bvp4c
Show older comments
I would like to solve 3 differential equations with bvp4c, but I kept getting error messages as:
Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in BPM_ode_Dec1417 (line 39)
sol=bvp4c(@odefun,@odebc,solinit,options);
Here's what I wrote:
solinit=bvpinit(linspace(0,LA,1000),[E_A U_A C3A]);
options=bvpset('RelTol',1e-3,'AbsTol',[1e-6 1e-6 1e-6]);
sol=bvp4c(@odefun,@odebc,solinit,options);
The function file is:
function [dydx]=odefun(y)
global F R T Z1 Z2 Z3 Z4 C1A C2A i U_A FixedCharge D3 e D4
C1=C1A.*exp(-Z1.*F/R/T.*(y(2)-U_A));
C2=C2A.*exp(-Z2.*F/R/T.*(y(2)-U_A));
dydx(1)=F/e*(C1-C2+10^(-8)/y(3)-y(3)+FixedCharge);
dydx(2)=-y(1);
J4=-D4*(-10^(-8)/y(3)^2*dydx(3)+Z4*F/R/T*10^(-8)/y(3)*dydx(2));
dydx(3)=-((i/F-Z4*J4)/Z3/D3)-Z3*F/R/T*y(3)*dydx(2);
end
The boundary condition is:
global C3A U_A E_A
res(1)=ya(1) - E_A;
res(2)=ya(2) - U_A;
res(3)=ya(3) - C3A;
end
I could not find the problem causing the error message here. Please help me out. Thank you very very very much!
7 Comments
Torsten
on 18 Dec 2017
If all boundary conditions are given at x=0, you should use ODE45 instead of BVP4C.
Best wishes
Torsten.
Luka
on 18 Dec 2017
Torsten
on 18 Dec 2017
How can you get an error message concerning "bvp4c" if you use "ode45" ?
Best wishes
Torsten.
Luka
on 18 Dec 2017
Luka
on 18 Dec 2017
Torsten
on 18 Dec 2017
Please insert the complete code you are using.
Best wishes
Torsten.
Luka
on 18 Dec 2017
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!