How to find coefficient and power of polynomial y=a*x^n

1 view (last 30 days)
I have 2 vector and I need to approximate the scattered plot they make to a polynomial like mentioned above. I've been searching for a couple of days now but for no avail. Any help will be much appreciated.

Accepted Answer

Star Strider
Star Strider on 29 Jun 2018
Two options:
x = 1:20;
y = 3*x.^pi + randn(size(x));
blin = [ones(size(x(:))) log(x(:))] \ log(y(:)) % Linear Approximation
blinc = [exp(blin(1)); blin(2)]
linreg = exp(blin(1)) * x.^blin(2);
figure
plot(x, y, 'p')
hold on
plot(x, linreg, '-r')
hold off
grid
b0 = [10; 10];
bnlin = fminsearch(@(b) norm(y(:) - b(1).*x(:).^b(2)), b0) % Nonlinear Approximation
nlinreg = bnlin(1) .* x(:).^bnlin(2);
figure
plot(x, y, 'p')
hold on
plot(x, nlinreg, '-r')
hold off
grid
The nonlinear estimation is more accurate.
  2 Comments
kfir reuven
kfir reuven on 29 Jun 2018
Edited: kfir reuven on 29 Jun 2018
Thank you very much. This is very helpful and works very well.
And of course, thank you for such a quick answer.

Sign in to comment.

More Answers (0)

Categories

Find more on Polynomials 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!