f

#### Best fit line for sinusoid

```Hi all,

I was wondering if there was a 'simple' way to get IDL to plot a best fit l=
ine for a sinusoidally-varying data set. For example, say temperatures were=
recorded each hour for 5 days at a certain location, with each measurement=
having an error of 2 deg C. Then we would have something like:

day =3D findgen(121)/24
temp =3D 15 + 10*sin(10*!pi*findgen(121)/120) + 5*randomu(seed, 121)
error =3D fltarr(121)+2

Is it possible from these three arrays for IDL to work out and plot a best =
fit line? I have searched online, and can't really find what I'm looking fo=
r. (surprisingly I have never had to plot a best fit line to anything befor=
e!)

Cheers,

Liam
``` 0  liam
9/30/2015 2:22:57 PM comp.lang.idl-pvwave  12260 articles. 4 followers. 4 Replies 408 Views Similar Articles

[PageSpeed] 21

```liam.steele@gmx.co.uk writes:

> I was wondering if there was a 'simple' way to get IDL to plot a best fit line for a sinusoidally-varying data set. For example, say temperatures were recorded each hour for 5 days at a certain location, with each measurement having an error of 2 deg C. Then we would have something like:
>
> day = findgen(121)/24
> temp = 15 + 10*sin(10*!pi*findgen(121)/120) + 5*randomu(seed, 121)
> error = fltarr(121)+2
>
> Is it possible from these three arrays for IDL to work out and plot a best fit line? I have searched online, and can't really find what I'm looking for. (surprisingly I have never had to plot a best fit line to anything before!)

You will do well to start here:

http://cow.physics.wisc.edu/~craigm/idl/fitting.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
``` 0  David
9/30/2015 2:37:45 PM
```On Wednesday, 30 September 2015 15:37:47 UTC+1, David Fanning  wrote:
> liam.steele@gmx.co.uk writes:=20
>=20
> > I was wondering if there was a 'simple' way to get IDL to plot a best f=
it line for a sinusoidally-varying data set. For example, say temperatures =
were recorded each hour for 5 days at a certain location, with each measure=
ment having an error of 2 deg C. Then we would have something like:
> >=20
> > day =3D findgen(121)/24
> > temp =3D 15 + 10*sin(10*!pi*findgen(121)/120) + 5*randomu(seed, 121)
> > error =3D fltarr(121)+2
> >=20
> > Is it possible from these three arrays for IDL to work out and plot a b=
est fit line? I have searched online, and can't really find what I'm lookin=
g for. (surprisingly I have never had to plot a best fit line to anything b=
efore!)
>=20
> You will do well to start here:
>=20
>    http://cow.physics.wisc.edu/~craigm/idl/fitting.html
>=20
> Cheers,
>=20
> David
> --=20
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Aha! That looks far more useful than anything I found. Thanks very much.
``` 0  liam
9/30/2015 2:51:31 PM
```On Wednesday, September 30, 2015 at 8:51:33 AM UTC-6, liam....@gmx.co.uk wr=
ote:
> On Wednesday, 30 September 2015 15:37:47 UTC+1, David Fanning  wrote:
> > liam.steele@gmx.co.uk writes:=20
> >=20
> > > I was wondering if there was a 'simple' way to get IDL to plot a best=
fit line for a sinusoidally-varying data set. For example, say temperature=
s were recorded each hour for 5 days at a certain location, with each measu=
rement having an error of 2 deg C. Then we would have something like:
> > >=20
> > > day =3D findgen(121)/24
> > > temp =3D 15 + 10*sin(10*!pi*findgen(121)/120) + 5*randomu(seed, 121)
> > > error =3D fltarr(121)+2
> > >=20
> > > Is it possible from these three arrays for IDL to work out and plot a=
best fit line? I have searched online, and can't really find what I'm look=
ing for. (surprisingly I have never had to plot a best fit line to anything=
before!)
> >=20
> > You will do well to start here:
> >=20
> >    http://cow.physics.wisc.edu/~craigm/idl/fitting.html
> >=20
> > Cheers,
> >=20
> > David
> > --=20
> > David Fanning, Ph.D.
> > Fanning Software Consulting, Inc.
> > Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
> > Sepore ma de ni thue. ("Perhaps thou speakest truth.")
>=20
> Aha! That looks far more useful than anything I found. Thanks very much.

Hi Liam,

Once you've done your fit, you can do an error bar plot like this:

day =3D dindgen(121)/24
temp =3D 15 + 10*sin(10*!pi*findgen(121)/120) + 5*randomu(seed, 121)
error =3D fltarr(121)+2
p =3D errorplot(day, temp, error, linestyle=3D'none')
yfit =3D ...
p1 =3D plot(day, yfit, '2', /overplot)

Cheers,
Chris
``` 0  Chris
9/30/2015 3:19:43 PM
```On Wednesday, 30 September 2015 15:23:01 UTC+1, liam....@gmx.co.uk  wrote:
> Hi all,
>=20
> I was wondering if there was a 'simple' way to get IDL to plot a best fit=
line for a sinusoidally-varying data set. For example, say temperatures we=
re recorded each hour for 5 days at a certain location, with each measureme=
nt having an error of 2 deg C. Then we would have something like:
>=20
> day =3D findgen(121)/24
> temp =3D 15 + 10*sin(10*!pi*findgen(121)/120) + 5*randomu(seed, 121)
> error =3D fltarr(121)+2
>=20
> Is it possible from these three arrays for IDL to work out and plot a bes=
t fit line? I have searched online, and can't really find what I'm looking =
for. (surprisingly I have never had to plot a best fit line to anything bef=
ore!)
>=20
> Cheers,
>=20
> Liam

Thanks for the tips everyone. I've managed to get something which I think l=
ooks correct, so that's good! I'll add the error bar plot when I work on th=

day =3D findgen(121)/24
temp =3D 15 + 10*sin(10*!pi*findgen(121)/120)+5*randomu(seed, 121)
error =3D fltarr(121)+2
meanval =3D mean(temp)

expr =3D 'P + P*sin(P*2*!pi*findgen(P)/(P-1) + P)'
start =3D [meanval, (max(temp)-min(temp))/2, 5., 121, 0.]

result =3D MPFITEXPR(expr, day, temp, error, start)
fitline =3D result + result*sin(result*2*!pi*findgen(result)/(r=
esult-1) + result)

plot, day, temp, psym=3Dsym(2)
oplot, day, fitline
``` 0  liam
9/30/2015 4:07:24 PM Similar Artilces:

Best fit line for an exponential line
Hi, I am new to using GNUPLOT and am trying to find the best fit line (to determine the slope) of a line that follows Power Law (is an exponential line). I realize I have to use a function f(x) = a*b**x. But, I do not know what to do next. Any help in this matter would be greatly appreciated. Thanks, Divya Divya Rao <divyarao09@yahoo.com> wrote: > Hi, > I am new to using GNUPLOT and am trying to find the best fit line (to > determine the slope) of a line that follows Power Law (is an > exponential line). First, a terminology issue: an exponential curv...

Line of best fit
I am new to python so apologies for the ignorance with this question. How would I apply a line of best fit to a plot? My data are netCDF4 data files and this is essentially what I have done so far: swh1=netCDF4.Dataset('filename','r') hs1=swh1.variables['hs'] swh2=netCDF4.Dataset('filename'.'r') hs2=swh2.variables['hs'] plt.plot(hs1,hs2,'.') Cheers, Jamie --001a113a6020e6901104f5e5a9f1 Content-Type: text/plain; charset=UTF-8 None of these are in the standard library but why re-invent the wheel? Using numpy:...

Best fit line?
Hi. Is there a function to calculate/plot the best fit line given a few (approx 3) points? I don't have any toolboxes, nor can I afford any. Can any function in the basic matlab application do this? Thanks! "Amir " <amirschricker.DELETE@DELETE.gmail.DELETE.com> wrote in message <g4o8va\$aa7\$1@fred.mathworks.com>... > Hi. Is there a function to calculate/plot the best fit line > given a few (approx 3) points? I don't have any toolboxes, > nor can I afford any. > > Can any function in the basic matlab application do this? Yes. help polyfit J...

Line of best fit
I'm a total newbie at this guys. I have the following data in an .m file: x = 0:2:20; y = [0.02 0.26 0.35 0.53 0.66 0.78 0.88 0.96 1.03 1.06 1.14]; plot(x,y,'rx'); How would i fit a line of best fit to this graph? I know this is rudimentary stuff but as i said i'm a total newbie!!! Cheers for any help help polyfit /Johan Jamie Sutton wrote: > I'm a total newbie at this guys. > I have the following data in an .m file: > > x = 0:2:20; > y = [0.02 0.26 0.35 0.53 0.66 0.78 0.88 0.96 1.03 1.06 1.14]; > plot(x,y,'rx'); > > How would i fit...

Best Fit Line
Hello, I have a problem that is puzzling me for very long.I got this problem of fitting in 80 over text files and within each txt file,it contains about 120 datas.I want to from these datas generate a best fit line to cut through all these points.The program I am now using is Matlab.Please help and reply asap,as I need the info urgently. Thanks. In article <a488ubsdofj7@legacy>, kellyblue19@yahoo.com (Eid) writes: >Hello, > I have a problem that is puzzling me for very long.I got this >problem of fitting in 80 over text files and within each t...

nonlinear best-fit line
Good afternoon, I am having trouble trying to figure out how to fit a nonlinear best fit line to my data in SAS. Any help would be greatly appreciated. Regards, Ligia ...

best fit line of an ROI
Hi everyone., The following code reads an image, allows user to select an ROI and then the intention is to select 1000 points randomly in the ROI and generate a best fit line through these points. By inserting breakpoints i see that the points generated randomly lie in the range of points belonging to the ROI. So, it seems there is no problem at this stage.I am not able to identify where else there is an error. Pls help. Thanx in advance. clc; close all; clear all; %WHEN USING THE IMAGE MAKE SURE THAT BW AND BW1 DO NOY HAVE TOO MANY ELEMENTS, IF THEY DO CROP BW AND BWI AND USE THE CROPPED...

Line of best fit #3
I have a matrix simular to the one below: 1 2 2 3 3 4 4 5 5 6 6 7 7 8 Is there a command that will give me an equation for a line of best fit for these data points? Thanks On Sep 27, 4:16=A0pm, "Charles " <charles.vaug...@colorado.edu> wrote: > I have a matrix simular to the one below: > > =A0 =A0 =A01 =A0 =A0 2 > =A0 =A0 =A02 =A0 =A0 3 > =A0 =A0 =A03 =A0 =A0 4 > =A0 =A0 =A04 =A0 =A0 5 > =A0 =A0 =A05 =A0 =A0 6 > =A0 =A0 =A06 =A0 =A0 7 > =A0 =A0 =A07 =A0 =A0 8 > > Is there a comm...

Help With Best Fit Lines
Hello All: I am trying to compare an observed dataset with best-fit models for: 1) Power Law 2) Exponential 3) Exponential Truncated Power Law I am able to get these four datasets (observed data + 3 models). But now I wish to see which of the models fits the dataset the best. It seems MATLAB AIC will only fit your data to built-in models, and not these 3 models I approximated myself. Any suggestions for procedures (whether or not they use MATLAB or AIC) will be very helpful!! Thank you. Jo PS: The datasets are not the same size (i.e. observed x=50 points, y=50 points. models x=1030 poi...

Best fit line in subplot
I want to add a linear trendline in both the plots of subplot. How do i do this, when i do this using the basic fitting option from the tools menu of figure, the line appears only for one data set ata time, i want to do it for both the data sets. You're right, it doesn't seem possible to do it with the Basic Fitting tool. I guess you have to do it by hand, like this: %%%%% x=[0:0.005:1.5]; %curve 1 y=sin(x); %linear fit 1 p = polyfit(x,y,1) y_lin = polyval(p,x); %curve 2 z=cos(x); %linear fit 2 p = polyfit(x,z,1) z_lin = polyval(p,x); %plot subplot(1,2,1) h(1)=plot(x,y) hold on h(2)=...

Weighted Line of Best Fit
At the moment I am writing code to find the weighted line of best fit. I can calculate the line of best fit using the code given below, where sortWLAN corresponds to the entries in an array, which I want to extract. onedist = sortWLAN(3,1:100); onerssi = sortWLAN(4,1:100); onewgt = sortWLAN(5,1:100); coeffs = polyfit(onedist,onerssi, coefficient); curvefit = polyval(coeffs, distance); hold on plot(onedist, onerssi, 'o'); plot(distance,curvefit, 'r'); hold off Anybode have any ideas? Cheers Brad wrote: > At the moment I am writing code to find the weighted line of best &...

best fit line through coordinates
Hi guys, I have an issue I'd like some help with. coordinates = 107.35 107 111.51 146 117 154.61 111.29 114 In the above matrix 'coordinates', its actually in the form [ x1 y1 x2 y2] for each of the 2 rows. Is there any function I can obtain a best fit line using these 4 points? thanks Kurtis Go look up the demo on the function polyfit, u can tell it to make a first order regression of those...

Outputting lines of best fit
I have a set of data in an array (11000,207). I've been asked to detrend the data in each of the 207 columns individually. I've tried using the Matlab detrend but I cant get it to work in a sensible way for this data. Instead I've been trying to ouput the equation for a line of best fit for the data in each column and then subtract that from the data. Seems a simple task but the only way I have found to find a line of best fit is doing it manually once you have a figure up using the best fitting option in tools. Obviously I don't want to do this manually 207 times. Does any...

line of best fit #2
I have two vectors and plotted them using a stem graph. I want to find the line of best fit and display this on the graph. I know about the function polyfit, but how do I graph its output? Look at help polyval cheers Peter wrote: > > > I have two vectors and plotted them using a stem graph. I want to > find the line of best fit and display this on the graph. I know > about > the function polyfit, but how do I graph its output? ... Web resources about - Best fit line for sinusoid - comp.lang.idl-pvwave Liver sinusoid - Wikipedia, the free encyclopedia
Anatomy of torso , digestive system : accessory digestive glands ( TA A05.8–9 , TH H3.04.05-07 , GA 11.1188 ) Veins of the abdomen and pelvis ...

AccessScience - Encyclopedia Article - Oscillator
An electronic circuit that generates a periodic output, often a sinusoid or a square wave. Oscillators have a wide range of applications in electronic ... Block Engineering: FTIR and Michelson Interferometer Technology Overview
Most interferometers used today for infrared spectrometry are based on the two beam type originally designed by Michelson in 1891. As such, a ... The DFT “à Pied”: Mastering The Fourier Transform in One Day : The DSP Dimension
If you’re into signal processing, you will no doubt say that the headline is a very tall claim. I would second this. Of course you can’t learn ...

Three examples where DSP saved my butt!
The Scientist and Engineer's Guide to Digital Signal Processing By Steven W. Smith, Ph.D. Home The Book by Chapters About the Book Copyright ... Electrical Construction and Maintenance (EC and M) Magazine
How to use various types of VFDs and harmonic mitigation tactics to combat the heat loss that accompanies these devices Free Apps for 2012-06-06