Problem using nlinfit with a multivariable function
Afficher commentaires plus anciens
I have the following code so far:
clear , clc , clf
% EXPERIMENTAL DATA =======================================================
load('dispvst.mat'); % Reads Data Set 1
X1 = dispvst(:,2); % Time Vector
Y1 = dispvst(:,1); % Displacement Vector
% REGRESSION ==============================================================
beta0 = [1 2];
FIT = nlinfit(X1,Y1,@FUN1,beta0); % Coefficient Fit
% Function ================================================================
function MODELFUN = FUN1(k,c,t)
m = 1; % Mass (kg)
Wn = sqrt(k/m); % Wn
E = c / (2*Wn); % E
Wd = Wn * sqrt(1-E^2); % Wd
A = sqrt((Wn*E*X1(1)) / Wd + X(1)^2); % A
Phi = atan(Wd/(E*Wn)); % Phi
MODELFUN = A*exp(-E*Wn*t)*sin(Wd*t+Phi); % Model Function
end
% END =====================================================================
MatLab gives me the following error code:
%===========================================================================
Error using nlinfit (line 213)
Error evaluating model function 'FUN1'.
Error in HW2P3 (line 16)
FIT = nlinfit(X1,Y1,@FUN1,beta0); % Coefficient Fit
Caused by:
Error using /
Matrix dimensions must agree.
=================================================================================
I can't figure out the correct syntax to use in order to use the function in the nlinfit function
1 commentaire
Patel Mounika
le 21 Fév 2019
Can you please share dispvst.mat file.
Réponses (0)
Catégories
En savoir plus sur Image Quality dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!