Hello,
How can I solve this boundaries value problem : y''(r) = (k*(k+1)/r^2)*y(r)-((2*k+1)/r)*f_1(r)*f_2(r)
where :
- r is defined as r=0:dr:r_max with dr and r_max given.
- y(r) is the function that I need to solve.
- k is a given integer parameter.
- f_1(r) and f_2(r) are two known functions.
The boundaries conditions are the following:
- y(0) = 0
- y'(r_max) = -(k/r_max)*y(r_max)
I have tried solving it using bvp5c but I failed :
iffunction sol=myproblem(dr,r_max,k,f1,f2)r=0:dr:r_max;solinit=bvpinit([0 r_max],[0 0]);sol=bvp5c(@odefun,@bcfun,solinit);end iffunction dydr=odefun(r,y,k,f1,f2,dr)c1=k*(k+1)./r.^2;c1(1)=k*(k+1)./(dr/10)^2; % to avoid dividing by 0
c2=(2*k+1)*f1(:).*f2(:)./r;c2(1)=0; % to avoid dividing by 0dydr=[y(2);c1.*y(1)-c2];endiffunction res=bcfun(ya,yb,k,r_max)res=[ya(1);yb(2)+(k/r_max)*yb(1)];end
In the code above, ignore the if, I can not remove them without loosing the code format.
thanks in advance,
David
Best Answer