首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maple:如何插入命令来强制我的代码选择随机整数值来查找我的值?

Maple:如何插入命令来强制我的代码选择随机整数值来查找我的值?
EN

Stack Overflow用户
提问于 2016-01-30 23:08:28
回答 1查看 101关注 0票数 2
代码语言:javascript
复制
                (x - 7)  + (y - 2)  = 100  and                             2          2
代码语言:javascript
复制
                (x - 11)  + (y - 5)  = 75  accurate to 25 digits. Plot these two circles in two colors showing their 2 real intersection points. 

我的代码在寻找这两个圆的交点的真正值点方面做得非常好。不过,我是用这两个圆的图像来确定我的猜测值。现在对于复杂的交叉点,我必须简单地猜测和检查可能的解决方案。然而,这是愚蠢而乏味的。

我想知道的是如何创建一个循环,该循环生成一对复数,运行下面的算法/for循环,如果它与先前的解决方案匹配,则再次开始循环。

代码语言:javascript
复制
f := (x-7)^2+(y-2)^2-100;
                          2          2      
                   (x - 7)  + (y - 2)  - 100
g := (x-11)^2+(y-5)^2-75;
                           2          2     
                   (x - 11)  + (y - 5)  - 75
with(plots);
plotf := implicitplot(f, x = -25 .. 25, y = -25 .. 25, color = blue, thickness = 1);
plotg := implicitplot(g, x = -25 .. 25, y = -25 .. 25, color = red, thickness = 1);
display(plotg, plotf);

x[0] := 5.0;
                              5.0
y[0] := 11.0;
                              11.0
X[0] := [x[0], y[0]];
                          [5.0, 11.0]
with(linalg);
G := unapply(convert(evalm((Vector(2, {(1) = x, (2) = y}))-1/jacobian([f, g], [x, y]) . (Vector(2, {(1) = f, (2) = g}))), list), x, y);
                   [        /       2          2      \
                   [(y - 5) \(x - 7)  + (y - 2)  - 100/
         (x, y) -> [-----------------------------------
                   [        2 (3 x - 4 y - 13)         

                      /        2          2     \      
              (y - 2) \(x - 11)  + (y - 5)  - 75/      
            - ----------------------------------- + x, 
                      2 (3 x - 4 y - 13)               
                    /       2          2      \
           (x - 11) \(x - 7)  + (y - 2)  - 100/
         - ------------------------------------
                    2 (3 x - 4 y - 13)         

                      /        2          2     \    ]
              (x - 7) \(x - 11)  + (y - 5)  - 75/    ]
            + ----------------------------------- + y]
                      2 (3 x - 4 y - 13)             ]
for K to 10 while `and`(evalf(abs(X[K-1][1]-X[K-2][1]), 25) <> 0, evalf(abs(X[K-1][2]-X[K-2][2]), 25) <> 0) do X[K] := evalf(G(X[K-1][1], X[K-1][2]), 25) end do;
    [5.749999999999999999999999, 12.00000000000000000000000]
    [5.803571428571428571428572, 11.92857142857142857142857]
    [5.803847569955817378497791, 11.92820324005891016200295]
    [5.803847577293368114236941, 11.92820323027550918101742]
    [5.803847577293368119417657, 11.92820323027550917410978]
    [5.803847577293368119417661, 11.92820323027550917410978]
X[0] := [17, -2];
                            [17, -2]
for K to 20 while `and`(evalf(abs(X[K-1][1]-X[K-2][1]), 25) <> 0, evalf(abs(X[K-1][2]-X[K-2][2]), 25) <> 0) do X[K] := evalf(G(X[K-1][1], X[K-1][2]), 25) end do;
   [16.21739130434782608695652, -1.956521739130434782608696]
   [16.19619565217391304347826, -1.928260869565217391304346]
   [16.19615242288645448220352, -1.928203230515272642938024]
   [16.19615242270663188058545, -1.928203230275509174113935]
   [16.19615242270663188058234, -1.928203230275509174109784]
   [16.19615242270663188058234, -1.928203230275509174109785]
X__0 := [170.0-1.*I, 270.0*I];
                    [170.0 - 1. I, 270.0 I]
for K to 20 while `and`(evalf(abs(X[K-1][1]-X[K-2][1]), 25) <> 0, evalf(abs(X[K-1][2]-X[K-2][2]), 25) <> 0) do X[K] := evalf(G(X[K-1][1], X[K-1][2]), 25) end do;
   [16.21739130434782608695652, -1.956521739130434782608696]
   [16.19619565217391304347826, -1.928260869565217391304346]
   [16.19615242288645448220352, -1.928203230515272642938024]
   [16.19615242270663188058545, -1.928203230275509174113935]
   [16.19615242270663188058234, -1.928203230275509174109784]
   [16.19615242270663188058234, -1.928203230275509174109785]
EN

回答 1

Stack Overflow用户

发布于 2016-02-04 10:26:14

请看我稍后对你的回答,related question

在这个答案中,我创建了一个为给定范围生成随机浮点数的过程。我不确定为什么您会坚持使用整数起点,但是您可以很容易地修改我答案中的代码来实现这一点。您可以像这样简单地定义过程fgen

代码语言:javascript
复制
fgen := proc(a::numeric,b::numeric,i::nonnegint:=1)
  seq(RandomTools:-Generate(integer('range'=a..b)),
      ii=1..i);
end proc:

fgen(-100, 100); # Usage example, a random point

                           15

fgen(-100, 100, 8);

           81, 64, -7, 91, -87, -81, -66, 19
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35103336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档