Problem using nlinfit with a multivariable function

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

Answers (0)

Products

Release

R2018b

Asked:

on 13 Feb 2019

Commented:

on 21 Feb 2019

Community Treasure Hunt

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

Start Hunting!