[Matlab] Which is the good solution My vs. School - curve fitting?

Click For Summary
SUMMARY

The discussion focuses on solving a nonlinear least squares problem using MATLAB, specifically comparing two methods: a manual implementation and the Curve Fitting Tool (cftool). The manual method involves linearizing the function y = x / (a + b.x) by substituting variables and using the fminsearch function to optimize parameters. The results obtained from both methods yield similar parameter estimates, but discrepancies arise in the residual sum of squares (SSE). The user seeks clarification on the differences in results and the validity of their approach.

PREREQUISITES
  • Understanding of nonlinear least squares optimization
  • Familiarity with MATLAB programming and syntax
  • Knowledge of linearization techniques in curve fitting
  • Experience with MATLAB functions such as fminsearch and cftool
NEXT STEPS
  • Explore MATLAB's Curve Fitting Toolbox documentation for advanced features
  • Learn about nonlinear regression techniques in MATLAB
  • Investigate alternative optimization functions like lsqcurvefit for nonlinear problems
  • Study the impact of variable substitution on model fitting in nonlinear regression
USEFUL FOR

Researchers, data analysts, and engineers who are working with nonlinear regression models in MATLAB, particularly those interested in optimizing curve fitting techniques and understanding the differences between manual and automated fitting methods.

artiny
Messages
6
Reaction score
0
Hy, I wonder which is the good solution for this problem:

Nonlinear least square problem: function: y = x / (a + b.x) linearization: 1/y = a/x + b substitution: v = 1/y , u = 1/x >> model v = b + a.u

What we did in school:

x = [1 2 4 7]; y = [2 1 0.4 0.1];
v=1./y;
u=1./x;
n = length(x);
A=[ones(n,1), u']
xbeta=A\v'
Lbeta=xbeta;
beta0=flipud(Lbeta)
beta=fminsearch('kritfun',beta0)
r = [kritfun(beta0) , kritfun(beta)]


+ kritfun.m

function z=kritfun(beta)
a=beta(1);
b=beta(2);
x = [1 2 4 7];
y = [2 1 0.4 0.1];
error = y - x./(a + b*x );
z = sum((error .^2 ));


in ML we get : xbeta =

7.3658
-8.1692
beta =

1.0e+014 *

-8.2085
4.1043
r =

11.0600 4.1700

but when I try in Curve Fitting tool too check the soulution , I get something else ..according to this video:
too call CF I typed to prompt >>cftool

When I try this I get the same number like in the Curve fitting tool , the a,b parameters is my beta(1),beta(2) and the SSE number is my r(2) ..what was same when I tried this:

x = [1 2 4 7];
y = [2 1 0.4 0.1];

%u = 1./x; %these u and v I don't use it...but I didnt know when not using substituion is correct the beta and r(2) , but when I didnt use I get same numbers lik in the Curve Fitting tool
%v = 1./y;

n = length(x);
X = [ ones(n,1), x'];
btr = X\y'

beta0 = flipud(btr)'
beta = fminsearch('mnsNLcFUN',beta0)
r = [mnsNLcFUN(beta0), mnsNLcFUN(beta)]


+ mnsNLcFUN.m function is:

function z=mnsNLcFUN(beta)
a=beta(1);
b=beta(2);

x = [1 2 4 7];
y = [2 1 0.4 0.1];

error = y - x./(a+b.*x);
z = sum((error .^2 ));
 
Physics news on Phys.org
Thanks for the post! Sorry you aren't generating responses at the moment. Do you have any further information, come to any new conclusions or is it possible to reword the post?
 
somewho said that is more possible way to do the linearization...and what we did is not the same as Matlab makes ,...or I don't know what else..
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
1
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
7K