Error 'lscurvefit' (Function value and YDATA sizes are not equal)

3 Ansichten (letzte 30 Tage)
David
David am 2 Dez. 2022
Kommentiert: David am 3 Dez. 2022
Hola! Estoy tratando de hacer un ajuste de curvas de una colección de puntos. Inicialmente se importa desde un archivo una matriz de 57x2, la cual separo y utilizo para hacer el ajuste de una función no lineal. No obstante, todo falla a la hora de ejecutar, dando el error del asunto. ¿Cuál podría ser una potencial fuente de error?
%% Parámetros iniciales:
%% Formato long, para poder apreciar mejor la presición de los
% decimales obtenidos.
format long;
%% Hold on, para poder apreciar varias gráficas a la vez.
hold on;
%% Datos globales:
%% Sea importa el archivo 'A_data_preg1.mat',y se asignan sus a la
% variable 'A'.
load('A_data_preg1.mat');
A = A_data_preg1;
%% Los métodos lsqcurvefit y polyfit requieren como parámetros una
% función un vector con valores iniciales, un vector 'x', y un vector
% 'y'. Desde A, se extraen 'xd' e 'yd'.
xd = A(:, 1);
yd = A(:, 2);
%% Sean el vector K1 los tres valores correspondientes al ajuste no-lineal
% a realizar:
%% Se declara la función del respectivo ajuste de curva. (f)
f = @(K, x) K(1) + K(2) / x + K(3) / x.^2;
%% Se calcula el ajuste de la función no lineal.
K1 = lsqcurvefit(f, [0, 0, 0], xd, yd);
%% Posteriormente, se declara un vector 'y', donde estarán los datos
% procesados por 'f' de 'xd'.
y = f(K1, xd);
%% Finalmente, se grafica.
plot(xd, y);
%%

Akzeptierte Antwort

Matt J
Matt J am 3 Dez. 2022
Bearbeitet: Matt J am 3 Dez. 2022
f = @(K, x) K(1) + K(2)./ x + K(3)./ x.^2;

Weitere Antworten (1)

Matt J
Matt J am 3 Dez. 2022
Since you have no bounds on K, you should probably just solve for K analytically, rather than iteratively with lsqcurvefit:
K=(xd.^[0,-1,-2])\yd;
  1 Kommentar
David
David am 3 Dez. 2022
Yeah, i know, but that for now isn't an option, since this an activitie for college, and they specifically said that i have to use lsqcurvefit. Thanks for the support <3

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by