MATLAB: Coupled differential equation with constant coefficients

bvp4code

here 'kappa' and 'sigma' are constants. The boundary conditions are;
R(-1)=1
S(1)=0
kappa=1.
I tried it using dsolve but the graph obtained werenot correct. If anyone can solve it using bvp4c in the region (0,2) , it would be of great help.

Best Answer

This code solves the given BV problem. See the documentation for details.
x = linspace(-1, 1, 100);
init = bvpinit(x, [0; 0]);
sol = bvp4c(@odeFun, @bvFun, init);
subplot(2,1,1);
plot(sol.x, real(sol.y));
title('real(sol)');
legend({'R', 'S'})
subplot(2,1,2);
plot(sol.x, imag(sol.y));
title('imaginary(sol)');
legend({'R', 'S'})
function dRSdz = odeFun(z, RS)
sigma = 1;
kappa = 2;
dRdz = 1i*sigma*RS(1) + 1i*kappa*RS(2);
dSdz = -1i*sigma*RS(2) - 1i*kappa*RS(1);
dRSdz = [dRdz; dSdz];
end
function res = bvFun(RSa, RSb)
res = [RSa(1)-1;
RSb(2)-0];
end