Search code examples
matlabmathoctavedifferential-equations

Lsode throwing INTDY-- T (=R1) ILLEGAL and invalid input detected


I have my function:

function [result] = my_func(x,y)
  result = y^2*(1-3*x)-3*y;
endfunction

Also, my vector with Ts, my function address and my initial variable x_0

load file_with_ts
# Add my limits as I also want to calculate those 
# (all values in file_with_ts are within those limits.)
t_points = [-1, file_with_ts, 2]
myfunc = str2func("my_func")
x_0 = 0.9142

I am trying to execute the following line:

lsode_d1 = lsode(myfunc, x_0, t_points)

And expecting a result, but getting the following error:

 INTDY--  T (=R1) ILLEGAL
      In above message,  R1 =  0.7987082301475D+00
       T NOT IN INTERVAL TCUR - HU (= R1) TO TCUR (=R2)
      In above,  R1 =  0.8091168896311D+00   R2 =  0.8280400838323D+00
 LSODE--  TROUBLE FROM INTDY. ITASK = I1, TOUT = R1
      In above message,  I1 =         1
      In above message,  R1 =  0.7987082301475D+00
error: lsode: invalid input detected (see printed message)
error: called from
    main at line 20 column 10

Also, the variable sizes are:

x_0 -> 1x1

t_points -> 1x153

myfunc -> 1x1

I tried transposing the t_points vector

using @my_func instead of the str2func function

I tried adding multiple variables as the starting point (instead of x_0 I entered [x_0; x_1])

Tried changing my function header from my_func(x, y) to my_func(y, x)

Read the documentation and confirmed that my_func allows x to be a vector and returns a vector (whenever x is a vector).

EDIT: T points is the following 1x153 matrix (with -1 and 2 added to the beggining and the end respectively):

-4.9451e-01 -4.9139e-01 -4.7649e-01 -4.8026e-01 -4.6177e-01 -4.5412e-01 -4.4789e-01 -4.2746e-01 -4.1859e-01 -4.0983e-01 -4.0667e-01 -3.8436e-01 -3.7825e-01 -3.7150e-01 -3.5989e-01 -3.5131e-01 -3.4875e-01 -3.3143e-01 -3.2416e-01 -3.1490e-01 -3.0578e-01 -2.9267e-01 -2.9001e-01 -2.6518e-01 -2.5740e-01 -2.5010e-01 -2.4017e-01 -2.3399e-01 -2.1491e-01 -2.1067e-01 -2.0357e-01 -1.8324e-01 -1.8112e-01 -1.7295e-01 -1.6147e-01 -1.5424e-01 -1.4560e-01 -1.1737e-01 -1.1172e-01 -1.0846e-01 -1.0629e-01 -9.4327e-02 -8.0883e-02 -6.6043e-02 -6.6660e-02 -6.1649e-02 -4.7245e-02 -2.8332e-02 -1.8043e-02 -7.7416e-03 -6.5142e-04 1.0918e-02 1.7619e-02 3.4310e-02 3.3192e-02 5.2275e-02 5.5756e-02 6.8326e-02 8.2764e-02 9.5195e-02 9.4412e-02 1.1630e-01 1.2330e-01 1.2966e-01 1.3902e-01 1.4891e-01 1.5848e-01 1.7012e-01 1.8026e-01 1.9413e-01 2.0763e-01 2.1233e-01 2.1895e-01 2.3313e-01 2.4092e-01 2.4485e-01 2.6475e-01 2.7154e-01 2.8068e-01 2.9258e-01 3.0131e-01 3.0529e-01 3.1919e-01 3.2927e-01 3.3734e-01 3.5841e-01 3.5562e-01 3.6758e-01 3.7644e-01 3.8413e-01 3.9904e-01 4.0863e-01 4.2765e-01 4.2875e-01 4.3468e-01 4.5802e-01 4.6617e-01 4.6885e-01 4.7247e-01 4.8778e-01 4.9922e-01 5.1138e-01 5.1869e-01 5.3222e-01 5.4196e-01 5.4375e-01 5.5526e-01 5.6629e-01 5.7746e-01 5.8840e-01 6.0006e-01 5.9485e-01 6.1771e-01 6.3621e-01 6.3467e-01 6.5467e-01 6.6175e-01 6.6985e-01 6.8091e-01 6.8217e-01 6.9958e-01 7.1802e-01 7.2049e-01 7.3021e-01 7.3633e-01 7.4985e-01 7.6116e-01 7.7213e-01 7.7814e-01 7.8882e-01 8.1012e-01 7.9871e-01 8.3115e-01 8.3169e-01 8.4500e-01 8.4168e-01 8.5705e-01 8.6861e-01 8.8211e-01 8.8165e-01 9.0236e-01 9.0394e-01 9.2033e-01 9.3326e-01 9.4164e-01 9.5541e-01 9.6503e-01 9.6675e-01 9.8129e-01 9.8528e-01 9.9339e-01


Solution

  • Credits to Lutz Lehmann and PierU.

    The problem lied in the array t_points not being a monotonous array. Adding a sort(t_points) before doing any calculations fixed the error.