Can not pass enough input arguments to BVP function using bvp4c

Hi all,
I'm trying to solve the following BVP function, where lambda will is an unknown and a_r is a constant.
y'' + lambda^2 * y = -lambda^2 * a_r defined in the range [0,L].
BC's are: y(0)=0 and y'(L)=0.
By the guidance of tutorial "Solve BVP with Unknown Parameters" I've written the code below.
lambda=2.5899;
solinit=bvpinit(linspace(0,L,10),@mat4init,lambda);
sol=bvp4c(mat4ode,mat4bc,solinit);
%% functions
function dydx=mat4ode(x,y,lambda)
a_r=3*pi/180;
dthdy=[y(2) -lambda^2*(a_r + y(1))];
end
function res=mat4bc(ya,yb,lambda)
res=[ya(1)
yb(2)];
end
function thinit=mat4init(x)
global L;
thinit=[sin(x*pi/2/L)
(pi/2/L)*cos(x*pi/2/L)];
end
As a result, I am getting this error:
Not enough input arguments.
Error in Untitled6>mat4ode (line 7)
dthdy=[y(2) -lambda^2*(a_r + y(1))];
Error in Untitled6 (line 3)
sol=bvp4c(mat4ode,mat4bc,solinit);
Could you please help me to fix that error?
Thanks

Answers (1)

In the line:
sol=bvp4c(mat4ode,mat4bc,solinit);
you call mat4ode without inputs. You want to provide the function handle instead and append the parameter lambda in addition:
sol=bvp4c(@(t,y) mat4ode(t, y, lambda), mat4bc, solinit);

3 Comments

Jan,
Thanks for your comment. But after that correction I've received the same for mat4bc. Then, done the same correction for this.
However, I am getting the following error now,
Error using Untitled6>@(t,y)mat4ode(t,y,lambda)
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 Untitled6 (line 3)
sol=bvp4c(@(t,y) mat4ode(t, y, lambda), @(ya,yb)mat4bc(ya,yb,lambda), solinit);
Let me share the new code as well.
lambda=2.5899;
solinit=bvpinit(linspace(0,0.6,10),@mat4init,lambda);
sol=bvp4c(@(t,y) mat4ode(t, y, lambda), @(ya,yb)mat4bc(ya,yb,lambda), solinit);
%% functions
function dydx=mat4ode(x,y,lambda)
a_r=3*pi/180;
dthdy=[y(2) -lambda^2*(a_r + y(1))];
end
function res=mat4bc(ya,yb,lambda)
res=[ya(1)
yb(2)];
end
function thinit=mat4init(x)
L=0.6;
thinit=[sin(x*pi/2/L)
(pi/2/L)*cos(x*pi/2/L)];
end
Thanks.
Two changes:
% solinit = bvpinit(linspace(0,0.6,10), @mat4init, lambda);
solinit = bvpinit(linspace(0,0.6,10), @mat4init);
% And:
% dthdy=[y(2) -lambda^2*(a_r + y(1))];
dydx = [y(2), -lambda^2*(a_r + y(1))];
Thank you Jan.
The problem is solved by adding an arbitrary 3rd boundary condition such as
ya(2)-1e6.
The problem is solved.

Sign in to comment.

Tags

Asked:

on 24 Apr 2021

Commented:

on 26 Apr 2021

Community Treasure Hunt

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

Start Hunting!