필터 지우기
필터 지우기

"Too many input arguments" error while using bvp4c.

조회 수: 2 (최근 30일)
Mukul
Mukul 2023년 9월 29일
댓글: Mukul 2023년 9월 29일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2023년 9월 29일
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
Torsten
Torsten 2023년 9월 29일
편집: Torsten 2023년 9월 29일
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 2023년 9월 29일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by