How to find coefficient and power of polynomial y=a*x^n
1 view (last 30 days)
Show older comments
kfir reuven
on 29 Jun 2018
Commented: Star Strider
on 29 Jun 2018
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.
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!