Curve fitting data - least square fit with two input variables

Hello all,
I am attempting to fit some testing data to a model using the lsqcurvefit function. I was able to successfully create a fit for data with a set of input data including one variable, however I am running into some trouble when I try to modify the code to accept multiple variables as inputs for the model.
Here is an example of my working code followed by how I am attempting to include the second input variable:
Working Fit:
which produces the following graphs
Multivariable fitting:
Where I am having trouble is including the varable Fz as an array of data as opposed to an averaged constant. I have tried to simply include it in the lsqcurvefit function and adjust the model function but I have had no success thus far.
Here is my code including the function if anybody has any input on how I might get this to work it would be immensely appreciated
altered model to include extra variable in "lat_slip2"
The error I am currently experiencing says the following:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in lat_slip2 (line 2)
Fy = (1 - exp(-C(1).*abs(X(:,1)/alph_c))).*C(2).*X(:,2).*sign(X(:,1)).*(C(3)+abs(X(:,2) - C(4))*C(5));
Error in Harty_Model_more_variable>@(C,X1)lat_slip2(C,X1,alph_c1) (line 160)
lat_f = @(C,X1)lat_slip2(C,X1, alph_c1);
Error in lsqcurvefit (line 222)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Harty_Model_more_variable (line 161)
C(:,1) = lsqcurvefit(lat_f, C0, alph1, FY(IA_zero_1));
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.

Answers (0)

Categories

Asked:

on 22 Jun 2020

Community Treasure Hunt

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

Start Hunting!