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

3 ビュー (過去 30 日間)
David
David 2022 年 12 月 2 日
コメント済み: David 2022 年 12 月 3 日
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);
%%

採用された回答

Matt J
Matt J 2022 年 12 月 3 日
編集済み: Matt J 2022 年 12 月 3 日
f = @(K, x) K(1) + K(2)./ x + K(3)./ x.^2;

その他の回答 (1 件)

Matt J
Matt J 2022 年 12 月 3 日
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 件のコメント
David
David 2022 年 12 月 3 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSplines についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by