I am trying to solve coupled differential equations using NDsolve. I am getting an error which says Boundary conditions not numerical. I am not sure about my mistake. Can I get some help? My code is as follows


    a = 1*10^10;
    b = -2*10^7;
    n = 11167.3;
    Subscript[L, i] = 0.4814*10^-3;
    Subscript[z, 1] = 0.25*10^-3;
    Subscript[z, 2] = 1.75*10^-3;
    a1 = 1;

    q[z_] := a*z^2 + b*z + n;(*Functional form of \[CapitalDelta]\[Beta]*)

    g = \[Pi]/Subscript[L, i];(*Subscript[\[CapitalDelta]\[Beta], NA]*)
    \[Kappa][z_, c_] := 
     c*(g - q[z]);(*constant\[Times](Subscript[\[CapitalDelta]\[Beta], \
    NA]-Subscript[\[CapitalDelta]\[Beta], MAX])*)
    eq1[z_, c_] := Ar1'[z] == I*\[Kappa][z, c]*Ar2[z, c]*Exp[-I*q[z]*z]
    eq2[z_, c_] := Ar2'[z] == I*\[Kappa][z, c]*Ar1[z, c]*Exp[+I*q[z]*z]
    syst = NDSolve[{eq1[z, c], eq2[z, c], Ar1[Subscript[z, 1]] == 1, 
       Ar2[Subscript[z, 2]] == 0}, {Ar1, Ar2}, {z, Subscript[z, 1], 
       Subscript[z, 2]}, {c, 0, 2}, MaxSteps -> \[Infinity]]


1 Answer 1


All these problems can be easily found if each statement is evaluated on its own and by looking at the output before going to the next statement. Then you'd see what the problem is instead of throwing all the code into one statement which makes it hard to see what is wrong

a = 3*10^10
b = -1*10^7
c = 11167.3
Subscript[L, i] = 0.4814*10^-3
Subscript[z, 1] = 0.25*10^-3
Subscript[z, 2] = 1.75*10^-3
q[z_] := a*z^2 + b*z + c
g = \[Pi]/Subscript[L, i]
\[Kappa][z_] := n*(g - q[z])

Mathematica graphics

So far OK. Now the next one

bc = {Ar1[Subscript[z, 1]] == a1, Ar2[Subscript[z, 2]] == 0}

Mathematica graphics

Opps, we already see something wrong. What is a1? Now the next one

ode = {Ar1'[z] == I*\[Kappa][z]*Ar2[z]*Exp[-I*q[z]*z], 
  Ar2'[z] == I*\[Kappa][z]*Ar1[z]*Exp[+I*q[z]*z]}

Mathematica graphics

Opps, we see anther problem. What is n in there? it has no value. Next

 syst = NDSolve[{ode, bc}, {Ar1, Ar2}, {z, Subscript[z, 1], Subscript[z, 2]}]

Gives the errors you mentioned. So from the above, it is clear what the error is. You need numerical values for n and a1

a1 = 1; n = 1;
syst = NDSolve[{ode, bc}, {Ar1, Ar2}, {z, Subscript[z, 1], Subscript[z, 2]}]

Mathematica graphics

  • $\begingroup$ @Naseer Thanks for your valuable comments. a1 is my input and n is going to be my fitting parameter. I am trying to find Ar1 and Ar2 at Z2. $\endgroup$ Aug 27, 2019 at 21:24
  • $\begingroup$ @Naseer I changed according to your suggestion. I have also made some changes in the code. c is my fitting parameter. I want to solve the coupled equation and plot absolute value of (Ar2/Ar1)^2 as a function of c. There is some obvious mistake in my code as it says "The length of the derivative operator Derivative in Ar'[z] is not same as the number of arguments. $\endgroup$ Aug 27, 2019 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.