bvp4c: Too many input arguments error

6 Ansichten (letzte 30 Tage)
I G
I G am 31 Mär. 2020
Kommentiert: Ameer Hamza am 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?

Antworten (1)

Ameer Hamza
Ameer Hamza am 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 Kommentare
I G
I G am 2 Apr. 2020
Bearbeitet: I G am 2 Apr. 2020
This is my system of equations:
p0' = - 32 .* beta .* m0 ./ (R .^ 4 .* p0)
p1' = - ( - 8 .* p0' ./ R - p0' .* p1 - 32 .* beta .* m1 ./ R .^ 4 ) ./ p0
I need to get p0 and p1, and m0 and m1 are unknown parameters. Boundary conditions are:
p0(z=0) = 8, p0(z=1) = 1, p1(z=0) = 0, p1(z=1) = 0
where p is expressed as function of logitudinal coordinate z. Values for other variables which are known are:
beta = 1;
ri = 0.7;
z = linspace(0,1,10)
R = ri - z .* (ri - 1);
I am using bvp4c because it has option for solution with unknown parameters, because of m0 and m1 that should be my case, here is documentation about this case.
Questions for your answer:
According to everything, I need matrix as a result, because I need to have values of p0 and p1 in all points of z, that means I will have two solutions p0 and p1, and every of both of them will have the same number of values as z has, for example:
p(1): 1 2 3 4 5 6 7 8 9
p(2): 2 3 4 5 6 7 8 9 1
z: 1 2 3 4 5 6 7 8 9
Where should I give assumption of values for unknown parameters m0 and m1, if you say "you don't need to pass the third argument to bvpinit"?
Ameer Hamza
Ameer Hamza am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by