- I have corre
- I have corrected your code
initial guess for bvp4c
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Alessia Nannetti
il 5 Feb 2021
Commentato: MOSLI KARIM
il 9 Feb 2023
rsco=0.0024 %Reference SC resistance at h0 mmHg/(μl/min)
rje = 2.08 %mmHg/(μl/min)
rd=0.694 %mmHg/(μl/min)
beta=rje/rsco
x=0:0.01:1; %μm
pac=15 %mmHg
pev=9 %mmHg
fi=rje/rd
%""you must provide an initial guess for the solution ?? here there is the
%problem everything else seems to be correct""
%--> suggestion from Matlab A: crude mesh of five points and a constant
%guess that satisfies the boundary conditions are good enough to get
%convergence on the interval
infinity = 1;
maxinfinity = 2;
solinit = bvpinit(linspace(0,infinity,2),[25 0 0]); %don't know how to manage it
sol = bvp4c(@fsode,@fsbc,solinit);
function dfdeta = fsode(y) %Function
dfdeta = [y(2)
(4/beta)*((y(1))^(1/4)-1)];
end
function res = fsbc(y0,y1) %Boundaries Conditions
res = [y0(2)
-((4*fi)/beta)*(y1(1)^(1/4)-1+pac-pev)];
end
this is my code I don't know why Matlab gives me this type of error
Error using case_1>fsode
Too many input arguments.
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 case_1 (line 26)
sol = bvp4c(@fsode,@fsbc,solinit);
can anyone help? thank you
1 Commento
MOSLI KARIM
il 9 Feb 2023
function bvp_6
global fi beta pac pev rsco rje rd
rsco=0.0024; %Reference SC resistance at h0 mmHg/(μl/min)
rje = 2.08; %mmHg/(μl/min)
rd=0.694 ;%mmHg/(μl/min)
beta=1;
x=0:0.01:1; %μm
pac=15; %mmHg
pev=9 ;%mmHg
fi=rje/rd ;
%""you must provide an initial guess for the solution ?? here there is the
%problem everything else seems to be correct""
%--> suggestion from Matlab A: crude mesh of five points and a constant
%guess that satisfies the boundary conditions are good enough to get
%convergence on the interval
infinity = 1;
maxinfinity = 2;
solinit = bvpinit(linspace(0,infinity,2),[25 0 ]); %don't know how to manage it
sol = bvp4c(@fct,@BC ,solinit)
figure(1)
hold on
plot(sol.x,sol.y)
function dfdeta = fct(x,y) %Function
dfdeta = [y(2);
(4/beta)*((y(1))^(1/4)-1)];
end
function res = BC(ya,yb) %Boundaries Conditions
% global fi beta pac pev
res = [ya(2)
-((4*fi)/beta)*(yb(1)^(1/4)-1+pac-pev)];
end
end
Risposta accettata
Asvin Kumar
il 9 Feb 2021
There are three parts to this problem:
1. Error: Too many input arguments.
To solve this issue, the second argument to bvpinit should have 2 entries instead of 3. This is an initial guess for all the mesh points. The fsode function accepts the y input argument which is expected to be a 2-length vector in your case. You can read more about 'yinit' argument here: https://www.mathworks.com/help/matlab/ref/bvpinit.html#mw_1c665a1d-6f2b-438a-95eb-6c6a2cd19026
solinit = bvpinit(linspace(0,infinity,2),[25 0]);
2. Even with this change you will see an error that the defined constants are not available inside the functions.
To do that, you will have to pass them as inputs to your fsode and fsbc functions. Some examples are available here: https://www.mathworks.com/matlabcentral/answers/274406-ode45-extra-parameters#comment_351560. Some sample code is given below which you can adapt from:
sol = bvp4c(@(x,y) fsode(x,y,rsco,rje,rd,beta_,pac,pev,fi_), ...
@(y0,y1) fsbc(y0,y1,rsco,rje,rd,beta_,pac,pev,fi_),...
solinit);
function dfdeta = fsode(x,y,rsco,rje,rd,beta_,pac,pev,fi_) %Function
dfdeta = [y(2)
(4/beta_)*((y(1))^(1/4)-1)];
end
function res = fsbc(y0,y1,rsco,rje,rd,beta_,pac,pev,fi_) %Boundaries Conditions
res = [y0(1)
-((4*fi_)/beta_)*(y1(1)^(1/4)-1+pac-pev)];
end
3. With these changes, the script would compile but might throw warnings.
If you see the warning: Unable to meet the tolerance without using more than 5000 mesh points...
You could experiment with appropriate initial choices and boundary conditions. You can also refer to the answer here for some ideas.
Here are a couple of examples from the Docs which should help you better understand how the bvp4c and the bvpinit functions can be used:
2 Commenti
Mark Benjamin
il 11 Feb 2021
Is there a way to get bvp4c to automatically re-run with a different initial condition upon divergence (singular Jacobian)? The script currently throws an exception and exits the solver.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Boundary Value Problems in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!