I am having trouble with a code in a two points boundary value problems.
??? Error using ==> bvpinit at 73
The entries of x must satisfy a = x(1) ~= x(end) = b.
Error in ==> polymer at 6
solinit = bvpinit(linspace(0,0.1,1.5),ones(3,1),1);
shown and I think it maybe a problem with the boundary conditions.
below is my code:
function polymer
clc,clf
B = 0 ;
options = [];
solinit = bvpinit(linspace(0,0.1,1.5),ones(3,1),1);
sol = bvp4c(@polymerode,@polymerbc,solinit,options,B);
clf reset
plot(sol.x,sol.y(2,:));
drawnow
%====================================================
function dydx = polymerode(x,y,T,B)
dydx = [ y(1)*(-0.5/y(2)*y(3)-0.25*(1+(y(3))^2)*(T+(y(2))^2*B))
y(3)
(6*y(3)+y(2)*(1+(y(3))^2)*(T-3*(y(2))^2*B))/(2*(y(2))^2*(T+(y(2))^2*B))];
end
% -------------------------------------------------------------------------
function res = polymerbc(ya,yb,T,B)
res = [ya(1) - 2
ya(2) - 1
yb(3)];
end
%====================================================
end
This is very important for me, can anyone help me???
Thanks so mush
Maybe you meant (0,1.5,15) ? With your settings for linspace, you will
only choose one discretization point in the interval [0,0.1] for the
independent variable.
Best wishes
Torsten.
Thx for your help, but I still can't make even using (0,1.5,15). BTW what do you mean was the "only choose one discretization point in the interval[0,0.1]"?
Cite:
y = linspace(a,b,n) generates a row vector y of n points linearly
spaced between and including a and b.
For n < 2, linspace returns b.
You set linspace(0,0.1,1.5). Since 1.5 < 2 , your command will result
in a grid of only one point, namely 0.1.
This explains the error message that x(1) must be different from
x(end).
Best wishes
Torsten.
Thank so much, I get your meaning now. I adjusted it to :
solinit = bvpinit(linspace(0,2,20),ones(3,1),1);
The result should be a grid of 20 points, from 0 to 2.
But I can't get the result as another errors.
Here's wt I get:
??? Error using ==> bvparguments at 126
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT,P1,P2...):
The boundary condition function BCFUN should return a column vector of
length 4.
Error in ==> bvp4c at 128
[n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Error in ==> polymer at 8
sol = bvp4c(@polymerode,@polymerbc,solinit,options,B);
Here's my MATLAB code:
function polymer
clc,clf
B = 0 ;
options = [];
solinit = bvpinit(linspace(0,2,20),ones(3,1),1);
sol = bvp4c(@polymerode,@polymerbc,solinit,options,B);
%===================================================
function dydx = polymerode(x,y,T,B)
dydx = [ y(1)*(-0.5/y(2)*y(3)-0.25*(1+(y(3))^2)*(T+(y(2))^2*B))
y(3)
(6*y(3)+y(2)*(1+(y(3))^2)*(T-3*(y(2))^2*B))/(2*(y(2))^2*(T+(y(2))^2*B))];
end
% -------------------------------------------------------------------------
function res = polymerbc(ya,yb,T,B)
res = [ya(1) - 2
ya(2) - 1
yb(3)];
end
%====================================================
end
Thank again for all of your help.
Best regard
T = ...;
> options = [];
> solinit = bvpinit(linspace(0,2,20),ones(3,1),1);
>
solinit = bvpinit(linspace(0,2,20),ones(3,1));
> sol = bvp4c(@polymerode,@polymerbc,solinit,options,B);
>
sol =
bvp4c(@(x,y)polymerode(x,y,T,B),@(ya,yb)polymerbc(yxa,yb,T,B),solinit,options);
> %===================================================
> function dydx = polymerode(x,y,T,B)
> dydx = [ y(1)*(-0.5/y(2)*y(3)-0.25*(1+(y(3))^2)*(T+(y(2))^2*B))
> y(3)
> (6*y(3)+y(2)*(1+(y(3))^2)*(T-3*(y(2))^2*B))/(2*(y(2))^2*(T+(y(2))^2*B))];
> end
>
> % -------------------------------------------------------------------------
> function res = polymerbc(ya,yb,T,B)
> res = [ya(1) - 2
> ya(2) - 1
> yb(3)];
>
> end
> %====================================================
> end
> Thank again for all of your help.
> Best regard- Zitierten Text ausblenden -