MATLAB: How to reduce error on loglog scale using linear regression

MATLABplotplotting

This is what I am doing with my imported data. What can I do to reduce the multiplicative errors? I tried to adapt non-linear regression to my script but I don't understand the examples that I've found so far. If possible, please suggest what could I do in both scenarios.
  1. Reduce the error in linear regression
  2. Apply non-linear regression instead with every line explained
The plot of my data in log scale is shown below.
Thanks
% x: assume any column vector x
% y: assume any column vector y
loglog(x,y, '*');
% % Estimating the best-fit line
const = polyfit(log(x),log(y), 1);
m = const(1);
k = const(2);
bfit = x.^m.*exp(k); % y = x^m * exp(k)
hold on
loglog(x,bfit)
Screen Shot 2018-11-13 at 00.33.57.png

Best Answer

Change them to additive errors (as they should be) using nonlinear regerssion techniques.
Example (from another Answer)
temp = [100,200,400,600,800,1000,1200,1400,1600]';
density = [3.5,1.7,0.85,0.6,0.45,0.35,0.3,0.25,0.2]';
fcn = @(b,x) exp(b(1).*x).*exp(b(2)) + b(3);
[B,rsdnorm] = fminsearch(@(b) norm(density - fcn(b,temp)), [-0.01; max(density); min(density)]);
fprintf(1, 'Slope \t\t=%10.5f\nIntercept \t=%10.5f\nOffset \t\t=%10.5f\n', B)
tv = linspace(min(temp), max(temp));
figure
plot(temp, density, 'p')
hold on
plot(tv, fcn(B,tv), '-')
grid
text(500, 1.7, sprintf('f(x) = %.2f\\cdote^{%.4f\\cdotx} + %.2f', B([2 1 3])))
There are a number of funcitons you can use to do nonlinear parameter estimation in MATLAB. I use fminsearch here because every body has it.