System of Equations with LSQCURVEFIT

2 views (last 30 days)
I would like to fit my data to a system of equations. I keep getting an error of "LSQCURVEFIT requires all values returned by user functions to be of data type double."
Any suggestions in getting my code to run correctly?
kappa1 = @(x, xdata)x(1)*xdata*x(2); % Equation 1
kappa2 = @(x, xdata)2*sqrt(2)*x(1).^2*x(2)*(-2*x(3).*(xdata+(xdata+x(3)).*log10(x(3)./...
(xdata+x(3))))); % Equation 2
E1 = char(kappa1) % Equation listing turn to character string; then combine
E2 = char(kappa2)
ES = (['{' E1 '; ' E2 '}'])
ESF = inline(ES)
k_2 = fcum(1:2,1:2); % ydata 2 by 2 matrix, two answers for each equation for two xdata points
T = AllDataTime; % two data time points
x0 = [.618 .088 .2]; % Initial guess values
[x, resnorm] = lsqcurvefit(ESF, x0, T, k_2)

Accepted Answer

Walter Roberson
Walter Roberson on 10 Jun 2016
lsqcurvefit cannot be used to fit to a system of equations. The output of the objective function must be the same size as the ydata, and cannot be a cell array.
The original poster also had difficulty with handling symbolic functions, but there is no point in posting a solution to that part as the overall goal cannot be met using lsqcurvefit

More Answers (1)

Jing_KU
Jing_KU on 10 Jun 2016
Have you solved this problem?
Regards, Jing

Community Treasure Hunt

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

Start Hunting!