Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gmtmath.rst 62 KB

You have to be logged in to leave a comment. Sign In
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  1. .. index:: ! gmtmath
  2. .. include:: module_core_purpose.rst_
  3. *******
  4. gmtmath
  5. *******
  6. |gmtmath_purpose|
  7. Synopsis
  8. --------
  9. .. include:: common_SYN_OPTs.rst_
  10. **gmt math** [ |-A|\ *t_f(t)*\ [**+e**]\ [**+r**]\ [**+s**\|\ **w**] ]
  11. [ |-C|\ *cols* ]
  12. [ |-E|\ *eigen* ] [ |-I| ]
  13. [ |-N|\ *n\_col*\ [/*t_col*] ]
  14. [ |-Q| ] [ |-S|\ [**f**\|\ **l**] ]
  15. [ |-T|\ [*min*/*max*/*inc*\ [**+b**\|\ **l**\|\ **n**]\|\ *file*\|\ *list*] ]
  16. [ |SYN_OPT-V| ]
  17. [ |SYN_OPT-b| ]
  18. [ |SYN_OPT-d| ]
  19. [ |SYN_OPT-e| ]
  20. [ |SYN_OPT-f| ]
  21. [ |SYN_OPT-g| ]
  22. [ |SYN_OPT-h| ]
  23. [ |SYN_OPT-i| ]
  24. [ |SYN_OPT-o| ]
  25. [ |SYN_OPT-q| ]
  26. [ |SYN_OPT-s| ]
  27. [ |SYN_OPT--| ]
  28. *operand* [ *operand* ] **OPERATOR** [ *operand* ] **OPERATOR** ...
  29. **=** [ *outfile* ]
  30. |No-spaces|
  31. Description
  32. -----------
  33. **math** will perform operations like add, subtract, multiply, and
  34. numerous other operands on one or more table data files or constants using
  35. `Reverse Polish Notation (RPN) <https://en.wikipedia.org/wiki/Reverse_Polish_notation>`_
  36. syntax. Arbitrarily complicated expressions may therefore be evaluated; the
  37. final result is written to an output file [or standard output]. Data
  38. operations are element-by-element, not matrix manipulations (except
  39. where noted). Some operators only require one operand (see below). If no
  40. data tables are used in the expression then options **-T**, **-N** can
  41. be set (and optionally **-bo** to indicate the
  42. data type for binary tables). If STDIN is given, the standard input will
  43. be read and placed on the stack as if a file with that content had been
  44. given on the command line. By default, all columns except the "time"
  45. column are operated on, but this can be changed (see **-C**).
  46. Complicated or frequently occurring expressions may be coded as a macro
  47. for future use or stored and recalled via named memory locations.
  48. Required Arguments
  49. ------------------
  50. *operand*
  51. If *operand* can be opened as a file it will be read as an ASCII (or
  52. binary, see **-bi**) table data file. If not
  53. a file, it is interpreted as a numerical constant or a special
  54. symbol (see below). The special argument STDIN means that *stdin*
  55. will be read and placed on the stack; STDIN can appear more than
  56. once if necessary.
  57. *outfile*
  58. The name of a table data file that will hold the final result. If
  59. not given then the output is sent to stdout.
  60. Optional Arguments
  61. ------------------
  62. .. _-A:
  63. **-A**\ *t_f(t)*\ [**+e**]\ [**+r**]\ [**+s**\|\ **w**]
  64. Requires **-N** and will partially initialize a table with values
  65. from the given file *t_f(t)* containing *t* and *f(t)* only. The *t* is
  66. placed in column *t\_col* while *f(t)* goes into column *n\_col* - 1
  67. (see **-N**). Append **+r** to only place *f(t)* and leave the left
  68. hand side of the matrix equation alone. If used with operators LSQFIT and SVDFIT you can
  69. optionally append the modifier **+e** which will instead evaluate
  70. the solution and write a data set with four columns: t, f(t), the
  71. model solution at t, and the the residuals at t, respectively
  72. [Default writes one column with model coefficients]. Append **+w**
  73. if *t_f(t* has a third column with weights, or append **+s** if
  74. *t_f(t)* has a third column with 1-sigma. In those two cases we
  75. find the weighted solution. The weights (or sigmas) will be output
  76. as the last column when **+e** is in effect.
  77. .. _-C:
  78. **-C**\ *cols*
  79. Select the columns that will be operated on until next occurrence of
  80. **-C**. List columns separated by commas; ranges like 1,3-5,7 are
  81. allowed, plus -Cx can be used for -C0 and -Cy can be used for -C1.
  82. **-C** (no arguments) resets the default action of using
  83. all columns except time column (see **-N**). **-Ca** selects all
  84. columns, including time column, while **-Cr** reverses (toggles) the
  85. current choices. When **-C** is in effect it also controls which
  86. columns from a file will be placed on the stack.
  87. .. _-E:
  88. **-E**\ *eigen*
  89. Sets the minimum eigenvalue used by operators LSQFIT and SVDFIT [1e-7].
  90. Smaller eigenvalues are set to zero and will not be considered in the
  91. solution.
  92. .. _-I:
  93. **-I**
  94. Reverses the output row sequence from ascending time to descending [ascending].
  95. .. _-N:
  96. **-N**\ *n_col*\ [/*t_col*]
  97. Select the number of columns and optionally the column number that
  98. contains the "time" variable [0]. Columns are numbered starting at 0
  99. [2/0]. If input files are specified then **-N** will add any missing
  100. columns.
  101. .. _-Q:
  102. **-Q**
  103. Quick mode for scalar calculation. Shorthand for **-Ca** **-N**\ 1/0 **-T**\ 0/0/1.
  104. In this mode, constants may have plot units (i.e., c, i, p) and if so the final
  105. answer will be reported in the unit set by :term:`PROJ_LENGTH_UNIT`.
  106. .. _-S:
  107. **-S**\ [**f**\|\ **l**]
  108. Only report the first or last row of the results [Default is all
  109. rows]. This is useful if you have computed a statistic (say the
  110. **MODE**) and only want to report a single number instead of
  111. numerous records with identical values. Append **l** to get the last
  112. row and **f** to get the first row only [Default].
  113. .. _-T:
  114. **-T**\ [*min*/*max*/*inc*\ [**+b**\|\ **l**\|\ **n**]\|\ *file*\|\ *list*]
  115. Required when no input files are given. Builds an array for
  116. the "time" column (see **-N**). If there is no time column
  117. (i.e., your input has only data columns), give **-T** with
  118. no arguments; this also implies **-Ca**.
  119. For details on array creation, see `Generate 1D Array`_.
  120. .. _-V:
  121. .. |Add_-V| unicode:: 0x20 .. just an invisible code
  122. .. include:: explain_-V.rst_
  123. .. |Add_-bi| unicode:: 0x20 .. just an invisible code
  124. .. include:: explain_-bi.rst_
  125. .. |Add_-bo| replace:: [Default is same as input, but see **-o**]
  126. .. include:: explain_-bo.rst_
  127. .. |Add_-d| unicode:: 0x20 .. just an invisible code
  128. .. include:: explain_-d.rst_
  129. .. |Add_-e| unicode:: 0x20 .. just an invisible code
  130. .. include:: explain_-e.rst_
  131. .. |Add_-f| unicode:: 0x20 .. just an invisible code
  132. .. include:: explain_-f.rst_
  133. .. |Add_-g| unicode:: 0x20 .. just an invisible code
  134. .. include:: explain_-g.rst_
  135. .. |Add_-h| unicode:: 0x20 .. just an invisible code
  136. .. include:: explain_-h.rst_
  137. .. include:: explain_-icols.rst_
  138. .. include:: explain_-ocols.rst_
  139. .. include:: explain_-q.rst_
  140. .. include:: explain_-s.rst_
  141. .. include:: explain_help.rst_
  142. .. include:: explain_array.rst_
  143. Operators
  144. ---------
  145. Choose among the following 185 operators. Here, "args" are the number of input
  146. and output arguments.
  147. +-----------------+--------+--------------------------------------------------------------------------------------------+
  148. | Operator | args | Returns |
  149. +-----------------+--------+--------------------------------------------------------------------------------------------+
  150. | **ABS** | 1 1 | abs (A) |
  151. +-----------------+--------+--------------------------------------------------------------------------------------------+
  152. | **ACOS** | 1 1 | acos (A) |
  153. +-----------------+--------+--------------------------------------------------------------------------------------------+
  154. | **ACOSH** | 1 1 | acosh (A) |
  155. +-----------------+--------+--------------------------------------------------------------------------------------------+
  156. | **ACSC** | 1 1 | acsc (A) |
  157. +-----------------+--------+--------------------------------------------------------------------------------------------+
  158. | **ACOT** | 1 1 | acot (A) |
  159. +-----------------+--------+--------------------------------------------------------------------------------------------+
  160. | **ADD** | 2 1 | A + B |
  161. +-----------------+--------+--------------------------------------------------------------------------------------------+
  162. | **AND** | 2 1 | B if A == NaN, else A |
  163. +-----------------+--------+--------------------------------------------------------------------------------------------+
  164. | **ASEC** | 1 1 | asec (A) |
  165. +-----------------+--------+--------------------------------------------------------------------------------------------+
  166. | **ASIN** | 1 1 | asin (A) |
  167. +-----------------+--------+--------------------------------------------------------------------------------------------+
  168. | **ASINH** | 1 1 | asinh (A) |
  169. +-----------------+--------+--------------------------------------------------------------------------------------------+
  170. | **ATAN** | 1 1 | atan (A) |
  171. +-----------------+--------+--------------------------------------------------------------------------------------------+
  172. | **ATAN2** | 2 1 | atan2 (A, B) |
  173. +-----------------+--------+--------------------------------------------------------------------------------------------+
  174. | **ATANH** | 1 1 | atanh (A) |
  175. +-----------------+--------+--------------------------------------------------------------------------------------------+
  176. | **BCDF** | 3 1 | Binomial cumulative distribution function for p = A, n = B, and x = C |
  177. +-----------------+--------+--------------------------------------------------------------------------------------------+
  178. | **BPDF** | 3 1 | Binomial probability density function for p = A, n = B, and x = C |
  179. +-----------------+--------+--------------------------------------------------------------------------------------------+
  180. | **BEI** | 1 1 | bei (A) |
  181. +-----------------+--------+--------------------------------------------------------------------------------------------+
  182. | **BER** | 1 1 | ber (A) |
  183. +-----------------+--------+--------------------------------------------------------------------------------------------+
  184. | **BITAND** | 2 1 | A & B (bitwise AND operator) |
  185. +-----------------+--------+--------------------------------------------------------------------------------------------+
  186. | **BITLEFT** | 2 1 | A << B (bitwise left-shift operator) |
  187. +-----------------+--------+--------------------------------------------------------------------------------------------+
  188. | **BITNOT** | 1 1 | ~A (bitwise NOT operator, i.e., return two's complement) |
  189. +-----------------+--------+--------------------------------------------------------------------------------------------+
  190. | **BITOR** | 2 1 | A \| B (bitwise OR operator) |
  191. +-----------------+--------+--------------------------------------------------------------------------------------------+
  192. | **BITRIGHT** | 2 1 | A >> B (bitwise right-shift operator) |
  193. +-----------------+--------+--------------------------------------------------------------------------------------------+
  194. | **BITTEST** | 2 1 | 1 if bit B of A is set, else 0 (bitwise TEST operator) |
  195. +-----------------+--------+--------------------------------------------------------------------------------------------+
  196. | **BITXOR** | 2 1 | A ^ B (bitwise XOR operator) |
  197. +-----------------+--------+--------------------------------------------------------------------------------------------+
  198. | **CEIL** | 1 1 | ceil (A) (smallest integer >= A) |
  199. +-----------------+--------+--------------------------------------------------------------------------------------------+
  200. | **CHICRIT** | 2 1 | Chi-squared distribution critical value for alpha = A and nu = B |
  201. +-----------------+--------+--------------------------------------------------------------------------------------------+
  202. | **CHICDF** | 2 1 | Chi-squared cumulative distribution function for chi2 = A and nu = B |
  203. +-----------------+--------+--------------------------------------------------------------------------------------------+
  204. | **CHIPDF** | 2 1 | Chi-squared probability density function for chi2 = A and nu = B |
  205. +-----------------+--------+--------------------------------------------------------------------------------------------+
  206. | **COL** | 1 1 | Places column A on the stack |
  207. +-----------------+--------+--------------------------------------------------------------------------------------------+
  208. | **COMB** | 2 1 | Combinations n_C_r, with n = A and r = B |
  209. +-----------------+--------+--------------------------------------------------------------------------------------------+
  210. | **CORRCOEFF** | 2 1 | Correlation coefficient r(A, B) |
  211. +-----------------+--------+--------------------------------------------------------------------------------------------+
  212. | **COS** | 1 1 | cos (A) (A in radians) |
  213. +-----------------+--------+--------------------------------------------------------------------------------------------+
  214. | **COSD** | 1 1 | cos (A) (A in degrees) |
  215. +-----------------+--------+--------------------------------------------------------------------------------------------+
  216. | **COSH** | 1 1 | cosh (A) |
  217. +-----------------+--------+--------------------------------------------------------------------------------------------+
  218. | **COT** | 1 1 | cot (A) (A in radians) |
  219. +-----------------+--------+--------------------------------------------------------------------------------------------+
  220. | **COTD** | 1 1 | cot (A) (A in degrees) |
  221. +-----------------+--------+--------------------------------------------------------------------------------------------+
  222. | **CSC** | 1 1 | csc (A) (A in radians) |
  223. +-----------------+--------+--------------------------------------------------------------------------------------------+
  224. | **CSCD** | 1 1 | csc (A) (A in degrees) |
  225. +-----------------+--------+--------------------------------------------------------------------------------------------+
  226. | **DDT** | 1 1 | d(A)/dt Central 1st derivative |
  227. +-----------------+--------+--------------------------------------------------------------------------------------------+
  228. | **D2DT2** | 1 1 | d^2(A)/dt^2 2nd derivative |
  229. +-----------------+--------+--------------------------------------------------------------------------------------------+
  230. | **D2R** | 1 1 | Converts Degrees to Radians |
  231. +-----------------+--------+--------------------------------------------------------------------------------------------+
  232. | **DENAN** | 2 1 | Replace NaNs in A with values from B |
  233. +-----------------+--------+--------------------------------------------------------------------------------------------+
  234. | **DILOG** | 1 1 | dilog (A) |
  235. +-----------------+--------+--------------------------------------------------------------------------------------------+
  236. | **DIFF** | 1 1 | Forward difference between adjacent elements of A (A[1]-A[0], A[2]-A[1], ..., NaN) |
  237. +-----------------+--------+--------------------------------------------------------------------------------------------+
  238. | **DIV** | 2 1 | A / B |
  239. +-----------------+--------+--------------------------------------------------------------------------------------------+
  240. | **DUP** | 1 2 | Places duplicate of A on the stack |
  241. +-----------------+--------+--------------------------------------------------------------------------------------------+
  242. | **ECDF** | 2 1 | Exponential cumulative distribution function for x = A and lambda = B |
  243. +-----------------+--------+--------------------------------------------------------------------------------------------+
  244. | **ECRIT** | 2 1 | Exponential distribution critical value for alpha = A and lambda = B |
  245. +-----------------+--------+--------------------------------------------------------------------------------------------+
  246. | **EPDF** | 2 1 | Exponential probability density function for x = A and lambda = B |
  247. +-----------------+--------+--------------------------------------------------------------------------------------------+
  248. | **ERF** | 1 1 | Error function erf (A) |
  249. +-----------------+--------+--------------------------------------------------------------------------------------------+
  250. | **ERFC** | 1 1 | Complementary Error function erfc (A) |
  251. +-----------------+--------+--------------------------------------------------------------------------------------------+
  252. | **ERFINV** | 1 1 | Inverse error function of A |
  253. +-----------------+--------+--------------------------------------------------------------------------------------------+
  254. | **EQ** | 2 1 | 1 if A == B, else 0 |
  255. +-----------------+--------+--------------------------------------------------------------------------------------------+
  256. | **EXCH** | 2 2 | Exchanges A and B on the stack |
  257. +-----------------+--------+--------------------------------------------------------------------------------------------+
  258. | **EXP** | 1 1 | exp (A) |
  259. +-----------------+--------+--------------------------------------------------------------------------------------------+
  260. | **FACT** | 1 1 | A! (A factorial) |
  261. +-----------------+--------+--------------------------------------------------------------------------------------------+
  262. | **FCDF** | 3 1 | F cumulative distribution function for F = A, nu1 = B, and nu2 = C |
  263. +-----------------+--------+--------------------------------------------------------------------------------------------+
  264. | **FCRIT** | 3 1 | F distribution critical value for alpha = A, nu1 = B, and nu2 = C |
  265. +-----------------+--------+--------------------------------------------------------------------------------------------+
  266. | **FLIPUD** | 1 1 | Reverse order of each column |
  267. +-----------------+--------+--------------------------------------------------------------------------------------------+
  268. | **FLOOR** | 1 1 | floor (A) (greatest integer <= A) |
  269. +-----------------+--------+--------------------------------------------------------------------------------------------+
  270. | **FMOD** | 2 1 | A % B (remainder after truncated division) |
  271. +-----------------+--------+--------------------------------------------------------------------------------------------+
  272. | **FPDF** | 3 1 | F probability density function for F = A, nu1 = B, and nu2 = C |
  273. +-----------------+--------+--------------------------------------------------------------------------------------------+
  274. | **GE** | 2 1 | 1 if A >= B, else 0 |
  275. +-----------------+--------+--------------------------------------------------------------------------------------------+
  276. | **GT** | 2 1 | 1 if A > B, else 0 |
  277. +-----------------+--------+--------------------------------------------------------------------------------------------+
  278. | **HSV2LAB** | 3 3 | Convert h,s,v triplets to l,a,b triplets, with h = A (0-360), s = B and v = C (0-1) |
  279. +-----------------+--------+--------------------------------------------------------------------------------------------+
  280. | **HSV2RGB** | 3 3 | Convert h,s,v triplets to r,g,b triplets, with h = A (0-360), s = B and v = C (0-1) |
  281. +-----------------+--------+--------------------------------------------------------------------------------------------+
  282. | **HSV2XYZ** | 3 3 | Convert h,s,v triplets to x,t,z triplets, with h = A (0-360), s = B and v = C (0-1) |
  283. +-----------------+--------+--------------------------------------------------------------------------------------------+
  284. | **HYPOT** | 2 1 | hypot (A, B) = sqrt (A\*A + B\*B) |
  285. +-----------------+--------+--------------------------------------------------------------------------------------------+
  286. | **I0** | 1 1 | Modified Bessel function of A (1st kind, order 0) |
  287. +-----------------+--------+--------------------------------------------------------------------------------------------+
  288. | **I1** | 1 1 | Modified Bessel function of A (1st kind, order 1) |
  289. +-----------------+--------+--------------------------------------------------------------------------------------------+
  290. | **IFELSE** | 3 1 | B if A != 0, else C |
  291. +-----------------+--------+--------------------------------------------------------------------------------------------+
  292. | **IN** | 2 1 | Modified Bessel function of A (1st kind, order B) |
  293. +-----------------+--------+--------------------------------------------------------------------------------------------+
  294. | **INRANGE** | 3 1 | 1 if B <= A <= C, else 0 |
  295. +-----------------+--------+--------------------------------------------------------------------------------------------+
  296. | **INT** | 1 1 | Numerically integrate A |
  297. +-----------------+--------+--------------------------------------------------------------------------------------------+
  298. | **INV** | 1 1 | 1 / A |
  299. +-----------------+--------+--------------------------------------------------------------------------------------------+
  300. | **ISFINITE** | 1 1 | 1 if A is finite, else 0 |
  301. +-----------------+--------+--------------------------------------------------------------------------------------------+
  302. | **ISNAN** | 1 1 | 1 if A == NaN, else 0 |
  303. +-----------------+--------+--------------------------------------------------------------------------------------------+
  304. | **J0** | 1 1 | Bessel function of A (1st kind, order 0) |
  305. +-----------------+--------+--------------------------------------------------------------------------------------------+
  306. | **J1** | 1 1 | Bessel function of A (1st kind, order 1) |
  307. +-----------------+--------+--------------------------------------------------------------------------------------------+
  308. | **JN** | 2 1 | Bessel function of A (1st kind, order B) |
  309. +-----------------+--------+--------------------------------------------------------------------------------------------+
  310. | **K0** | 1 1 | Modified Kelvin function of A (2nd kind, order 0) |
  311. +-----------------+--------+--------------------------------------------------------------------------------------------+
  312. | **K1** | 1 1 | Modified Bessel function of A (2nd kind, order 1) |
  313. +-----------------+--------+--------------------------------------------------------------------------------------------+
  314. | **KN** | 2 1 | Modified Bessel function of A (2nd kind, order B) |
  315. +-----------------+--------+--------------------------------------------------------------------------------------------+
  316. | **KEI** | 1 1 | kei (A) |
  317. +-----------------+--------+--------------------------------------------------------------------------------------------+
  318. | **KER** | 1 1 | ker (A) |
  319. +-----------------+--------+--------------------------------------------------------------------------------------------+
  320. | **KURT** | 1 1 | Kurtosis of A |
  321. +-----------------+--------+--------------------------------------------------------------------------------------------+
  322. | **LAB2HSV** | 3 3 | Convert l,a,b triplets to h,s,v triplets |
  323. +-----------------+--------+--------------------------------------------------------------------------------------------+
  324. | **LAB2RGB** | 3 3 | Convert l,a,b triplets to r,g,b triplets |
  325. +-----------------+--------+--------------------------------------------------------------------------------------------+
  326. | **LAB2XYZ** | 3 3 | Convert l,a,b triplets to x,y,z triplets |
  327. +-----------------+--------+--------------------------------------------------------------------------------------------+
  328. | **LCDF** | 1 1 | Laplace cumulative distribution function for z = A |
  329. +-----------------+--------+--------------------------------------------------------------------------------------------+
  330. | **LCRIT** | 1 1 | Laplace distribution critical value for alpha = A |
  331. +-----------------+--------+--------------------------------------------------------------------------------------------+
  332. | **LE** | 2 1 | 1 if A <= B, else 0 |
  333. +-----------------+--------+--------------------------------------------------------------------------------------------+
  334. | **LMSSCL** | 1 1 | LMS (Least Median of Squares) scale estimate (LMS STD) of A |
  335. +-----------------+--------+--------------------------------------------------------------------------------------------+
  336. | **LMSSCLW** | 2 1 | Weighted LMS scale estimate (LMS STD) of A for weights in B |
  337. +-----------------+--------+--------------------------------------------------------------------------------------------+
  338. | **LOG** | 1 1 | log (A) (natural log) |
  339. +-----------------+--------+--------------------------------------------------------------------------------------------+
  340. | **LOG10** | 1 1 | log10 (A) (base 10) |
  341. +-----------------+--------+--------------------------------------------------------------------------------------------+
  342. | **LOG1P** | 1 1 | log (1+A) (accurate for small A) |
  343. +-----------------+--------+--------------------------------------------------------------------------------------------+
  344. | **LOG2** | 1 1 | log2 (A) (base 2) |
  345. +-----------------+--------+--------------------------------------------------------------------------------------------+
  346. | **LOWER** | 1 1 | The lowest (minimum) value of A |
  347. +-----------------+--------+--------------------------------------------------------------------------------------------+
  348. | **LPDF** | 1 1 | Laplace probability density function for z = A |
  349. +-----------------+--------+--------------------------------------------------------------------------------------------+
  350. | **LRAND** | 2 1 | Laplace random noise with mean A and std. deviation B |
  351. +-----------------+--------+--------------------------------------------------------------------------------------------+
  352. | **LSQFIT** | 1 0 | Let current table be [A \| b] return least squares solution x = A \\ b |
  353. +-----------------+--------+--------------------------------------------------------------------------------------------+
  354. | **LT** | 2 1 | 1 if A < B, else 0 |
  355. +-----------------+--------+--------------------------------------------------------------------------------------------+
  356. | **MAD** | 1 1 | Median Absolute Deviation (L1 STD) of A |
  357. +-----------------+--------+--------------------------------------------------------------------------------------------+
  358. | **MADW** | 2 1 | Weighted Median Absolute Deviation (L1 STD) of A for weights in B |
  359. +-----------------+--------+--------------------------------------------------------------------------------------------+
  360. | **MAX** | 2 1 | Maximum of A and B |
  361. +-----------------+--------+--------------------------------------------------------------------------------------------+
  362. | **MEAN** | 1 1 | Mean value of A |
  363. +-----------------+--------+--------------------------------------------------------------------------------------------+
  364. | **MEANW** | 2 1 | Weighted mean value of A for weights in B |
  365. +-----------------+--------+--------------------------------------------------------------------------------------------+
  366. | **MEDIAN** | 1 1 | Median value of A |
  367. +-----------------+--------+--------------------------------------------------------------------------------------------+
  368. | **MEDIANW** | 2 1 | Weighted median value of A for weights in B |
  369. +-----------------+--------+--------------------------------------------------------------------------------------------+
  370. | **MIN** | 2 1 | Minimum of A and B |
  371. +-----------------+--------+--------------------------------------------------------------------------------------------+
  372. | **MOD** | 2 1 | A mod B (remainder after floored division) |
  373. +-----------------+--------+--------------------------------------------------------------------------------------------+
  374. | **MODE** | 1 1 | Mode value (Least Median of Squares) of A |
  375. +-----------------+--------+--------------------------------------------------------------------------------------------+
  376. | **MODEW** | 2 1 | Weighted mode value (Least Median of Squares) of A for weights in B |
  377. +-----------------+--------+--------------------------------------------------------------------------------------------+
  378. | **MUL** | 2 1 | A \* B |
  379. +-----------------+--------+--------------------------------------------------------------------------------------------+
  380. | **NAN** | 2 1 | NaN if A == B, else A |
  381. +-----------------+--------+--------------------------------------------------------------------------------------------+
  382. | **NEG** | 1 1 | -A |
  383. +-----------------+--------+--------------------------------------------------------------------------------------------+
  384. | **NEQ** | 2 1 | 1 if A != B, else 0 |
  385. +-----------------+--------+--------------------------------------------------------------------------------------------+
  386. | **NORM** | 1 1 | Normalize (A) so max(A)-min(A) = 1 |
  387. +-----------------+--------+--------------------------------------------------------------------------------------------+
  388. | **NOT** | 1 1 | NaN if A == NaN, 1 if A == 0, else 0 |
  389. +-----------------+--------+--------------------------------------------------------------------------------------------+
  390. | **NRAND** | 2 1 | Normal, random values with mean A and std. deviation B |
  391. +-----------------+--------+--------------------------------------------------------------------------------------------+
  392. | **OR** | 2 1 | NaN if B == NaN, else A |
  393. +-----------------+--------+--------------------------------------------------------------------------------------------+
  394. | **PCDF** | 2 1 | Poisson cumulative distribution function for x = A and lambda = B |
  395. +-----------------+--------+--------------------------------------------------------------------------------------------+
  396. | **PERM** | 2 1 | Permutations n_P_r, with n = A and r = B |
  397. +-----------------+--------+--------------------------------------------------------------------------------------------+
  398. | **PPDF** | 2 1 | Poisson distribution P(x,lambda), with x = A and lambda = B |
  399. +-----------------+--------+--------------------------------------------------------------------------------------------+
  400. | **PLM** | 3 1 | Associated Legendre polynomial P(A) degree B order C |
  401. +-----------------+--------+--------------------------------------------------------------------------------------------+
  402. | **PLMg** | 3 1 | Normalized associated Legendre polynomial P(A) degree B order C (geophysical convention) |
  403. +-----------------+--------+--------------------------------------------------------------------------------------------+
  404. | **POP** | 1 0 | Delete top element from the stack |
  405. +-----------------+--------+--------------------------------------------------------------------------------------------+
  406. | **POW** | 2 1 | A ^ B |
  407. +-----------------+--------+--------------------------------------------------------------------------------------------+
  408. | **PQUANT** | 2 1 | The B'th quantile (0-100%) of A |
  409. +-----------------+--------+--------------------------------------------------------------------------------------------+
  410. | **PQUANTW** | 3 1 | The C'th weighted quantile (0-100%) of A for weights in B |
  411. +-----------------+--------+--------------------------------------------------------------------------------------------+
  412. | **PSI** | 1 1 | Psi (or Digamma) of A |
  413. +-----------------+--------+--------------------------------------------------------------------------------------------+
  414. | **PV** | 3 1 | Legendre function Pv(A) of degree v = real(B) + imag(C) |
  415. +-----------------+--------+--------------------------------------------------------------------------------------------+
  416. | **QV** | 3 1 | Legendre function Qv(A) of degree v = real(B) + imag(C) |
  417. +-----------------+--------+--------------------------------------------------------------------------------------------+
  418. | **R2** | 2 1 | R2 = A^2 + B^2 |
  419. +-----------------+--------+--------------------------------------------------------------------------------------------+
  420. | **R2D** | 1 1 | Convert radians to degrees |
  421. +-----------------+--------+--------------------------------------------------------------------------------------------+
  422. | **RAND** | 2 1 | Uniform random values between A and B |
  423. +-----------------+--------+--------------------------------------------------------------------------------------------+
  424. | **RCDF** | 1 1 | Rayleigh cumulative distribution function for z = A |
  425. +-----------------+--------+--------------------------------------------------------------------------------------------+
  426. | **RCRIT** | 1 1 | Rayleigh distribution critical value for alpha = A |
  427. +-----------------+--------+--------------------------------------------------------------------------------------------+
  428. | **RGB2HSV** | 3 3 | Convert r,g,b triplets to h,s,v triplets, with r = A, g = B, and b = C (in 0-255 range) |
  429. +-----------------+--------+--------------------------------------------------------------------------------------------+
  430. | **RGB2LAB** | 3 3 | Convert r,g,b triplets to l,a,b triplets, with r = A, g = B, and b = C (in 0-255 range) |
  431. +-----------------+--------+--------------------------------------------------------------------------------------------+
  432. | **RGB2XYZ** | 3 3 | Convert r,g,b triplets to x,y,x triplets, with r = A, g = B, and b = C (in 0-255 range) |
  433. +-----------------+--------+--------------------------------------------------------------------------------------------+
  434. | **RINT** | 1 1 | rint (A) (round to integral value nearest to A) |
  435. +-----------------+--------+--------------------------------------------------------------------------------------------+
  436. | **RMS** | 1 1 | Root-mean-square of A |
  437. +-----------------+--------+--------------------------------------------------------------------------------------------+
  438. | **RMSW** | 1 1 | Weighted root-mean-square of A for weights in B |
  439. +-----------------+--------+--------------------------------------------------------------------------------------------+
  440. | **RPDF** | 1 1 | Rayleigh probability density function for z = A |
  441. +-----------------+--------+--------------------------------------------------------------------------------------------+
  442. | **ROLL** | 2 0 | Cyclicly shifts the top A stack items by an amount B |
  443. +-----------------+--------+--------------------------------------------------------------------------------------------+
  444. | **ROTT** | 2 1 | Rotate A by the (constant) shift B in the t-direction |
  445. +-----------------+--------+--------------------------------------------------------------------------------------------+
  446. | **SEC** | 1 1 | sec (A) (A in radians) |
  447. +-----------------+--------+--------------------------------------------------------------------------------------------+
  448. | **SECD** | 1 1 | sec (A) (A in degrees) |
  449. +-----------------+--------+--------------------------------------------------------------------------------------------+
  450. | **SIGN** | 1 1 | sign (+1 or -1) of A |
  451. +-----------------+--------+--------------------------------------------------------------------------------------------+
  452. | **SIN** | 1 1 | sin (A) (A in radians) |
  453. +-----------------+--------+--------------------------------------------------------------------------------------------+
  454. | **SINC** | 1 1 | sinc (A) (sin (pi\*A)/(pi\*A)) |
  455. +-----------------+--------+--------------------------------------------------------------------------------------------+
  456. | **SIND** | 1 1 | sin (A) (A in degrees) |
  457. +-----------------+--------+--------------------------------------------------------------------------------------------+
  458. | **SINH** | 1 1 | sinh (A) |
  459. +-----------------+--------+--------------------------------------------------------------------------------------------+
  460. | **SKEW** | 1 1 | Skewness of A |
  461. +-----------------+--------+--------------------------------------------------------------------------------------------+
  462. | **SQR** | 1 1 | A^2 |
  463. +-----------------+--------+--------------------------------------------------------------------------------------------+
  464. | **SQRT** | 1 1 | sqrt (A) |
  465. +-----------------+--------+--------------------------------------------------------------------------------------------+
  466. | **STD** | 1 1 | Standard deviation of A |
  467. +-----------------+--------+--------------------------------------------------------------------------------------------+
  468. | **STDW** | 2 1 | Weighted standard deviation of A for weights in B |
  469. +-----------------+--------+--------------------------------------------------------------------------------------------+
  470. | **STEP** | 1 1 | Heaviside step function H(A) |
  471. +-----------------+--------+--------------------------------------------------------------------------------------------+
  472. | **STEPT** | 1 1 | Heaviside step function H(t-A) |
  473. +-----------------+--------+--------------------------------------------------------------------------------------------+
  474. | **SUB** | 2 1 | A - B |
  475. +-----------------+--------+--------------------------------------------------------------------------------------------+
  476. | **SUM** | 1 1 | Cumulative sum of A |
  477. +-----------------+--------+--------------------------------------------------------------------------------------------+
  478. | **TAN** | 1 1 | tan (A) (A in radians) |
  479. +-----------------+--------+--------------------------------------------------------------------------------------------+
  480. | **TAND** | 1 1 | tan (A) (A in degrees) |
  481. +-----------------+--------+--------------------------------------------------------------------------------------------+
  482. | **TANH** | 1 1 | tanh (A) |
  483. +-----------------+--------+--------------------------------------------------------------------------------------------+
  484. | **TAPER** | 1 1 | Unit weights cosine-tapered to zero within A of end margins |
  485. +-----------------+--------+--------------------------------------------------------------------------------------------+
  486. | **TN** | 2 1 | Chebyshev polynomial Tn(-1<A<+1) of degree B |
  487. +-----------------+--------+--------------------------------------------------------------------------------------------+
  488. | **TCRIT** | 2 1 | Student's t distribution critical value for alpha = A and nu = B |
  489. +-----------------+--------+--------------------------------------------------------------------------------------------+
  490. | **TPDF** | 2 1 | Student's t probability density function for t = A, and nu = B |
  491. +-----------------+--------+--------------------------------------------------------------------------------------------+
  492. | **TCDF** | 2 1 | Student's t cumulative distribution function for t = A, and nu = B |
  493. +-----------------+--------+--------------------------------------------------------------------------------------------+
  494. | **UPPER** | 1 1 | The highest (maximum) value of A |
  495. +-----------------+--------+--------------------------------------------------------------------------------------------+
  496. | **VAR** | 1 1 | Variance of A |
  497. +-----------------+--------+--------------------------------------------------------------------------------------------+
  498. | **VARW** | 2 1 | Weighted variance of A for weights in B |
  499. +-----------------+--------+--------------------------------------------------------------------------------------------+
  500. | **WCDF** | 3 1 | Weibull cumulative distribution function for x = A, scale = B, and shape = C |
  501. +-----------------+--------+--------------------------------------------------------------------------------------------+
  502. | **WCRIT** | 3 1 | Weibull distribution critical value for alpha = A, scale = B, and shape = C |
  503. +-----------------+--------+--------------------------------------------------------------------------------------------+
  504. | **WPDF** | 3 1 | Weibull density distribution P(x,scale,shape), with x = A, scale = B, and shape = C |
  505. +-----------------+--------+--------------------------------------------------------------------------------------------+
  506. | **XOR** | 2 1 | B if A == NaN, else A |
  507. +-----------------+--------+--------------------------------------------------------------------------------------------+
  508. | **XYZ2HSV** | 3 3 | Convert x,y,z triplets to h,s,v triplets |
  509. +-----------------+--------+--------------------------------------------------------------------------------------------+
  510. | **XYZ2LAB** | 3 3 | Convert x,y,z triplets to l,a,b triplets |
  511. +-----------------+--------+--------------------------------------------------------------------------------------------+
  512. | **XYZ2RGB** | 3 3 | Convert x,y,z triplets to r,g,b triplets |
  513. +-----------------+--------+--------------------------------------------------------------------------------------------+
  514. | **Y0** | 1 1 | Bessel function of A (2nd kind, order 0) |
  515. +-----------------+--------+--------------------------------------------------------------------------------------------+
  516. | **Y1** | 1 1 | Bessel function of A (2nd kind, order 1) |
  517. +-----------------+--------+--------------------------------------------------------------------------------------------+
  518. | **YN** | 2 1 | Bessel function of A (2nd kind, order B) |
  519. +-----------------+--------+--------------------------------------------------------------------------------------------+
  520. | **ZCDF** | 1 1 | Normal cumulative distribution function for z = A |
  521. +-----------------+--------+--------------------------------------------------------------------------------------------+
  522. | **ZPDF** | 1 1 | Normal probability density function for z = A |
  523. +-----------------+--------+--------------------------------------------------------------------------------------------+
  524. | **ZCRIT** | 1 1 | Normal distribution critical value for alpha = A |
  525. +-----------------+--------+--------------------------------------------------------------------------------------------+
  526. | **ROOTS** | 2 1 | Treats col A as f(t) = 0 and returns its roots |
  527. +-----------------+--------+--------------------------------------------------------------------------------------------+
  528. Symbols
  529. -------
  530. The following symbols have special meaning:
  531. +-------------+-----------------------------------------+
  532. | **PI** | 3.1415926... |
  533. +-------------+-----------------------------------------+
  534. | **E** | 2.7182818... |
  535. +-------------+-----------------------------------------+
  536. | **EULER** | 0.5772156... |
  537. +-------------+-----------------------------------------+
  538. | **PHI** | 1.6180339... (golden ratio) |
  539. +-------------+-----------------------------------------+
  540. | **EPS_F** | 1.192092896e-07 (sgl. prec. eps) |
  541. +-------------+-----------------------------------------+
  542. | **EPS_D** | 2.2204460492503131e-16 (dbl. prec. eps) |
  543. +-------------+-----------------------------------------+
  544. | **TMIN** | Minimum t value |
  545. +-------------+-----------------------------------------+
  546. | **TMAX** | Maximum t value |
  547. +-------------+-----------------------------------------+
  548. | **TRANGE** | Range of t values |
  549. +-------------+-----------------------------------------+
  550. | **TINC** | t increment |
  551. +-------------+-----------------------------------------+
  552. | **N** | The number of records |
  553. +-------------+-----------------------------------------+
  554. | **T** | Table with t-coordinates |
  555. +-------------+-----------------------------------------+
  556. | **TNORM** | Table with normalized t-coordinates |
  557. +-------------+-----------------------------------------+
  558. | **TROW** | Table with row numbers 1, 2, ..., N-1 |
  559. +-------------+-----------------------------------------+
  560. .. include:: explain_precision.rst_
  561. Notes On Operators
  562. ------------------
  563. #. The operators **PLM** and **PLMg** calculate the associated Legendre
  564. polynomial of degree L and order M in x which must satisfy -1 <= x <= +1
  565. and 0 <= M <= L. x, L, and M are the three arguments preceding the
  566. operator. **PLM** is not normalized and includes the Condon-Shortley
  567. phase (-1)^M. **PLMg** is normalized in the way that is most commonly
  568. used in geophysics. The C-S phase can be added by using -M as argument.
  569. **PLM** will overflow at higher degrees, whereas **PLMg** is stable
  570. until ultra high degrees (at least 3000).
  571. #. Files that have the same names as some operators, e.g., **ADD**,
  572. **SIGN**, **=**, etc. should be identified by prepending the current
  573. directory (i.e., ./).
  574. #. The stack depth limit is hard-wired to 100.
  575. #. All functions expecting a positive radius (e.g., **LOG**, **KEI**,
  576. etc.) are passed the absolute value of their argument.
  577. #. The **DDT** and **D2DT2** functions only work on regularly spaced data.
  578. #. All derivatives are based on central finite differences, with
  579. natural boundary conditions.
  580. #. **ROOTS** must be the last operator on the stack, only followed by **=**.
  581. .. include:: explain_sto_rcl_clr.rst_
  582. #. The bitwise operators
  583. (**BITAND**, **BITLEFT**, **BITNOT**, **BITOR**, **BITRIGHT**,
  584. **BITTEST**, and **BITXOR**) convert a tables's double precision values
  585. to unsigned 64-bit ints to perform the bitwise operations. Consequently,
  586. the largest whole integer value that can be stored in a double precision
  587. value is 2^53 or 9,007,199,254,740,992. Any higher result will be masked
  588. to fit in the lower 54 bits. Thus, bit operations are effectively limited
  589. to 54 bits. All bitwise operators return NaN if given NaN arguments or
  590. bit-settings <= 0.
  591. #. TAPER will interpret its argument to be a width in the same units as
  592. the time-axis, but if no time is provided (i.e., plain data tables) then
  593. the width is taken to be given in number of rows.
  594. #. The color-triplet conversion functions (**RGB2HSV**, etc.) includes not
  595. only r,g,b and h,s,v triplet conversions, but also l,a,b (CIE L a b ) and
  596. sRGB (x, y, z) conversions between all four color spaces. These functions
  597. behave differently whether **-Q** is used or not. With **-Q** we expect
  598. three input constants and we place three output results on the stack. Since
  599. only the top stack item is printed, you must use operators such as POP and
  600. ROLL to get to the item of interest. Without **-Q**, these operators work
  601. across the three columns and modify the three column entries, returning their
  602. result as a single three-column item on the stack.
  603. Macros
  604. ------
  605. Users may save their favorite operator combinations as macros via the
  606. file *gmtmath.macros* in their current or user directory. The file may contain
  607. any number of macros (one per record); comment lines starting with # are
  608. skipped. The format for the macros is **name** = **arg1 arg2 ... arg2**
  609. [ : *comment*] where **name** is how the macro will be used. When this
  610. operator appears on the command line we simply replace it with the
  611. listed argument list. No macro may call another macro. As an example,
  612. the following macro expects that the time-column contains seafloor ages
  613. in Myr and computes the predicted half-space bathymetry:
  614. **DEPTH** = **SQRT 350 MUL 2500 ADD NEG** : *usage: DEPTH to return
  615. half-space seafloor depths*
  616. **Note**: Because geographic or time constants may be present in a macro, it
  617. is required that the optional comment flag (:) must be followed by a space.
  618. As another example, we show a macro **GPSWEEK** which determines which GPS week
  619. a timestamp belongs to:
  620. **GPSWEEK** = **1980-01-06T00:00:00 SUB 86400 DIV 7 DIV FLOOR** : *usage: GPS week without rollover*
  621. Active Column Selection
  622. -----------------------
  623. When **-C**\ *cols* is set then any operation, including loading of data from files, will
  624. restrict which columns are affected.
  625. To avoid unexpected results, note that if you issue a **-C**\ *cols* option before you load
  626. in the data then only those columns will be updated, hence the unspecified columns will be zero.
  627. On the other hand, if you load the file first and then issue **-C**\ *cols* then the unspecified
  628. columns will have been loaded but are then ignored until you undo the effect of **-C**.
  629. Examples
  630. --------
  631. .. include:: explain_example.rst_
  632. To add two plot dimensions of different units, we can run
  633. ::
  634. length=`gmt math -Q 15c 2i SUB =`
  635. To take the square root of the content of the second data column being
  636. piped through **gmtmath** by process1 and pipe it through a 3rd process, use
  637. ::
  638. process1 | gmt math STDIN SQRT = | process3
  639. To take log10 of the average of 2 data files, use
  640. ::
  641. gmt math file1.txt file2.txt ADD 0.5 MUL LOG10 = file3.txt
  642. Given the file samples.txt, which holds seafloor ages in m.y. and seafloor
  643. depth in m, use the relation depth(in m) = 2500 + 350 \* sqrt (age) to
  644. print the depth anomalies:
  645. ::
  646. gmt math samples.txt T SQRT 350 MUL 2500 ADD SUB = | lpr
  647. To take the average of columns 1 and 4-6 in the three data sets sizes.1,
  648. sizes.2, and sizes.3, use
  649. ::
  650. gmt math -C1,4-6 sizes.1 sizes.2 ADD sizes.3 ADD 3 DIV = ave.txt
  651. To take the 1-column data set ages.txt and calculate the modal value and
  652. assign it to a variable, try
  653. ::
  654. mode_age=`gmt math -S -T ages.txt MODE =`
  655. To evaluate the dilog(x) function for coordinates given in the file t.txt:
  656. ::
  657. gmt math -Tt.txt T DILOG = dilog.txt
  658. To demonstrate the use of stored variables, consider this sum of the
  659. first 3 cosine harmonics where we store and repeatedly recall the
  660. trigonometric argument (2\*pi\*T/360):
  661. ::
  662. gmt math -T0/360/1 2 PI MUL 360 DIV T MUL STO@kT COS @kT 2 MUL COS ADD @kT 3 MUL COS ADD = harmonics.txt
  663. To use **gmtmath** as a RPN Hewlett-Packard calculator on scalars (i.e., no
  664. input files) and calculate arbitrary expressions, use the **-Q** option.
  665. As an example, we will calculate the value of Kei (((1 + 1.75)/2.2) +
  666. cos (60)) and store the result in the shell variable z:
  667. ::
  668. z=`gmt math -Q 1 1.75 ADD 2.2 DIV 60 COSD ADD KEI =`
  669. To convert the r,g,b value for yellow to h,s,v and save the hue, try
  670. ::
  671. set hue = `gmt math -Q 255 255 0 RGB2HSV POP POP =`
  672. To use **gmtmath** as a general least squares equation solver, imagine
  673. that the current table is the augmented matrix [ A \| b ] and you want
  674. the least squares solution x to the matrix equation A \* x = b. The
  675. operator **LSQFIT** does this; it is your job to populate the matrix
  676. correctly first. The **-A** option will facilitate this. Suppose you
  677. have a 2-column file ty.txt with *t* and *b(t)* and you would like to fit
  678. a the model y(t) = a + b\*t + c\*H(t-t0), where H is the Heaviside step
  679. function for a given t0 = 1.55. Then, you need a 4-column augmented
  680. table loaded with t in column 1 and your observed y(t) in column 3. The
  681. calculation becomes
  682. ::
  683. gmt math -N4/1 -Aty.txt -C0 1 ADD -C2 1.55 STEPT ADD -Ca LSQFIT = solution.txt
  684. Note we use the **-C** option to select which columns we are working on,
  685. then make active all the columns we need (here all of them, with
  686. **-Ca**) before calling **LSQFIT**. The second and fourth columns (col
  687. numbers 1 and 3) are preloaded with t and y(t), respectively, the other
  688. columns are zero. If you already have a pre-calculated table with the
  689. augmented matrix [ A \| b ] in a file (say lsqsys.txt), the least squares
  690. solution is simply
  691. ::
  692. gmt math -T lsqsys.txt LSQFIT = solution.txt
  693. Users must be aware that when **-C** controls which columns are to be
  694. active the control extends to placing columns from files as well.
  695. Contrast the different result obtained by these very similar commands:
  696. ::
  697. echo 1 2 3 4 | gmt math STDIN -C3 1 ADD =
  698. 1 2 3 5
  699. versus
  700. ::
  701. echo 1 2 3 4 | gmt math -C3 STDIN 1 ADD =
  702. 0 0 0 5
  703. References
  704. ----------
  705. Abramowitz, M., and I. A. Stegun, 1964, *Handbook of Mathematical
  706. Functions*, Applied Mathematics Series, vol. 55, Dover, New York.
  707. Holmes, S. A., and W. E. Featherstone, 2002, A unified approach to the
  708. Clenshaw summation and the recursive computation of very high degree and
  709. order normalized associated Legendre functions. *Journal of Geodesy*,
  710. 76, 279-299.
  711. Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery,
  712. 1992, *Numerical Recipes*, 2nd edition, Cambridge Univ., New York.
  713. Spanier, J., and K. B. Oldman, 1987, *An Atlas of Functions*, Hemisphere
  714. Publishing Corp.
  715. See Also
  716. --------
  717. :doc:`gmt`,
  718. :doc:`grdmath`
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...