问题
My initial question is to: Use the several variable version of the Newton-Raphson algorithm to find all 4 (real and complex) intersection points of the 2 circles
2 2
(x - 7) + (y - 2) = 100
and
2 2
(x - 11) + (y - 5) = 75
accurate to 25 digits. Plot these two circles in two colors showing their 2 real intersection points.
The code I has does a every good job in find the real value points of the intersection of these two circles. However, I am the image of the two circles to determine my guessing values. Now for the complex intersection points, I have to simple guess and check for a possible solution. However this is silly tedious.
What I would like to know how to do is create a loop that produces a pair of complex numbers, runs the algorithm/for loop below, and if it matches a previous solution then starts the loop again.
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]
回答1:
See my answer to your later, related question.
In that answer I created a procedure which generated random floats for a given range. I'm not sure why you might insist on integer starting points, but you can easily modify the code in my answer to do that instead. You could simply define the procedure fgen
like this instead,
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
来源:https://stackoverflow.com/questions/35103336/maple-how-to-insert-a-command-to-force-my-code-to-choose-random-integer-values