Wolfram mathematica 根在间隔中

Wolfram mathematica 根在间隔中,wolfram-mathematica,intervals,Wolfram Mathematica,Intervals,请帮我修一下线路! 行“For..”工作并打印不包含根的间隔。 我必须输出剩余的区间,其中包括根。(我知道这些间隔应为2) 我试过但它不知何故是错的:( X={-2,6} 其中,1.35785,1.3407,1.407,1.347,1.35785,1.3407,1.347,1.24657,1.24657,1.24655,1.24655,1.229941,1.29941,1.781-1.1-1.90577,1.90577-1.90577,1.1-1.1-1.1-1-1.1-1-1-1.11811,

请帮我修一下线路! 行“
For..
”工作并打印不包含根的间隔。 我必须输出剩余的区间,其中包括根。(我知道这些间隔应为2) 我试过
但它不知何故是错的:(

X={-2,6}
其中,1.35785,1.3407,1.407,1.347,1.35785,1.3407,1.347,1.24657,1.24657,1.24655,1.24655,1.229941,1.29941,1.781-1.1-1.90577,1.90577-1.90577,1.1-1.1-1.1-1-1.1-1-1-1.11811,1.1-1.1.1.901-1-1-1-1-1-1-1-1-1.781-1-1-1-1-1-1-1-1-1-1.781-1-1-1-1-1-1-1-1-1-1-1-1-1-1.781-1-1-1-1-1-1-1-1-1-1-1.901 4.75,5,5.25,5.5,5.75,6}
spfw={33.3632, 43.263, 51.6709, 55.5421, 57.1266, 57.2511, 57.3756,58.059, 58.0778, 58.1995,56.846,55.1903,54.5739,53.0828,51.1542,48.9959,48.0325,42.2533, 36.408,30.7952,30.1551,28.6446,23.138,19.4168,6.47053,5.90328,5.32951,-0.513959, -0.750527, -6.38895, -6.39157, -6.39418,-6.36456, -6.09357, -6.28599, -5.25369, -4.19539, -2.18625, -0.133803,2.90414, 6.171}
spfn={33.3632, 40.2933, 46.5882, 51.9781, 55.5583, 55.5708, 55.5762, 55.4604, 55.4393, 55.0045, 530116, 51.1309, 50.4546, 48.1226, 45.6012, 43.402, 42.066, 37.5522, 32.6864, 28.1979, 28.0685,25.7067, 17.5943,13.5547, -2.97428, -3.21054, -3.36422, -5.05466, -5.1301, -6.4392,-6.76879, -6.48231, -7.20196, -7.00719, -7.53373, -6.00246, -4.41058,-2.8187, -1.16621, 2.35765, 6.04694}
对于[i=1,i
您可以使用
否定整个逻辑表达式:

 If[! (((0 < spfn[[i]]) && (0 < spfn[[i + 1]])) ||
       ((spfw[[i]] < 0) && (spfw[[i + 1]] < 0))), 
    Print["1) exist some roots on: {", spx[[i]], ";", spx[[i + 1]], "}"]]
…一旦您学会使用mathematica的面向对象编程方法:

 First /@ Select[ 
         Transpose[
        Partition[#, 2, 1] & /@ {spx, spfn, spfw}]  , 
      ! ((#[[2, 1]] > 0  && #[[2, 2]] > 0) || 
        (#[[3, 1]] < 0  && #[[3, 2]] < 0)) & ]
First/@Select[
转置[
分区[#,2,1]&/{spx,spfn,spfw}],
! ((#[[2, 1]] > 0  && #[[2, 2]] > 0) || 
(#[[3, 1]] < 0  && #[[3, 2]] < 0)) & ]
(*{2.11731,2.5},{2.5,2.5625},{2.5625,2.625},{2.625, 3.3125},{5.5,5.75}}*)

 If[((0 < spfn[[i]]) && (0 < spfn[[i + 1]])) || 
    ((spfw[[i]] < 0) && (spfw[[i + 1]] < 0)), 
   Print["1) exist no roots on: {", spx[[i]], ";", spx[[i + 1]], "}"],
   Print["2) exist  roots on: {", spx[[i]], ";", spx[[i + 1]], "}"]]
 First /@ Select[ 
         Transpose[
        Partition[#, 2, 1] & /@ {spx, spfn, spfw}]  , 
      ! ((#[[2, 1]] > 0  && #[[2, 2]] > 0) || 
        (#[[3, 1]] < 0  && #[[3, 2]] < 0)) & ]