why "The boundary condition function BCFUN should return a column vector of length 4" error message is came?
Show older comments
why "The boundary condition function BCFUN should return a column vector of length 4" error message is came?
function meltbvp_final
global r re p thc gr th e s ha hc k br rd pr en nr t I1 ph Al
Al1=0:.01:.1;
Al=Al1';
x=linspace(0, 1, 150);
y=[0 0 0 0];
solinit = bvpinit(x,y);
sol = bvp4c(@meltode, @meltbc, solinit);
%plot(sol.x, sol.y(3,:), color(i), 'LineWidth',1);
t=sol.x;
y=sol.y;
h=x(2)-x(1);
I=0;
for i=1:2:148
% en(i)=((th-1).^2).*(k+rd.*((th-1).*y(3,i)+1).^3).*(y(4,i).^2)./(((th-1).*y(3,i)+1).^2) ...
% +br.*(e.*y(2,i).^2+ha.^2*s*y(1,i).^2)./((th-1)*y(3,i)+1);
I=I+((th-1).^2).*(k+rd.*((th-1).*y(3,i)+1).^3).*(y(4,i).^2)./(((th-1).*y(3,i)+1).^2) ...
+br.*(e.*y(2,i).^2+ha.^2*s*y(1,i).^2)./((th-1)*y(3,i)+1)...
+4*(((th-1).^2).*(k+rd.*((th-1).*y(3,i+1)+1).^3).*(y(4,i+1).^2)./(((th-1).*y(3,i+1)+1).^2) ...
+br.*(e.*y(2,i+1).^2+ha.^2*s*y(1,i+1).^2)./((th-1)*y(3,i+1)+1))...
+((th-1).^2).*(k+rd.*((th-1).*y(3,i+2)+1).^3).*(y(4,i+2).^2)./(((th-1).*y(3,i+2)+1).^2) ...
+br.*(e.*y(2,i+2).^2+ha.^2*s*y(1,i+2).^2)./((th-1)*y(3,i+2)+1);
end
I1=h*I/3;
plot(Al,I1)
%plot(t,I1)
%axis ([0 5 0 7])
%axis square
%axis tight
xlabel('\eta','FontSize',16);
ylabel('f^\prime(\eta)','FontSize',16);
drawnow
%end
hold off
function dydx = meltode(x,y)
global re p gr th thc e s ha hc k br rd ph pr
re=1;
p=1;
gr=1;
ha=1;
br=1;
rd=1;
ph=.1;
pr=1;
th=1.5;
%Water (base fluid)
rhf=997.1;
cf=4398.56;
kf=0.613;
bf=0.00021 ;
sf=5.5*10^-6;
%Al203 (Alumina)-----------------------------------------------------------
rhs=3970;
cs=765;
ks=40;
bs=.0000085;
ss=35*10^6;
k=(ks+2*kf-2*ph*(kf-ks))/(ks+2*kf+ph*(kf-ks));
r=1-ph+ph*rhs/rhf;
hc=1-ph+ph*(rhs/rhf)*(cs/cf);
e=1/(1-ph)^(2.5);
thc=1-ph+ph*(rhs/rhf)*(bs/bf);
si = ss/sf;
s=1+3*ph*(si-1)/((si+2)-ph*(si-1));
dydx = [ y(2)
(-p-gr*thc*(th-1)*y(3)+re*r*y(2)+s*y(1)*ha*ha)/e
y(4)
(re*pr*hc*y(4)-br*(e*y(2)*y(2)+ha*ha*s*y(1)*y(1))/(th-1)-3*rd*(th-1)*((th-1)*y(3)+1)^2*y(4)*y(4))/(k+rd*((th-1)*y(3)+1)^3)
];
%-----------------------------------------------------------------------
function res = meltbc(ya,yb)
global Al k bi1 bi2 nr th
%Al=.1;
bi1=1;
bi2=1;
nr=1;
res =[ -Al*ya(2)+ya(1)
Al*yb(2)+yb(1)
k*ya(4)-bi1*(ya(3)-1)-nr*(((th-1)*ya(3)+1)^4-th^4)/(th-1)
k*yb(4)+bi2*yb(3)+nr*(((th-1)*yb(3)+1)^4-1)/(th-1)
];
4 Comments
Torsten
on 20 Dec 2017
You will have to include your code for us to see what's going wrong.
Best wishes
Torsten.
Jan
on 20 Dec 2017
As Torsten I'm sure, it is impossible to guess the cause of a problem, if you do not show the code. How could we know which functions you are working with? Please edit the question to insert useful details.
Walter Roberson
on 20 Dec 2017
You probably have the function returning a row vector at the moment instead of a column vector.
Jan
on 21 Dec 2017
@Palash: I've moved the code to the question, because it is not an answer.
Answers (1)
Jan
on 21 Dec 2017
Your Al is a vector:
Al1 = 0:.01:.1;
Al = Al1';
Then inside meltbc:
function res = meltbc(ya,yb)
global Al k bi1 bi2 nr th
%Al=.1;
bi1=1;
bi2=1;
nr=1;
res =[ -Al*ya(2)+ya(1) % <== here
Al*yb(2)+yb(1) % <== here
k*ya(4)-bi1*(ya(3)-1)-nr*(((th-1)*ya(3)+1)^4-th^4)/(th-1)
k*yb(4)+bi2*yb(3)+nr*(((th-1)*yb(3)+1)^4-1)/(th-1)
];
the first two lines create vectors also, such that res has more than 4 elements - as the error message explains clearly.
You can find such problems using the debugger, see https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html: Set a breakpoint in the line which creates res and check what you get instead of the expected [4 x 1] vector.
Categories
Find more on Univariate Discrete Distributions 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!