How to fitt a power function to data

1 visualización (últimos 30 días)
Sadegh Aberoumand
Sadegh Aberoumand el 20 de Abr. de 2021
Respondida: Star Strider el 20 de Abr. de 2021
I have two 26*1 matrixes of x and y. How can I fitt a power function like (y=bx^n) to the generated graph? I just have basic fitting tool in which there is no power function. So I think I should use an appropriate code. Appreciate it.
Cheers,

Respuestas (2)

David Hill
David Hill el 20 de Abr. de 2021
If you have the curve fitting toolbox.
f=fit(x,y,'power1');

Star Strider
Star Strider el 20 de Abr. de 2021
This uses only basic MATLAB functions. No Toolboxes are required.
x = 1:100; % Create Vector
y = rand(size(x)); % Create Vector
objfcn = @(b,x) b(1).*x.^b(2); % Objective Function
parms = fminsearch(@(b) norm(y - objfcn(b,x)), rand(2,1))
xv = linspace(min(x), max(x));
figure
plot(x, y, 'p')
hold on
plot(xv, objfcn(parms,xv), '-r')
hold off
title(sprintf('$y(x) = %.3f \\cdot x^{%.3f}$', parms), 'Interpreter','latex')
.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by