Sunday, September 8, 2024
HomeMatlabAn Fascinating, and Maybe New, Matrix » Cleve’s Nook: Cleve Moler on...

An Fascinating, and Maybe New, Matrix » Cleve’s Nook: Cleve Moler on Arithmetic and Computing

I don’t recall having seen this matrix earlier than, however I cannot be stunned to be taught that anyone else already is aware of all about it, particularly if that individual’s identify is Nick.

Contents

Q

I have been investigating the matrices generated by this elegant one-liner.

```    Q = @(n) (-n:n).^2 + (-n:n)'.^2;
```

The center column accommodates the squares of the integers from -n to n. So does the center row. The apostrophe summons singleton enlargement. The ensuing matrix has order 2*n+1. Right here is Q(5).

```    Q5 = Q(5)
```
```
Q5 =

50    41    34    29    26    25    26    29    34    41    50
41    32    25    20    17    16    17    20    25    32    41
34    25    18    13    10     9    10    13    18    25    34
29    20    13     8     5     4     5     8    13    20    29
26    17    10     5     2     1     2     5    10    17    26
25    16     9     4     1     0     1     4     9    16    25
26    17    10     5     2     1     2     5    10    17    26
29    20    13     8     5     4     5     8    13    20    29
34    25    18    13    10     9    10    13    18    25    34
41    32    25    20    17    16    17    20    25    32    41
50    41    34    29    26    25    26    29    34    41    50

```

I just like the contour plot.

```    contourf(Q(100))
axis sq.
colorbar
title('Q(100)')
```

D

For an additional weblog put up beneath growth, I want a logical masks that carves a round area out of graphic. This disc does the job.

```    D = @(n) Q(n) <= n^2;
```

Right here is my carver.

```    spy(D(100))
title('D(100)')
```

Did you discover the digits within the depend of nonzeros in D(100)? It occurs every time n is an influence of 10.

```    fprintf('%15s %12sn','n','nnz(D(n))')
for n = 10.^(0:4)
fprintf('%15d %12dn',n, nnz(D(n)))
finish
```
```              n    nnz(D(n))
1            5
10          317
100        31417
1000      3141549
10000    314159053
```

O.E.I.S.

A basic drawback, described within the On-line Encyclopedia of Integer Sequences, asks what number of factors with integer coordinates lie inside a disc of accelerating radius. Our nonzero depend gives the reply.

```    fprintf('%15s %8sn','n','a(n)')
for n = [1:15  99:101  499:501  999:1001]
if mod(n,100) == 99
fprintf('%15s %8sn','-','-')
finish
a(n) = nnz(D(n));
fprintf('%15d %8dn',n,a(n))
finish
```
```              n     a(n)
1        5
2       13
3       29
4       49
5       81
6      113
7      149
8      197
9      253
10      317
11      377
12      441
13      529
14      613
15      709
-        -
99    30757
100    31417
101    32017
-        -
499   782197
500   785349
501   788509
-        -
999  3135157
1000  3141549
1001  3147833
```

R

Taking the reciprocals of the matrix entries, and lowering the vary of the nameless index, produces a matrix that behaves a bit just like the Hilbert matrix, hilb(n).

```    R = @(n) 1./((1:n).^2 + (1:n)'.^2);
```

Listed below are the 5-by-5’s.

```    format rat
R5 = R(5)
H5 = hilb(5)
```
```
R5 =

1/2            1/5            1/10           1/17           1/26
1/5            1/8            1/13           1/20           1/29
1/10           1/13           1/18           1/25           1/34
1/17           1/20           1/25           1/32           1/41
1/26           1/29           1/34           1/41           1/50

H5 =

1              1/2            1/3            1/4            1/5
1/2            1/3            1/4            1/5            1/6
1/3            1/4            1/5            1/6            1/7
1/4            1/5            1/6            1/7            1/8
1/5            1/6            1/7            1/8            1/9

```

Situation

Going away from the diagonal, the weather of R(n) decay extra quickly than these of hilb(n), so R(n) is healthier conditioned than hilb(n).

```    format quick e
fprintf('%15s %12s %12sn','n','cond R','cond H')
for n = 1:12
fprintf('%15d %12.2e %12.2en',n,cond(R(n)),cond(hilb(n)))
finish
```
```              n       cond R       cond H
1     1.00e+00     1.00e+00
2     1.53e+01     1.93e+01
3     2.04e+02     5.24e+02
4     2.59e+03     1.55e+04
5     3.21e+04     4.77e+05
6     3.89e+05     1.50e+07
7     4.67e+06     4.75e+08
8     5.54e+07     1.53e+10
9     6.53e+08     4.93e+11
10     7.65e+09     1.60e+13
11     8.92e+10     5.22e+14
12     1.04e+12     1.62e+16
```

Further Credit score

What’s the rank of Q(n)? Why? See a paper in SIAM Assessment by Strang and Moler.

Why is the desk of values for nnz(D(10^okay)) so quick? How may you prolong this desk?

Examine R(n). Is it optimistic particular? What are its eigenvalues? What’s its inverse? What’s the signal sample of the weather of its inverse? For what values of n are you able to compute the inverse reliably utilizing floating level arithmetic? How does all this evaluate with hilb(n) and invhilb(n) ?

Feedback within the Feedback, or in e mail to me, are welcome.

Printed with MATLAB® R2022a

RELATED ARTICLES