File: fit.htm

package info (click to toggle)
extrema 4.3.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 19,212 kB
  • ctags: 6,452
  • sloc: cpp: 86,428; sh: 8,229; makefile: 814
file content (42 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download
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
<HTML>
<HEAD>
<TITLE>Fit a function</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">

<p>
 Read in some x-y data and then find a least-squares fit to the data as a linear
 combination of given functions, or as a nonlinear function.</P>
<P>
 Read in arrays <code>x</code> and <code>y</code> from
 <a href="xyL.dat">xyL.dat</a> and find the best 5th degree polynomial fit</P>
<P>
 <font color="blue"><pre>
 read xyL.dat x y
 scalar\fit a0 a1 a2 a3 a4 a5
 fit y = a0+a1*x+a1*x^2+a2*x^3+a3*x^4+a4*x^5
 </pre></font></P>
<P>
 <img src="fit1.gif"></P>
<P>
 Read in arrays <code>x</code> and <code>y</code> from <a href="xyN.dat">xyN.dat</a>
 and find the best fit to <code>y(x) = a0*exp(a1*x)*sin(a2*x+a3)</code></P>
<P>
 <font color="blue"><pre>
 read xyN.dat x y
 scalar\fit a0 a1 a2 a3
 a0 = 5
 a1 = -.5
 a2 = 1.5
 a3 = .5
 fit y = a0*exp(a1*x)*sin(a2*x+a3)
 </pre></font></P>
<P>
 <img src="fit2.gif"></P>
<P>
 <a href="readdata.htm"><img src="../shadow_left.gif">&nbsp;
 <font size="+1" color="olive">Read data from files</font></a><br />
 <a href="defineplotfunction.htm"><img src="../shadow_right.gif">&nbsp;
 <font size="+1" color="olive">Define and plot a function</font></a></P>
</BODY>
</HTML>