如何联合间隔?(How to unite intervals?)

编程入门 行业动态 更新时间:2024-10-27 14:20:40
如何联合间隔?(How to unite intervals?)

请帮助我 团结一致的间隔

“ For... ”行输出根存在的区间(根:2.94和5,52)。 我要考虑一句话

如果在区间{x * [i],x [i + 1]}和{x [i + 1]中,x ** [i + 1]}可以是等式的根,则范围{x * [ i],x ** [i + 1]}必须至少有一个根。

X = {-2, 6} spx = {-2, -1.90577, -1.81153, -1.59327, -1.375, -1.35785, -1.3407, -1.24655, -1.22941, -1.11811, -0.934054, -0.80167, -0.75, -0.625,-0.5, -0.25, -0.0981238, 0.303752, 0.651876, 0.94833, 1, 1.5, 1.75,2.11731, 2.5, 2.5625, 2.625, 3.3125, 3.75, 4, 4.00964, 4.01928,4.25964, 4.36731, 4.5, 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} For[i = 1, i < Length@spfn, i++, If[! (((0 < spfn[[i]]) && (0 < spfn[[i + 1]])) || ((spfw[[i]] < 0) && (spfw[[i + 1]] < 0))), Print["1) exists root on: {", spx[[i]], ";", spx[[i + 1]], "}"]]]

所以结果包括5个区间:

1) exists root on: {2.11731;2.5} 1) exists root on: {2.5;2.5625} 1) exists root on: {2.5625;2.625} 1) exists root on: {2.625;3.3125} 1) exists root on: {5.5;5.75}

并且由于第一个根是2.94,它必须进入4个第一个区间,最后一个区间为5.52。 因此,在考虑该注释后,该行应输出两个间隔。 我试图使用IntervalUnion但它不起作用:(请帮我在这行编写这个注释。

Help me please to unite resulted intervals!

The line "For..." outputs the intervals where the roots exist (roots: 2.94 and 5,52). I have to consider a remark:

If in the intervals {x*[i],x[i+1]} and {x[i+1],x**[i+1]} can be the roots of the equation, the range {x*[i],x**[i+1]} must have at least one of its root.

X = {-2, 6} spx = {-2, -1.90577, -1.81153, -1.59327, -1.375, -1.35785, -1.3407, -1.24655, -1.22941, -1.11811, -0.934054, -0.80167, -0.75, -0.625,-0.5, -0.25, -0.0981238, 0.303752, 0.651876, 0.94833, 1, 1.5, 1.75,2.11731, 2.5, 2.5625, 2.625, 3.3125, 3.75, 4, 4.00964, 4.01928,4.25964, 4.36731, 4.5, 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} For[i = 1, i < Length@spfn, i++, If[! (((0 < spfn[[i]]) && (0 < spfn[[i + 1]])) || ((spfw[[i]] < 0) && (spfw[[i + 1]] < 0))), Print["1) exists root on: {", spx[[i]], ";", spx[[i + 1]], "}"]]]

So the result include 5 intervals:

1) exists root on: {2.11731;2.5} 1) exists root on: {2.5;2.5625} 1) exists root on: {2.5625;2.625} 1) exists root on: {2.625;3.3125} 1) exists root on: {5.5;5.75}

And as the first root is 2.94 it has to enter into 4 first intervals, and 5.52 in the last. So after considering the remark, that line should outputs two intervals. I tried to use IntervalUnion but it doesn't work:( Please help me to code this remark in this line.

最满意答案

修改后的答案。 有关## &[]说明,请参阅此链接 。

spxpairs = Interval /@ Partition[spx, 2, 1]; spfwpairs = Interval /@ Partition[spfw, 2, 1]; spfnpairs = Interval /@ Partition[spfn, 2, 1]; ans = Apply[IntervalUnion, If[Not[0 < Min@#1 || Max@#2 < 0], #3, ## &[]] & @@@ Transpose[{spfnpairs, spfwpairs, spxpairs}]]; Column[Prepend[List @@ ans, "Roots exist on :"], Spacings -> 1]

根源存在于:

{2.11731,3.3125}

{5.5,5.75}

Revised answer. See this link for explanation of ## &[].

spxpairs = Interval /@ Partition[spx, 2, 1]; spfwpairs = Interval /@ Partition[spfw, 2, 1]; spfnpairs = Interval /@ Partition[spfn, 2, 1]; ans = Apply[IntervalUnion, If[Not[0 < Min@#1 || Max@#2 < 0], #3, ## &[]] & @@@ Transpose[{spfnpairs, spfwpairs, spxpairs}]]; Column[Prepend[List @@ ans, "Roots exist on :"], Spacings -> 1]

Roots exist on :

{2.11731, 3.3125}

{5.5, 5.75}

更多推荐

本文发布于:2023-08-07 20:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465664.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间隔   unite   intervals

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!