1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
program roofnrte;
uses
typ,
spe,
roo;
const
num = 3;
nmax = 3;
var
term, i, j, k, l, n: ArbInt;
re, residu: ArbFloat;
x: array[1..nmax] of ArbFloat;
procedure f(var x0, fx: ArbFloat; var deff: boolean);
var
xloc: array[1..nmax] of ArbFloat absolute x0;
f: array[1..nmax] of ArbFloat absolute fx;
x, y, z: ArbFloat;
begin
x := xloc[1];
y := xloc[2];
if n = 3 then
z := xloc[3];
case i of
1:
begin
if j * 2 <= k then
deff := x >= 0
else
deff := y >= 0;
f[1] := x * x - y * y - 2;
f[2] := x + y - 1;
end;
2:
begin
f[1] := exp(x) + exp(y) - exp(z);
f[2] := sin(x) + cos(y) - z;
f[3] := x * y - sqr(z);
end;
3: if (x > 0) and (y > 0) then
begin
f[1] := spepow(x, y) - spepow(y, x);
f[2] := sin(x) - cos(y);
end
else
deff := False
end;
end;
begin
Write(' program results roofnrte');
case sizeof(ArbFloat) of
4: writeln('(single)');
6: writeln('(real)');
8: writeln('(double)');
end;
writeln;
writeln(' number of examples:', num: 3);
for i := 1 to num do
begin
writeln;
writeln('Locating the root of the equations ');
case i of
1:
begin
n := 2;
writeln('x + y = 1');
writeln('xý + yý = 2');
end;
2:
begin
n := 3;
writeln('exp(x) + exp(y) = exp(z)');
writeln('sin(x) + cos(y) = z');
writeln('xy = zý');
end;
3:
begin
n := 2;
writeln('xy = yx');
writeln('sin(x) = cos(y)');
end
end;
Read(k);
for j := 1 to k do
begin
for l := 1 to n do
Read(x[l]);
Read(re);
writeln(' starting values: (n=', n: 1, ')');
for l := 1 to n do
Write(x[l]: numdig, ' ');
writeln(' re =', re: 8);
roofnr(@f, n, x[1], residu, re, term);
writeln;
writeln(' term =', term: 2);
if term < 3 then
begin
writeln(' solution vector');
for l := 1 to n do
Write(x[l]: numdig, ' ');
writeln;
writeln(' residu = ', residu: 8);
end;
writeln('-------------------------------------------------');
end;
writeln('======================================================');
end;
Close(input);
Close(output);
end.
|