0

I need to solve two differential equations, where I have two boundary conditions for every equation. Because of that I choose Matlab method bvp4c to solve this system:

p1' = -32 * beta * m1 / (R ^ 4 * p1) p2' = - ( - 8 * p1' / R - p1' * p2 - 32 * beta * m2 / R ^ 4 ) / p1

I have function file bvpfcn.m where I defined two differential equations:

function dpdz = bvpfcn(z,p)

beta = 1;
m1 = 1;
m2 = 0.1;
ri = 0.7;
z = linspace(0,1,1001);
R = ri - z .* (ri - 1);

dpdz = zeros(2,1001);
dpdz = [- 32 .* beta .* m0 ./ (R .^ 4 .* p(1));
       -( - 8 .* dpdz(1) ./ R - dpdz(1) .* p(2) - 32 .* beta .* m1 ./ R .^ 4 ) ./ p(1);
];
end

Then in function file bcfcn.m I defined boundary conditions. My boundary conditions are:

p(1)|(z=0) = 8

p(1)|(z=1) = 1

p(2)|(z=0) = 0

p(2)|(z=1) = 0

And file bcfcn.m is:

function res = bcfcn(pa,pb)
res = [pa(1)-8; 
       pa(2);
       pb(1)-1;
       pb(2)];
end

My solution need to be of shape: shape of expected solution

Because of that shape I am making guess function of cosine type:

function g = guess(z)
g = [0.65.*cos(z)
     0.65.*cos(z)];
end

When I execute everything with:

beta = 1;
m1 = 1;
m2 = 0.1;
ri = 0.7;
xmesh = linspace(0,1,1001);
solinit = bvpinit(xmesh, @guess);
sol = bvp4c(@bvpfcn, @bcfcn, solinit);

I got error:

Error using bvparguments (line 111)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
  The boundary condition function BCFUN should return a column vector of length 2.
Error in bvp4c (line 130)
    bvparguments(solver_name,ode,bc,solinit,options,varargin);

How can I make column vector when I have 4 boundary conditions? Are my assumpsions ok?

iviviviviv
  • 21
  • 8
  • Please check again carefully your equations. Are they really first order? Is it correct that there is a first derivative on the right side of the second equation? How did you intend to reflect that in code? // Are the parameters fixed by the model or can they be adapted? With 2 free parameters you get the required 4 slots in the boundary conditions. // What is the meaning of the dimension 1001 in the derivatives function? – Lutz Lehmann Mar 25 '20 at 14:35

1 Answers1

0

Your column vector from bvpfcn and bcfcn should have same dimensions. Since you have two first order ODEs, you should give only two boundary conditions. You have two extra boundary conditions, these extra conditions will be dependent on other two. You have to find out the independent boundary conditions