# bvp4c: Too many input arguments error

5 views (last 30 days)
I G on 31 Mar 2020
Commented: Ameer Hamza on 3 Apr 2020
I need to solve two differential equations of the first order, with one unknown parameter in each equation, and I have four boundary conditions. My function for guessing solution is pinit:
function pinit = mat4init(z)
pinit = [ 0.65.*cos(z)
0.65.*cos(z) ];
end
I also have function for boundary condtions mat4bc:
function res = mat4bc(pa, pb)
res = [ pa(1,:)-8
pb(1,:)-1
pa(2,:)
pb(2,:) ];
end
where with index 1 are boubdary conditions for the first equation. Unknown parameters are m0, and m1, and I am guessing it bellow, and bellow in matrix4ode function are given also differential equations :
function dpdz = matrix4ode(z, p)
m0 = 2;
m1 = 1;
z = linspace(0,pi,10);
ri = 0.7;
R = ri - z .* (ri - 1);
beta = 1;
dpdz = zeros(2, size(z,2));
dpdz(1,:) = - 32 .* beta .* m0 ./ (R .^ 4 .* p(1,:));
dpdz(2,:) = -( - 8 .* dpdz(1,:) ./ R - dpdz(1,:) .* p(2,:) - 32 .* beta .* m1 ./ R .^ 4 ) ./ p(1,:);
end
And I am using bvpinit with this command:
solinit = bvpinit(linspace(0,pi,10),@mat4init , [2 1]);
and after that calling bvp4c with code:
m0 = 2;
m1 = 1;
z = linspace(0,pi,10);
ri = 0.7;
R = ri - z .* (ri - 1);
beta = 1;
sol = bvp4c(@matrix4ode,@mat4bc,solinit);
I got error:
Error using matrix4ode
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);
How when I have not additional input arguments in matrix4ode function? What should I do?

Ameer Hamza on 2 Apr 2020
First, you don't need to pass the third argument to bvpinit unless you are solving a parametric boundary value problem. Change the line to
solinit = bvpinit(linspace(0,pi,10),@mat4init);
This will solve the current issue, but there are other issues in your code. The ODE matrix4ode should return a column vector, but your function returns a matrix. If you can show the mathematical equation of your problem, maybe I will be able to suggest a solution to this issue too.
##### 2 CommentsShowHide 1 older comment
Ameer Hamza on 3 Apr 2020
Your code shows that the boundary conditions are between 0 and 1. How do you expect to find values at z=2,3,4...,9? Check the following code and compare with your original code to see the difference
solinit = bvpinit(linspace(0,1,10),@mat4init, [2 1]);
sol = bvp4c(@matrix4ode,@mat4bc,solinit);
plot(sol.x, sol.y);
function dpdz = matrix4ode(z, p, params)
m0 = params(1);
m1 = params(2);
ri = 0.7;
R = ri - z .* (ri - 1);
beta = 1;
dpdz = zeros(2, size(z,2));
dpdz(1,:) = - 32 .* beta .* m0 ./ (R .^ 4 .* p(1));
dpdz(2,:) = -( - 8 .* dpdz(1) ./ R - dpdz(1) .* p(2) - 32 .* beta .* m1 ./ R .^ 4 ) ./ p(1);
end
function pinit = mat4init(z)
pinit = [ 0.65.*cos(z)
0.65.*cos(z) ];
end
function res = mat4bc(pa, pb, params)
res = [ pa(1,:)-8
pb(1,:)-1
pa(2,:)
pb(2,:) ];
end

### Categories

Find more on Boundary Value Problems 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!

Translated by