|
20 | 20 | margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ |
21 | 21 | vertical-align: middle; |
22 | 22 | } |
| 23 | +/* CSS for syntax highlighting */ |
| 24 | +html { -webkit-text-size-adjust: 100%; } |
| 25 | +pre > code.sourceCode { white-space: pre; position: relative; } |
| 26 | +pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } |
| 27 | +pre > code.sourceCode > span:empty { height: 1.2em; } |
| 28 | +.sourceCode { overflow: visible; } |
| 29 | +code.sourceCode > span { color: inherit; text-decoration: inherit; } |
| 30 | +div.sourceCode { margin: 1em 0; } |
| 31 | +pre.sourceCode { margin: 0; } |
| 32 | +@media screen { |
| 33 | +div.sourceCode { overflow: auto; } |
| 34 | +} |
| 35 | +@media print { |
| 36 | +pre > code.sourceCode { white-space: pre-wrap; } |
| 37 | +pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } |
| 38 | +} |
| 39 | +pre.numberSource code |
| 40 | + { counter-reset: source-line 0; } |
| 41 | +pre.numberSource code > span |
| 42 | + { position: relative; left: -4em; counter-increment: source-line; } |
| 43 | +pre.numberSource code > span > a:first-child::before |
| 44 | + { content: counter(source-line); |
| 45 | + position: relative; left: -1em; text-align: right; vertical-align: baseline; |
| 46 | + border: none; display: inline-block; |
| 47 | + -webkit-touch-callout: none; -webkit-user-select: none; |
| 48 | + -khtml-user-select: none; -moz-user-select: none; |
| 49 | + -ms-user-select: none; user-select: none; |
| 50 | + padding: 0 4px; width: 4em; |
| 51 | + } |
| 52 | +pre.numberSource { margin-left: 3em; padding-left: 4px; } |
| 53 | +div.sourceCode |
| 54 | + { } |
| 55 | +@media screen { |
| 56 | +pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } |
| 57 | +} |
23 | 58 | </style> |
24 | 59 |
|
25 | 60 |
|
|
70 | 105 | } |
71 | 106 | }</script> |
72 | 107 |
|
| 108 | + <script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6"></script> |
| 109 | + <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script> |
| 110 | + |
| 111 | +<script type="text/javascript"> |
| 112 | +const typesetMath = (el) => { |
| 113 | + if (window.MathJax) { |
| 114 | + // MathJax Typeset |
| 115 | + window.MathJax.typeset([el]); |
| 116 | + } else if (window.katex) { |
| 117 | + // KaTeX Render |
| 118 | + var mathElements = el.getElementsByClassName("math"); |
| 119 | + var macros = []; |
| 120 | + for (var i = 0; i < mathElements.length; i++) { |
| 121 | + var texText = mathElements[i].firstChild; |
| 122 | + if (mathElements[i].tagName == "SPAN" && texText && texText.data) { |
| 123 | + window.katex.render(texText.data, mathElements[i], { |
| 124 | + displayMode: mathElements[i].classList.contains('display'), |
| 125 | + throwOnError: false, |
| 126 | + macros: macros, |
| 127 | + fleqn: false |
| 128 | + }); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +window.Quarto = { |
| 134 | + typesetMath |
| 135 | +}; |
| 136 | +</script> |
73 | 137 |
|
74 | 138 | <link rel="stylesheet" href="../../custom.css"> |
75 | 139 | </head> |
|
414 | 478 | <h2 id="toc-title">On this page</h2> |
415 | 479 |
|
416 | 480 | <ul class="collapse"> |
417 | | - <li><a href="#source-code" id="toc-source-code" class="nav-link active" data-scroll-target="#source-code">Source Code</a></li> |
| 481 | + <li><a href="#examples" id="toc-examples" class="nav-link active" data-scroll-target="#examples">Examples</a></li> |
| 482 | + <li><a href="#source-code" id="toc-source-code" class="nav-link" data-scroll-target="#source-code">Source Code</a></li> |
418 | 483 | <li><a href="#see-also" id="toc-see-also" class="nav-link" data-scroll-target="#see-also">See Also</a></li> |
419 | 484 | </ul> |
420 | 485 | </nav> |
@@ -442,23 +507,47 @@ <h1 class="title">polyfit</h1> |
442 | 507 |
|
443 | 508 |
|
444 | 509 | <pre><code>p = polyfit(x, y, n=length(x)-1; xscale=1)</code></pre> |
445 | | -<p>Returns the coefficients for a polynomial p(x) of degree <code>n</code> that is the least-squares best fit for the data in y. The coefficients in p are in ascending powers, and the length of p is n+1.</p> |
| 510 | +<p>Returns the coefficients for a polynomial p(x) of degree <code>n</code> that is the least-squares best fit for the data in y. The coefficients in p are in ascending powers, and the length of p is n+1, where</p> |
| 511 | +<p><span class="math display">\[p(x) = p[1] + p[2]x + p[3]x^2 + \ldots + p[n+1]x^n\]</span></p> |
446 | 512 | <p>The <code>xscale</code> parameter is useful when needing to get coeficients in different x units. For example when converting months or seconds into years.</p> |
| 513 | +<section id="examples" class="level2"> |
| 514 | +<h2 class="anchored" data-anchor-id="examples">Examples</h2> |
| 515 | +<p>Fit a simple linear regression model to a set of discrete 2-D data points.</p> |
| 516 | +<p>Create a few vectors of sample data points (x,y). Fit a first degree polynomial to the data.</p> |
| 517 | +<div id="ad1df5e1" class="cell" data-execution_count="1"> |
| 518 | +<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">GMT</span></span> |
| 519 | +<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span> |
| 520 | +<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">50</span>; </span> |
| 521 | +<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>y <span class="op">=</span> <span class="op">-</span><span class="fl">0.3</span><span class="op">*</span>x <span class="op">+</span> <span class="fl">2</span><span class="fu">*randn</span>(<span class="fl">50</span>); </span> |
| 522 | +<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> <span class="fu">polyfit</span>(x,y,<span class="fl">1</span>);</span> |
| 523 | +<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span> |
| 524 | +<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>f <span class="op">=</span> <span class="fu">polyval</span>(p,x); <span class="co"># Evaluate the fitted polynomial p at the points in x.</span></span> |
| 525 | +<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(x,y,marker<span class="op">=:</span>circ, legend<span class="op">=</span><span class="st">"data"</span>)</span> |
| 526 | +<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(x, f, lc<span class="op">=:</span>brown, legend<span class="op">=</span><span class="st">"linear fit"</span>, show<span class="op">=</span><span class="cn">true</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div> |
| 527 | +<div class="cell-output cell-output-display"> |
| 528 | +<div> |
| 529 | +<figure class="figure"> |
| 530 | +<p><img src="polyfit_files/figure-html/cell-2-output-1.png" class="img-fluid figure-img"></p> |
| 531 | +</figure> |
| 532 | +</div> |
| 533 | +</div> |
| 534 | +</div> |
| 535 | +</section> |
447 | 536 | <section id="source-code" class="level2"> |
448 | 537 | <h2 class="anchored" data-anchor-id="source-code">Source Code</h2> |
449 | 538 | <p>This function has multiple methods:</p> |
450 | 539 | <ul> |
451 | | -<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1034"><code>polyfit(x, y, n::Int64; xscale)</code></a> - utils.jl:1034</li> |
452 | | -<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1033"><code>polyfit(D::GMTdataset, n::Int64; xscale)</code></a> - utils.jl:1033</li> |
453 | | -<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1034"><code>polyfit(x, y; ...)</code></a> - utils.jl:1034</li> |
454 | | -<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1033"><code>polyfit(D::GMTdataset; ...)</code></a> - utils.jl:1033</li> |
| 540 | +<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1059"><code>polyfit(x, y, n::Int64; xscale)</code></a> - utils.jl:1059</li> |
| 541 | +<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1058"><code>polyfit(D::GMTdataset, n::Int64; xscale)</code></a> - utils.jl:1058</li> |
| 542 | +<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1059"><code>polyfit(x, y; ...)</code></a> - utils.jl:1059</li> |
| 543 | +<li><a href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/utils.jl#L1058"><code>polyfit(D::GMTdataset; ...)</code></a> - utils.jl:1058</li> |
455 | 544 | </ul> |
456 | 545 | </section> |
457 | 546 | <section id="see-also" class="level2"> |
458 | 547 | <h2 class="anchored" data-anchor-id="see-also">See Also</h2> |
| 548 | +<p><a href="../..\documentation/utilities/linearfitxy.html">linearfitxy</a>, <a href="../..\documentation/modules/polyval.html">polyval</a>, <a href="../..\documentation/utilities/plotlinefit.html">plotlinefit</a>, <a href="../..\documentation/modules/plot.html">plot</a></p> |
459 | 549 | <ul> |
460 | 550 | <li><a href="../alphabetical.html">Alphabetical Function List</a></li> |
461 | | -<li><a href="https://www.generic-mapping-tools.org/GMTjl_doc/">GMT.jl Documentation</a></li> |
462 | 551 | </ul> |
463 | 552 |
|
464 | 553 |
|
|
0 commit comments