Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BVP4C for 2 points boundary value problems and boundary conditions

227 views
Skip to first unread message

Ka Lun

unread,
Apr 8, 2011, 10:54:05 AM4/8/11
to
Hey Matlab Peeps,

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

Torsten

unread,
Apr 11, 2011, 2:32:25 AM4/11/11
to

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.

Ka Lun

unread,
Apr 18, 2011, 10:27:06 AM4/18/11
to
Torsten <Torsten...@umsicht.fraunhofer.de> wrote in message <c178e17f-091b-4cf9...@w7g2000yqe.googlegroups.com>...

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]"?

Torsten

unread,
Apr 18, 2011, 10:49:38 AM4/18/11
to
On 18 Apr., 16:27, "Ka Lun " <lunmr...@gmail.com> wrote:
> Torsten <Torsten.Hen...@umsicht.fraunhofer.de> wrote in message <c178e17f-091b-4cf9-8419-4f0cbf04a...@w7g2000yqe.googlegroups.com>...
> 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]"?- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

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.


Ka Lun

unread,
Apr 19, 2011, 7:54:04 AM4/19/11
to
Torsten <Torsten...@umsicht.fraunhofer.de> wrote in message <20821bbf-651d-4ba1...@l30g2000vbn.googlegroups.com>...

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

Torsten

unread,
Apr 19, 2011, 10:34:07 AM4/19/11
to
>
> 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 ;
>

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 -

0 new messages