Question: I need to fit data using the function nlinfit in order to make a regression to the existing data I already have, loaded from the
I need to fit data using the function nlinfit in order to make a regression to the existing data I already have, loaded from the dispvst.mat' file. I'm trying to use the function used below, but come up with an error code. What is the correct syntax to use this function with nlinfit?
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
