gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:06:29 26 4
gpt4 key购买 nike

我最初的问题是:使用 Newton-Raphson 算法的多个变量版本找到 2 个圆的所有 4 个(实数和复数)交点 2 2
(x - 7) + (y - 2) = 100 和 2 2
(x - 11) + (y - 5) = 75 精确到 25 位。用两种颜色绘制这两个圆圈,显示它们的 2 个真实交点。

我的代码在找到这两个圆的交点的真正值(value)点方面做得很好。但是,我是根据两个圆圈的图像来确定我的猜测值的。现在对于复杂的交叉点,我必须简单地猜测并检查可能的解决方案。然而,这太无聊了。

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

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]

最佳答案

稍后再看我的回答,related question .

在那个答案中,我创建了一个程序,它为给定范围生成随机 float 。我不确定您为什么坚持整数起点,但您可以轻松地修改我的答案中的代码来改为这样做。您可以像这样简单地定义过程 fgen

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

关于algorithm - Maple:如何插入命令以强制我的代码选择随机整数值来查找我的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35103336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com