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

조회 수: 2 (최근 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 CenterFile Exchange에서 Splines에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by