1) Polynomial fit:
in polynomial.m
----------------------------------------
function polynomial
c=[1 2 -1] % for x*x+2*x-1
x=-1:0.1:1
y=polyval(c,x) % y=x*x+2*x-1
noise = rand(1, size(y,2)) %create some noise
newy=y+noise
newc=polyfit(x, newy,2) % get fit parameter
yc=polyval(newc,x)
hold on % plot all plots in 1 figure
plot(x, y, 'b--') % plot original blue --
plot(x, newy, 'r+') %plot new data with noise red ++
plot(x, yc, 'g') % plot fit curve green
legend('original curve','Data','Polynomial Fit','Location','NW')
---------------------------------------------------------
2. Non linear fit, for example Gaussian fit
define gauss.m
-----------------------------
function f=gauss(a,x)
f=a(1)*exp(-(((x-a(2))/a(3))/a(3)).^2)
-------------------------------------------------
then
-----------------------------------------
a=[2 0.5 1] % guess a
a=nlinfit(x,newy,'gauss',a) % find fit parameters for data [x, newy]
plot(x,gauss(a,x),'k') % plot fitted Gaussian curve in black
Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHP: add a download as pdf file button in report page
- How to blend adsense inside your post?
- Formatting my post
- PHPWind-- A PHP forum script applcaition in China
- Notepad++ - Add C++ compiler
- PHP connect IBM db2 database in XAMPP
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Sweet Alert JS library - beautiful replacement of JavaScript Alert
- ActionScript 3.0 demo: create a falling snow in flash CS6
No comments:
Post a Comment