Solving BVP for nonlinear ODE in Nsp

13 views
Skip to first unread message

Rainer von Seggern

unread,
Aug 30, 2010, 6:14:14 AM8/30/10
to tumbi
Hello
I'm new in this group, and my first steps in learning Nsp are by
starting to solve boundary value problems for nonlinear ordinary
differential equations by spline collocation. Since it may be of
interest I give here a very first result.
Rainer

// Nonlinear boundary value problem:
// y''=2*y^3; y(0)=1; y'(1)=-1/4
// Solution: y(x)=1/(1+x)
// Numerical solution by spline collocation.
// The differential equation may be implicit of order three,
// and it should be simple to extend the method to systems.

nk=21;x=linspace(0,1,nk)';
n=100;xp=linspace(0,1,n)';
y0=ones(nk,1);
d0=splin(x,y0);
p0=[y0;d0];

function lhs = DEQ(x,y,y1,y2,y3)
lhs=y2-2*y.^3;
endfunction

function lhs = LBC(a,y,y1,y2)
lhs=log(y(1)); // lhs=y(1)-1;
endfunction

function lhs = RBC(b,y,y1,y2)
lhs=exp(y1($)+1/4)-1; // lhs=y1($)+1/4
endfunction

function z=res(p)
yy=p(1:nk,1);
d=p(nk+1:$,1);
[yp,yp1,yp2,yp3]=interp(xp,x,yy,d);
z=[DEQ(x,yp,yp1,yp2);LBC(0,yp);RBC(1,yp,yp1)];
endfunction

p1=fsolve_lsq(p0,res,n+2);
y1=p1(1:nk,1);d1=p1(nk+1:$,1);
[yp,yp1,yp2,yp3]=interp(xp,x,y1,d1);

function y=yex(x), y=1./(x+1); endfunction
function y=yex1(x), y=-1./((x+1).^2); endfunction

plot2d(xp,[yp-yex(xp),yp1-yex1(xp)],leg='yp-yex@yp1-yex1');

bruno

unread,
Aug 31, 2010, 6:07:35 AM8/31/10
to tumbi
> Hello
> I'm new in this group, and my first steps in learning Nsp are by
> starting to solve boundary value problems for nonlinear ordinary
> differential equations by spline collocation. Since it may be of
> interest I give here a very first result.
> Rainer
>

Thanks Rainer, this looks interesting and could complete one
missed feature of nsp. Btw in your exemple n seems to be
the number of collocation points so should not be depending
on nk the number of spline intervals ?

Best regards
Bruno
Reply all
Reply to author
Forward
0 new messages