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
- PHPWind-- A PHP forum script applcaition in China
- How to blend adsense inside your post?
- Formatting my post
- Install PHPMailer 5.2.4 and use smtp gmail
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Linux, automatically backup MySQL database daily
- SPSS job interview questions
- Notepad++ - Add C++ compiler
- Install PHP ibm_db2 extension in Linux (redHat)
No comments:
Post a Comment