Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Help with bvp4c
Replies: 3   Last Post: Sep 18, 2013 6:33 PM

 Messages: [ Previous | Next ]
 mecej4 Posts: 3 Registered: 1/19/11
Re: Help with bvp4c
Posted: Sep 18, 2013 6:33 PM

On 9/15/2013 6:31 PM, Midhun wrote:
> Hi all,
>
> I have a 2nd order equation given by:
>
> C" + i/(C+ r) *( C/(C+r) - 1 ) C' - k* C = 0
>
> where C = C(x),
> i, r,k are constants.
>
> Boundary conditions:
> C(0) = 1;
> C'(1) = 1/(1 + r/C).
>
> I was trying to use bvp4c for this problem by converting them to a set
> of ODEs, but couldn't make out how to specify the 2nd boundary condition.
>
> Set of ODEs:
>
> C' = P
> P' = -i/(C+r) * (C/C+r - 1)*P +k*C
>
> BCs : C(0) = 1;
> P(1) = i/(1+r/C)
>
> My code:
>
> solinit = bvpinit([0,1],[0,0]);
> sol = bvp4c(@deriv,@bcs,solinit);
> plot(sol.x,sol.y(1,:),'b-x',sol.x,sol.y(2,:),'g-x');
>
> %------------------
>
> function dYdx = deriv(x,Y)
> i = 1;r = 1;
> k = 1;
> dYdx = zeros(2,1); dYdx(1) = Y(2); dYdx(2) = -i/(Y(1)+r) *
> (Y(1)/(Y(1)+r) - 1)*Y(2) + k * Y(1);
>
> %-----------------
>
> function res = bcs(ya,yb)
> i = 1;
> r = 1;
> res = [ ya(1) - 1 ???? ];
>
> Could anyone help me on I can specify the 2nd B.C which is a function of
> C ?

In your notation, yb(1) and yb(2) in function "res" stand for C(x=1) and
C'(x=1). Hence, you should have

res = [ ya(1) - 1; yb(2) - 1/(1 + r/yb(1)];

HTH -- mecej4

Date Subject Author
9/15/13 Midhun
9/15/13 Nasser Abbasi
9/15/13 Midhun
9/18/13 mecej4