使用八度音阶的tan函数的常微分方程显示错误

时间:2015-09-11 06:42:21

标签: octave ode

我尝试使用octave4求解一个常微分方程。它对于sin和余弦函数都很好。但是对于tan来说它显示错误

 # Define the right-hand side of the equation:
function ret=f(y,x);ret=tan(x) ;end;
# x will be on the interval [0,1]; y(0)=0.5
# x will be the set of moments of time:
# ywill be the values of the function at these moments of time.
y=lsode ('f', 5, (x=linspace(0,100,100)));
plot(x,y)

-------------------------------------------- ---------------------------------- 错误

 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.6201527144160D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.6201527144160D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.6758957986520D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7056317233321D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7210002414438D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7288235178363D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7327811043353D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7347822361589D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7357991952018D-16
 LSODE--  WARNING..INTERNAL T (=R1) AND H (=R2) ARE
       SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP
       (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY
      In above,  R1 =  0.1570796326795D+01   R2 =  0.7363225763750D-16
 LSODE--  ABOVE WARNING HAS BEEN ISSUED I1 TIMES.
       IT WILL NOT BE ISSUED AGAIN FOR THIS PROBLEM
      In above message,  I1 =        10

请帮我解决tan函数的常微分方程。

1 个答案:

答案 0 :(得分:1)

我认为你的问题非常简单 - tan 函数在 x = pi / 2 + pi * k 处有不连续性。更改x的定义。这段代码效果很好:

x=linspace(0,pi/2-0.01,100);
y=lsode ('f', 5, x);
plot(x,y);