LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-15-2006, 08:48 PM   #1
wwnexc
Member
 
Registered: Sep 2005
Location: California
Distribution: Slackware & Debian
Posts: 264

Rep: Reputation: 30
Lightbulb Matlab


Hi,

I have been fiddeling around with matlab for a bit now, and i think it's an amazing program. I am not very strong with it, but i was wondering if there is any way to calculate a sine regression to fit given data.

I have been able to graph the data using [CODEplot(time,hight,'*')][/CODE]

I am trying to fit a sine regression / best fit line to fit the data.

Does anybody here know how to do something like this?
 
Old 03-17-2006, 06:06 AM   #2
rch
Member
 
Registered: Feb 2003
Location: Santa Clara,CA
Distribution: Mandriva
Posts: 909

Rep: Reputation: 48
I totally agree with the statement that Matlab is an amazing program. I don't know about sine regression analysis but the language Matlab is based upon called R supports all kinds of regression. I am not from mathematical background, so I don't know the particulars but these pages might help
http://www.mathworks.com/access/help...ts/f49559.html
http://www.mathworks.com/access/help...gression5.html
 
Old 03-17-2006, 06:36 AM   #3
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Is
http://www.mathworks.com/matlabcentr...bjectType=file
what you're looking for?

Matlab's help mentions multiple regression and fitting functions, but none seem to include "sine regression" (at first sight). Altough that may be included in toolboxes that I don't have installed.

Perhaps there are some alternative functions you can try at Matlab Central's file exchange:
http://www.mathworks.com/matlabcentr...oadCategory.do
in the Mathematics category probably.
Those functions may still be a little buggy though.
 
Old 03-17-2006, 09:20 AM   #4
wwnexc
Member
 
Registered: Sep 2005
Location: California
Distribution: Slackware & Debian
Posts: 264

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by timmeke
This seems to be it. I will check it out once i get home today.

I'll keep you posted on how it goes.
 
Old 03-17-2006, 04:19 PM   #5
wwnexc
Member
 
Registered: Sep 2005
Location: California
Distribution: Slackware & Debian
Posts: 264

Original Poster
Rep: Reputation: 30
I am not sure why i can't get it to work.

I have two lists (variables), one containing the x-values, an other one containing the y-values. I have not yet found a way of actually calculating a sine wave which fits these (less than 30) values.

The format for the wave should be something like this "y=a*sin(b*x+c)+c".

Is there any paractical way (without having to get a degree in advanced mathematics first) to calculate something like this??
 
Old 03-17-2006, 05:11 PM   #6
wwnexc
Member
 
Registered: Sep 2005
Location: California
Distribution: Slackware & Debian
Posts: 264

Original Poster
Rep: Reputation: 30
I believe this kind of function is also called a "sinusoid".

Does anybody know how to get it to work??

EDIT: The TI 83 was able to compute a SinReg within a few seconds.... Why is it that hard to do it in matlab?

Last edited by wwnexc; 03-17-2006 at 05:16 PM.
 
Old 03-20-2006, 02:33 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
I don't really know how the TI 83 works, so can't help you with that. It may just plot a sine that approximates the given values (not really fitting it as good as possible).

"fitting" (ie least square fitting) is usually an iterative approach. That always involves making slight changes to the variables in a function (such as a sine function) until some error value is minimized.
In your case, the error value could be something like the RMS value of distance between each value and the sine wave. Based on that RMS error indication, you can slowly adjust your sine parameters until the RMS reaches a minimum. Matlab surely has functions for that. Check out least squares fitting, for instance.

Another approach would be to just make a sinusoid that approaches your values, rather than actually "fitting" as closely as possible.
To do this, you simply need to determine 3 things: the sine's amplitude and frequency (or wavelength) and the phase.
In general, a sinusoid is something of the form:
y = A * sin(bx + c)
"A" is your amplitude, "b" is related to the frequency (or 1/wavelenght) in the x direction and "c" is the phase (in radians).
If you plot the values, you should be able to approximate each of the values.
You could also use these values as starting point for the least square fitting.

I don't really get why you included yet another "+c" in your formula for sinusoids (ie "sine-like function").
The +c you've added would probably only be an offset in the y direction (ie if the mean value of your wave isn't at y=0 but at y=c). This "y offset" is however unrelated to the sine's phase, so -mathematically speaking- you should call them "c1" and "c2" instead of just 2 times "c".

Last edited by timmeke; 03-20-2006 at 02:34 AM.
 
Old 03-20-2006, 09:16 PM   #8
wwnexc
Member
 
Registered: Sep 2005
Location: California
Distribution: Slackware & Debian
Posts: 264

Original Poster
Rep: Reputation: 30
"y=a*sin(b*x+c)+c" should be "y=a*sin(b*x+c)+d".

I am not sure how i could have ever made that typo.

I think i got the concept now: one has to specify the starting values for each variable. I though that matlab would simply calculate a best fitting line, without any start-data given.
 
Old 03-21-2006, 01:43 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
No. I believe there is no such thing like "fitting without starting data".
You normally need to have starting data, provided from an approximation, a best guess, etc.
Fitting is typically an iterative approach, starting with some data, that adjust the variables slightly (in each iteration), until some error value is minimized.

The downsides of such an iterative algorithm are
1. performance
2. they can get stuck on "local minima". Let's say that the error is decreasing, reaches a local minimum and then increases slightly before going down again to the real minimum. The iterative algo may stop at the local minimum instead of pursuing the real one. Their are alternative approaches, such as neural networks, to get past this disadvantage.

I recommend you try the least squares fit.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Matlab 6.5 !! Help!! rcnow Linux - Software 11 05-10-2007 03:41 AM
MATLAB 7.0.4 on SUSE 10 ringofti Linux - Software 0 11-05-2005 11:40 AM
Terminal cmd for starting Matlab M-file editor without starting matlab fubzot Linux - Software 2 02-15-2005 06:49 AM
Matlab safrout Programming 3 04-13-2002 03:36 PM
MATLAB or MAPLE or... shogun Linux - General 2 02-08-2002 06:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration