What does this emacs-lisp code do? - lisp

I am very confused about what the function "do-something" does. Maybe I can replace it with another name.
(defun do-something (m &optional n)
(let* ((count (if (null n) 20 n))
(bound (* count m)))
(loop for i from 0 below m
do (princ "[ ")
(loop for j from (+ (- bound) i) to (+ bound i) by m
do (princ j)
(princ " "))
(princ "]\n"))))

You can try it on emacs by cut'n'paste to buffer and run C-x C-e (eval-last-sexp)
(do-something 10 10)
[ -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 ]
[ -99 -89 -79 -69 -59 -49 -39 -29 -19 -9 1 11 21 31 41 51 61 71 81 91 101 ]
[ -98 -88 -78 -68 -58 -48 -38 -28 -18 -8 2 12 22 32 42 52 62 72 82 92 102 ]
[ -97 -87 -77 -67 -57 -47 -37 -27 -17 -7 3 13 23 33 43 53 63 73 83 93 103 ]
[ -96 -86 -76 -66 -56 -46 -36 -26 -16 -6 4 14 24 34 44 54 64 74 84 94 104 ]
[ -95 -85 -75 -65 -55 -45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105 ]
[ -94 -84 -74 -64 -54 -44 -34 -24 -14 -4 6 16 26 36 46 56 66 76 86 96 106 ]
[ -93 -83 -73 -63 -53 -43 -33 -23 -13 -3 7 17 27 37 47 57 67 77 87 97 107 ]
[ -92 -82 -72 -62 -52 -42 -32 -22 -12 -2 8 18 28 38 48 58 68 78 88 98 108 ]
[ -91 -81 -71 -61 -51 -41 -31 -21 -11 -1 9 19 29 39 49 59 69 79 89 99 109 ]
As you see, it prints 2 dimensional array with some form.

Related

list with initial-element are start from 99 to 0 in Lisp

Function that takes a positive number and creates a list of all numbers between 0 (included) and the number passed as an argument (excluded). By default, it's 100
(defun list-numbers (&optional (n 100))
(mapcar #'abs (make-list n :initial-element (- n 1))))
if you want to see the result https://ideone.com/Jbz5u3
(99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99)
but my goal is create a simple list that initial-element are started with values ​​from 99 to 0
(99 98 97 96 95 94 93 92 91 90 89 88 87 86....
9 8 7 6 5 4 3 2 1 0)
CL-USER 160 > (loop for i from 99 downto 0 collect i)
(99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)
or
CL-USER 167 > (do* ((i 0 (+ i 1))
(result (list i) (cons i result)))
((= i 99) result))
(99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)

Compute laplacian using gradient

I'm trying to get Laplacian using 3 different method, in case 1 and 2 results the same but what is wrong with 3?
Here is code in Matlab:
m= magic(6)
Lap1Dx= convn(m,[-1 2 -1],'same')
Lap1Dy= convn(m,[-1;2;-1],'same')
%ver1
Lap2Dxy= convn(m,[0 -1 0;-1 4 -1;0 -1 0],'same')
%ver2
Lap2Dxy= Lap1Dx+Lap1Dy %same as ver 1
%ver 3
%get laplacian using gradients
gradx= convn(m,[-1 1],'same')
grady= convn(m,[-1;1],'same')
gradxx= convn(gradx,[-1 1],'same')
gradyy= convn(grady,[-1;1],'same')
Lap2Dxy= gradxx+gradyy
Output:
m =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
Lap1Dx =
69 -39 -15 27 -12 29
-26 54 -39 12 0 27
53 -15 -27 15 12 13
-12 15 21 -9 -12 20
55 -54 51 -24 0 18
-28 39 9 -21 12 4
Lap1Dy =
67 -30 5 31 15 23
-60 54 6 -6 0 6
51 -42 -36 6 21 0
-45 42 30 0 -21 -6
48 -54 6 -6 0 6
-22 67 24 14 22 6
Lap2Dxy =
136 -69 -10 58 3 52
-86 108 -33 6 0 33
104 -57 -63 21 33 13
-57 57 51 -9 -33 14
103 -108 57 -30 0 24
-50 106 33 -7 34 10
Lap2Dxy =
136 -69 -10 58 3 52
-86 108 -33 6 0 33
104 -57 -63 21 33 13
-57 57 51 -9 -33 14
103 -108 57 -30 0 24
-50 106 33 -7 34 10
gradx =
34 -5 -20 7 -5 24
-29 25 -14 -2 -2 25
22 7 -20 -5 7 20
-20 -5 16 7 -5 15
25 -29 22 -2 -2 16
-32 7 16 -5 7 11
grady =
32 -31 -1 5 -4 -1
-28 23 5 -1 -4 5
23 -19 -31 5 17 5
-22 23 -1 5 -4 -1
26 -31 5 -1 -4 5
4 36 29 13 18 11
gradxx =
39 15 -27 12 -29 24
-54 39 -12 0 -27 25
15 27 -15 -12 -13 20
-15 -21 9 12 -20 15
54 -51 24 0 -18 16
-39 -9 21 -12 -4 11
gradyy =
60 -54 -6 6 0 -6
-51 42 36 -6 -21 0
45 -42 -30 0 21 6
-48 54 -6 6 0 -6
22 -67 -24 -14 -22 -6
4 36 29 13 18 11
Lap2Dxy =
99 -39 -33 18 -29 18
-105 81 24 -6 -48 25
60 -15 -45 -12 8 26
-63 33 3 18 -20 9
76 -118 0 -14 -40 10
-35 27 50 1 14 22
First of all, there are some sign issues. Convolving with [-1 1] gives you the first derivative with the minus sign: convolution flips one of two arrays so you end subtracting each element from the following one. Convolve with [1 -1] to get the first derivative. For the second derivative, use [1 -2 1].
But the main issue here has to do with truncation ('same' parameter). With the first two approaches, you convolve and then truncate. With the third, you convolve, then truncate, then convolve again and truncate again.
Since the issue can be seen already on a one-dimensional array, I'll focus on the first row of yours. Let's drop the parameter same for now:
m = [35 1 6 26 19 24]
mx = convn(m,[1 -1]) // [35 -34 5 20 -7 5 -24]
mxx = convn(mx,[1 -1]) // [35 -69 39 15 -27 12 -29 24]
m2x = convn(m,[1 -2 1]) // [35 -69 39 15 -27 12 -29 24]
As you can see, the results are identical. Next, with the 'same' parameter:
mx = convn(m,[1 -1],'same') // [-34 5 20 -7 5 -24]
mxx = convn(mx,[1 -1],'same') // [39 15 -27 12 -29 24]
m2x = convn(m,[1 -2 1],'same') // [-69 39 15 -27 12 -29]
For m2x, 'same' cleanly picks the middle part of the full convolution, which is exactly the part you want.
But for the first-order derivative, there is just one element to drop. The choice has to be made, and convn drops the first one (resulting in the forward difference). When computing mxx, it has to do it again. So, as a result of dropping the first element of full convolution twice, you end up with a shifted array. This is why mxx has most of the same numbers as m2x, except misaligned.
If you insist on having two-step convolution (first derivative, then second), the first convolution must be without any truncation. Otherwise, the truncation influences the result of the second convolution. For the second one, you can use 'same' but in addition, the last element will need to be dropped. Like this.
mx = convn(m, [1 -1])
mxx = convn(mx,[1 -1],'same')
mxx = mxx(1:end-1)
Or, equivalently,
mx = convn(m, [1 -1])
mxx = convn(mx,[1 -1])
mxx = mxx(2:end-1)

MRT function [1] "error code = 0"

When I make my MRT, I got two errors:
[1] "error code = 0" and Error in indval.default(Ynode, clustering =
clustnode, numitr = 1000) : All species must occur in at least one
plot. Does anyone have an idea of why? I checked and all my species
have an abundance >0...
MRTtest=mvpart(vegetation~ Placette+ Tourb + Transect + Largcanal + Annouvert + Elevation + Profnappe + Litiere+ Solnu+ Deblign+ Densiometre+ EpaissMO+ Vonpostvingt+ Vonpostsoixante+ Pyrovingt+ Pyrosoixante+ Sommesurfterr,tot,margin=0.08,cp=0,xv="pick",xval=10,xvmult=150,which=4,pca=F)
X-Val rep : 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 114 115 116 117 118 119
120 121 122 123 124 125 126 127 128 129 130 131 132 133
134 135 136 137 138 139 140 141 142 143 144 145 146 147
148 149 150
Minimum tree sizes
tabmins
2 3 4 6
2 125 5 18
MRTtest1=MRT(MRTtest,percent=10,species=colnames(vegetation))
summary(MRTtest1)
Portion (%) of deviance explained by species for every particular node
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- Node 1 ---
Complexity(R2) 14.87422
Sommesurfterr>=6.024 Sommesurfterr< 6.024
~ Discriminant species :
THOnmtot THOmtot
% of expl. deviance 17.61057298 38.419650816
Mean on the left 0.37621604 0.430818462
Mean on the right 0.08877576 0.006259911
[1] "error code = 0"
~ INDVAL species for this node: : left is 1, right is 2
cluster indicator_value probability
THOmtot 1 0.9597 0.001
THOnmtot 1 0.7878 0.001
LEG 1 0.5802 0.031
LIB 1 0.5078 0.010
MELnmtot 1 0.4710 0.047
EPNnmtot 1 0.4404 0.026
Sum of probabilities = 87.497
Sum of Indicator Values = 30.02
Sum of Significant Indicator Values = 12.67
Number of Significant Indicators = 29
Significant Indicator Distribution
1 2
8 21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- Node 2 ---
Complexity(R2) 7.920283
Densiometre< 19.88 Densiometre>=19.88
~ Discriminant species :
TRA THOmtot
% of expl. deviance 10.54536819 27.8848051
Mean on the left 0.02754503 0.5158733
Mean on the right 0.20823621 0.2220475
Error in indval.default(Ynode, clustering = clustnode, numitr = 1000)
: All species must occur in at least one plot

missing glyphs when displaying vector field in paraview?

When visualizing the file below (paraview 4.2.0 64 bit linux), not all glyphs are rendered. For instance, the glyph at [7,0,0] (corresponding to pointID 7) is missing.
Can anyone confirm that behaviour?
file.vti
<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" compressor="vtkZLibDataCompressor">
<ImageData WholeExtent="0 7 0 15 0 0" Origin="0 0 0" Spacing="1 1 1">
<Piece Extent="0 7 0 15 0 0">
<PointData>
<DataArray type="Float64" Name="thedata" NumberOfComponents="3" format="ascii" RangeMin="1.7320508076" RangeMax="221.70250337">
1 -1 1 2 -2 2
3 -3 3 4 -4 4
5 -5 5 6 -6 6
7 -7 7 8 -8 8
9 -9 9 10 -10 10
11 -11 11 12 -12 12
13 -13 13 14 -14 14
15 -15 15 16 -16 16
17 -17 17 18 -18 18
19 -19 19 20 -20 20
21 -21 21 22 -22 22
23 -23 23 24 -24 24
25 -25 25 26 -26 26
27 -27 27 28 -28 28
29 -29 29 30 -30 30
31 -31 31 32 -32 32
33 -33 33 34 -34 34
35 -35 35 36 -36 36
37 -37 37 38 -38 38
39 -39 39 40 -40 40
41 -41 41 42 -42 42
43 -43 43 44 -44 44
45 -45 45 46 -46 46
47 -47 47 48 -48 48
49 -49 49 50 -50 50
51 -51 51 52 -52 52
53 -53 53 54 -54 54
55 -55 55 56 -56 56
57 -57 57 58 -58 58
59 -59 59 60 -60 60
61 -61 61 62 -62 62
63 -63 63 64 -64 64
65 -65 65 66 -66 66
67 -67 67 68 -68 68
69 -69 69 70 -70 70
71 -71 71 72 -72 72
73 -73 73 74 -74 74
75 -75 75 76 -76 76
77 -77 77 78 -78 78
79 -79 79 80 -80 80
81 -81 81 82 -82 82
83 -83 83 84 -84 84
85 -85 85 86 -86 86
87 -87 87 88 -88 88
89 -89 89 90 -90 90
91 -91 91 92 -92 92
93 -93 93 94 -94 94
95 -95 95 96 -96 96
97 -97 97 98 -98 98
99 -99 99 100 -100 100
101 -101 101 102 -102 102
103 -103 103 104 -104 104
105 -105 105 106 -106 106
107 -107 107 108 -108 108
109 -109 109 110 -110 110
111 -111 111 112 -112 112
113 -113 113 114 -114 114
115 -115 115 116 -116 116
117 -117 117 118 -118 118
119 -119 119 120 -120 120
121 -121 121 122 -122 122
123 -123 123 124 -124 124
125 -125 125 126 -126 126
127 -127 127 128 -128 128
</DataArray>
</PointData>
<CellData>
</CellData>
</Piece>
</ImageData>
</VTKFile>
Try changing the Glyph Mode to All Points. In 4.2, the default is to use a sampling mechanism to attempt to get uniformly distributed glyphs.

Comparing area between two matrices with multiple points of intersection (MATLAB)

I have two matrices that contain the points for the top boundaries of two jigsaw puzzles. I am trying to calculate the area contained between these two matrices (of unequal rows). They have multiple points of intersection. The picture below gives a better idea of what I'm trying to accomplish. The output should be a numerical value (of the total area highlighted in blue). If this is too difficult to achieve, is there a better way to compare matrices to see which ones "fit" the best?
Un-Highlighted Picture
Area(in blue) that I am trying to calculate (numerical value)
The matrix values are below if it helps:
Matrix 1:
1 1
2 2
3 2
4 2
5 2
6 3
7 3
8 3
9 3
10 3
11 3
12 2
13 2
14 2
15 2
16 2
17 2
18 2
19 2
20 2
21 2
22 2
23 2
24 2
25 2
26 2
27 2
28 2
29 2
30 2
31 2
32 2
33 2
34 2
35 2
36 2
37 2
38 2
39 2
40 2
41 2
42 2
43 2
44 2
45 2
46 2
47 2
48 2
49 2
50 2
51 2
52 2
53 2
54 2
55 2
56 2
57 2
58 2
59 2
60 2
61 2
62 2
63 2
64 2
65 2
66 2
67 2
68 2
69 2
70 2
71 2
72 3
73 3
74 3
75 4
76 5
77 6
78 7
79 8
79 9
80 10
80 11
80 12
80 13
80 14
80 15
79 16
79 17
79 18
78 19
78 20
78 21
77 22
77 23
77 24
76 25
76 26
76 27
75 28
75 29
75 30
74 31
74 32
74 33
73 34
73 35
73 36
73 37
73 38
72 39
72 40
72 41
72 42
72 43
72 44
73 45
73 46
73 47
74 48
75 49
76 50
77 51
78 52
79 53
80 53
81 54
82 54
83 55
84 55
85 56
86 56
87 57
88 57
89 57
90 58
91 58
92 58
93 58
94 59
95 59
96 59
97 59
98 59
99 59
100 59
101 59
102 59
103 59
104 59
105 59
106 59
107 59
108 59
109 59
110 59
111 59
112 58
113 58
114 58
115 58
116 57
117 57
118 57
119 56
120 56
121 56
122 55
123 55
124 54
125 53
126 53
127 52
128 51
129 51
130 50
131 49
132 48
132 47
133 46
133 45
133 44
133 43
133 42
133 41
133 40
133 39
133 38
132 37
132 36
132 35
131 34
131 33
131 32
131 31
130 30
130 29
130 28
130 27
129 26
129 25
128 24
128 23
127 22
127 21
127 20
127 19
126 18
126 17
126 16
126 15
126 14
126 13
126 12
126 11
126 10
126 9
127 8
128 7
129 6
130 5
131 4
132 3
133 3
134 2
135 2
136 2
137 2
138 2
139 2
140 2
141 2
142 2
143 2
144 2
145 2
146 2
147 2
148 2
149 2
150 2
151 2
152 2
153 2
154 2
155 2
156 2
157 2
158 2
159 2
160 2
161 2
162 2
163 2
164 2
165 2
166 2
167 2
168 1
169 1
170 1
171 1
172 1
Matrix 2:
173 3
172 3
171 3
170 2
169 2
168 2
167 2
166 2
165 2
164 2
163 2
162 2
161 2
160 2
159 2
158 2
157 2
156 2
155 2
154 2
153 2
152 2
151 2
150 2
149 2
148 2
147 2
146 2
145 2
144 2
143 2
142 2
141 2
140 2
139 2
138 2
137 2
136 2
135 3
134 3
133 3
132 3
131 4
130 4
129 4
128 5
127 6
127 7
127 8
126 9
127 10
127 11
127 12
127 13
127 14
126 15
127 16
127 17
127 18
127 19
127 20
127 21
128 22
128 23
128 24
128 25
129 26
129 27
129 28
130 29
130 30
130 31
131 32
131 33
131 34
132 35
132 36
132 37
132 38
133 39
133 40
133 41
133 42
133 43
132 44
132 45
132 46
131 47
130 48
129 49
128 50
127 51
126 52
125 53
124 54
123 54
122 55
121 55
120 55
119 56
118 56
117 57
116 58
115 58
114 59
113 59
112 59
111 59
110 60
109 60
108 60
107 60
106 60
105 60
104 60
103 60
102 60
101 60
100 60
99 60
98 60
97 60
96 60
95 59
94 59
93 59
92 59
91 59
90 58
89 58
88 57
87 57
86 56
85 56
84 55
83 55
82 54
81 54
80 53
79 52
78 51
77 50
76 49
75 48
74 47
73 46
73 45
73 44
73 43
73 42
73 41
73 40
73 39
73 38
73 37
73 36
74 35
74 34
74 33
75 32
75 31
75 30
76 29
76 28
76 27
77 26
77 25
77 24
78 23
78 22
78 21
79 20
79 19
80 18
80 17
80 16
81 15
81 14
81 13
81 12
81 11
81 10
80 10
79 9
79 8
78 7
77 6
76 5
75 4
74 4
73 3
72 3
71 2
70 2
69 2
68 1
67 2
66 2
65 2
64 2
63 2
62 2
61 2
60 2
59 2
58 2
57 2
56 2
55 2
54 2
53 2
52 2
51 2
50 2
49 2
48 2
47 2
46 2
45 2
44 2
43 2
42 2
41 2
40 2
39 2
38 2
37 2
36 2
35 2
34 2
33 2
32 2
31 2
30 2
29 2
28 2
27 2
26 2
25 2
24 2
23 2
22 2
21 2
20 2
19 2
18 2
17 2
16 2
15 2
14 2
13 2
12 2
11 2
10 2
9 2
8 2
7 2
6 2
5 2
4 2
3 2
2 2
1 3
Mark everything above one curve and mark everything below the other curve. Then you can get the area between the curves by finding where there are two marks.
You should take a look at this question Similarity measures between curves?