Tricks in MATLAB

From Computational Biophysics and Materials Science Group
Jump to: navigation, search

Quick fitting

http://www.mathworks.com/help/matlab/ref/polyfit.html

a= 1:0.1:10;
p = polyfit(a,exp(a),5); % Fits a fifth degree polynomial to exp(a) in the Least squares sense
v = polyval(p,a);
plot(a,v,a,exp(a)) % You will see the difference.