Code covered by the BSD License

### Highlights from Power Law, Exponential and Logarithmic Fit

4.625

4.6 | 8 ratings Rate this file 169 Downloads (last 30 days) File Size: 7.17 KB File ID: #29545

# Power Law, Exponential and Logarithmic Fit

26 Nov 2010 (Updated )

Finds and plots the linear fit to some data points when plotted on a log scale.

File Information
Description

logfit(X,Y,graphType), where X is a vector and Y is a vector or a
matrix will plot the data with the axis scaling determined
by graphType as follows: graphType-> xscale, yscale
loglog-> log, log
logx -> log, linear
logy -> linear, log
linear -> linear, linear
A line is then fit to the scaled data in a least squares
sense.
See the 'notes' section below for help choosing a method.

logfit(X,Y), will search through all the possible axis scalings and
finish with the one that incurs the least error (with error
measured as least squares on the linear-linear data.)

Notes:
A power law relationship
[slope, intercept] = logfit(x,y,'loglog');
yApprox = (10^intercept)*x.^(slope);

An exponential relationship
[slope, intercept] = logfit(x,y,'logy');
yApprox = (10^intercept)*(10^slope).^x;

A logarithmic relationship
[slope, intercept] = logfit(x,y,'logx');
yApprox = (intercept)+(slope)*log10(x);

A linear relationship
[slope, intercept] = logfit(x,y,'linear');
yApprox = (intercept)+(slope)*x;

MATLAB release MATLAB 7.11 (R2010b)
13 Nov 2013

very usefull,,

by the way, how to make non linear curve fit using custom equation when plot on log scale?

thx

23 Sep 2013
11 Jul 2013

23 May 2013

Just what the Dr. ordered. Thank You.

11 Feb 2013

Awesome!

30 Jan 2012

Saviour !!!!!!!!!!

06 Jan 2012

Nice.

I use:

% y = a x^b
function [a b] = my_powerLawFit(y, x)

logx=log(x);
logy=log(y);
p=polyfit(logx,logy,1);
b=p(1);
loga=p(2);
a=exp(loga);
end

30 Jan 2011

Extremely cool!

09 Aug 2013

Updated to include Mean Squared Error

17 Dec 2013

fixed 'skipbegin' feature functionality

09 Jan 2014

Updated to use R2 as 'best fit' criterion rather than MSE