power law fit to find exponent
    3 views (last 30 days)
  
       Show older comments
    
I have a data in column matrix x and y 
I need a power law fit    say y=x^m
I require to plot scatter of y versus x and plot a power law fit on top of it ; and find m and display on graph.
any help will be appreciated!
4 Comments
  Star Strider
      
      
 on 17 Feb 2020
				If you want to linearise this equation: 
y=x^m
take the logs of both sides.  (There are much better ways to do this, however that will get you close enough.)  
Answers (1)
  Star Strider
      
      
 on 18 Feb 2020
        I would do this (no Toolboxes required): 
x = linspace(0, 5, 50);                                     % Create Data
y = x.^pi + randn(size(x))*10;                              % Create Data
fcn = @(b,x) b(1).*x.^b(2) + b(3);                          % Objective Function
B = fminsearch(@(b) norm(y - fcn(b,x)), rand(3,1)*2)        % Estimate Parameters
figure
plot(x, y, '.')
hold on
plot(x, fcn(B,x), '-r')
hold off
grid
Here, ‘m’ is ‘B(2)’.  
Taking the logs of both sides will only work if both ‘x’ nor ‘y’ are >=0.  
0 Comments
See Also
Categories
				Find more on Two y-axis in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
