"Too many input arguments" error while using bvp4c.

6 views (last 30 days)
Mukul
Mukul on 29 Sep 2023
Commented: Mukul on 29 Sep 2023
I am trying to find the solution to the following differential equations (which comes up while finding the similarity solution for boundary layer) using bvp4c. Here, .
Here m is a known parameter. I convert this third-order ode to three first order ode's as follows.
, , .
This gives,
The boundary conditions are: .
The code is as given below, with initial guess :
m = -0.05; % n = -0.5; Pr = 0.72;
init = bvpinit(linspace(0,50,200),[0 0 0.5], m); % 0 0.5]);
sol = bvp4c(@(Z) bvp_rhs(Z, m), @(Zi, Zf) bvp_bc(Zi, Zf, m), init);
eta = linspace(0,50,200); BS = deval(sol, eta);
plot(eta, BS(1,:))
function rhs = bvp_rhs(Z, m) %, n, Pr)
rhs = [Z(2); Z(3); -((m + 1)/2)*Z(1)*Z(3) - m*(1 - Z(2)^2)]; %Z(5); -((m + 1)/2)*Pr*Z(1)*Z(5) - n*Pr*(1 - Z(4))*Z(2)];
end
function bc = bvp_bc(Zi, Zf)
bc = [Zi(1) - 0; Zi(2) - 0; Zf(2) - 1]; %Zi(4) - 0; Zi(5) - 0; Zf(4) - 1];
end
Here since is achieved at , I have considered .
I keep on getting the following error message and I am not sure why.
Error using untitled2>@(Z)bvp_rhs(Z,m)
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in untitled2 (line 3)
sol = bvp4c(@(Z) bvp_rhs(Z, m), @(Zi, Zf) bvp_bc(Zi, Zf, m), init);
untitled
Error using untitled>@(Z)bvp_rhs(Z,m)
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in untitled (line 3)
sol = bvp4c(@(Z) bvp_rhs(Z, m), @(Zi, Zf) bvp_bc(Zi, Zf, m), init);
Can anyone please help me with this?
If I have to further extend this code to couple the following ode with the first one, withn and as known parameters,
such that and and additional boundary conditions . Can the commented portion in the code work when appropriately added in the required places?

Answers (1)

Walter Roberson
Walter Roberson on 29 Sep 2023
bvp4c expects the first parameter to be an ode function. That ode function is expect to take two parameters -- current time and current boundary conditions/] But you are passing @(Z) bvp_rhs(Z, m) which is an anonymous function that expects one parameter, not two.
In MATLAB, parameters are passed positionally, not by name of the variable, so there is no possibility that MATLAB could look at the @(Z) and guess from the name of the variable that you were wanting to skip the time parameter. If you do not want to pass the time parameter into later code then use
sol = bvp4c(@(t, Z) bvp_rhs(Z, m), @(Zi, Zf) bvp_bc(Zi, Zf, m), init);
which would accept a first parameter but then just not do anything with it.
  3 Comments
Torsten
Torsten on 29 Sep 2023
Edited: Torsten on 29 Sep 2023
How should MATLAB know that you additionally want to pass "m" to your ODE function ? You must indicate this in your list of inputs to the function.
So use
sol = bvp4c(@(eta,Z)bvp_rhs(eta,Z,m), @bvp_bc, init);
instead of
sol = bvp4c(@bvp_rhs, @bvp_bc, init);
And I think you made a mistake in the transformation to a first-order system.
Shouldn't it read
-((m + 1)/2)*Z(1)*Z(2) - m*(1 - Z(2)^2)
instead of
-((m + 1)/2)*Z(1)*Z(3) - m*(1 - Z(2)^2)
?
And why do you set
Zf(2) - 1
as a boundary condition if you want to prescribe Z_2(Inf) = 0 ?
Mukul
Mukul on 29 Sep 2023
The transformation looks okay to me.
I had incorrectly put the BC instead of in my original question. I have editted it there.
Sorry for the mistakes. I am new to MATLAB and am still learning.
I have attached the expected result for different values of m.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!