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?