Output of MATLAB Curve Fitting Toolbox does not match generated function -


a similar question has been answered in past, part of question not answered (matlab curve fitting tool, cftool, generate code function not give same fit).

i have set of data points meant show "ideal" curve mechanism studying.

when ask curve fitting toolbox in matlab find 2-term exponential, great fit (r-square: 0.9998, adjusted r-square: 0.9997). however, when generate code fit, changes coefficients a, b, c , d.

in toolbox, displays:

general model exp2:

 f(x) = a*exp(b*x) + c*exp(d*x) 

coefficients (with 95% confidence bounds):

   =   4.698e+04  (-1.477e+13, 1.477e+13)     b =      0.4381  (-1200, 1201)     c =  -4.698e+04  (-1.477e+13, 1.477e+13)     d =      0.4381  (-1200, 1201) 

goodness of fit:

sse: 0.002979

r-square: 0.9998

adjusted r-square: 0.9997

rmse: 0.006823

function generated curve-fitting toolbox:

function [fitresult, gof] = createfit1(bgst, testst) %createfit1(bgst,testst) %  create fit. % %  data 'standard mechanism' fit: %      x input : bgst %      y output: testst %  output: %      fitresult : fit object representing fit. %      gof : structure goodness-of fit info. % %  see fit, cfit, sfit.  %  auto-generated matlab on 29-apr-2015 15:54:07   %% fit: 'standard mechanism'. [xdata, ydata] = preparecurvedata( bgst, testst );  % set fittype , options. ft = fittype( 'exp2' ); opts = fitoptions( 'method', 'nonlinearleastsquares' ); opts.display = 'off'; opts.startpoint = [0.935605768794225 0.667093185616236 0 0.667093185616236];  % fit model data. [fitresult, gof] = fit( xdata, ydata, ft, opts );  % plot fit data. figure( 'name', 'standard mechanism' ); h = plot( fitresult, xdata, ydata ); legend( h, 'testst vs. bgst', 'standard mechanism', 'location', 'northeast' ); % label axes xlabel bgst ylabel testst grid on 

notice coefficients different, curves generated.

notice coefficients displayed in curve-fitting toolbox, c = -a , d = b, y should equal 0 value of x, ludicrous.

but when edit generated function replace function's coefficients coefficients toolbox, curve.

edited code:

function [fitresult, gof] = standardfit(bgst, testst) %standardfit(bgst,testst) %  create fit. % %  data 'standard mechanism' fit: %      x input : bgst %      y output: testst %  output: %      fitresult : fit object representing fit. %      gof : structure goodness-of fit info. % %  see fit, cfit, sfit.  %  auto-generated matlab on 29-apr-2015 15:54:07  %from curve fitting toolbox: %general model exp2: %     f(x) = a*exp(b*x) + c*exp(d*x) %coefficients (with 95% confidence bounds): %       =   4.698e+04  (-1.477e+13, 1.477e+13) %       b =      0.4381  (-1200, 1201) %       c =  -4.698e+04  (-1.477e+13, 1.477e+13) %       d =      0.4381  (-1200, 1201)  %goodness of fit: %  sse: 0.002979 %  r-square: 0.9998 %  adjusted r-square: 0.9997 %  rmse: 0.006823   %% fit: 'standard mechanism'. [xdata, ydata] = preparecurvedata( bgst, testst );  % set fittype , options. ft = fittype( 'exp2' ); opts = fitoptions( 'method', 'nonlinearleastsquares' ); opts.display = 'off'; opts.startpoint = [4.698e+04 0.4381 -4.698e+04 0.4381];  % fit model data. [fitresult, gof] = fit( xdata, ydata, ft, opts );  % plot fit data. figure( 'name', 'standard mechanism' ); h = plot( fitresult, xdata, ydata ); legend( h, 'testst vs. bgst', 'standard mechanism', 'location', 'northeast' ); % label axes xlabel bgst ylabel testst grid on 

i don't have enough reputation post images of curves, in toolbox looks perfect , 1 function looks awful - translated in same way linked poster.

here's variable bgst:

-2.85 -2.8 -2.75 -2.7 -2.65 -2.6 -2.55 -2.5 -2.45 -2.4 -2.35 -2.3 -2.25 -2.2 -2.15 -2.1 -2.05 -2 -1.95 -1.9 -1.85 -1.8 -1.75 -1.7 -1.65 -1.6 -1.55 -1.5 -1.45 -1.4 -1.35 -1.3 -1.25 -1.2 -1.15 -1.1 -1.05 -1 -0.95 -0.9 -0.85 -0.8 -0.75 -0.7 -0.65 -0.6 -0.55 -0.5 -0.45 -0.4 -0.35 -0.3 -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 

here's variable testst:

0 0.01 0.01 0.02 0.02 0.02 0.03 0.04 0.04 0.05 0.06 0.06 0.07 0.08 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.2 0.21 0.23 0.24 0.26 0.28 0.3 0.31 0.33 0.35 0.37 0.39 0.41 0.43 0.45 0.48 0.5 0.52 0.55 0.57 0.6 0.63 0.66 0.68 0.72 0.74 0.78 0.81 0.85 0.88 0.92 0.96 1 1.04 1.08 1.12 1.17 1.21 1.26 1.3 1.35 1.39 1.44 

edit: have enough reputation add images.

figure generated curve fitting toolbox:

figure generated cftool

figure generated automatically-generated function:

figure generated function

i ran similar problem using exponential fit due how coefficients bounded. it's possible they're bounded in dialogue, don't see they'd bounded in generated code.


Comments

Popular posts from this blog

command line - Use qwinsta in PowerShell ISE -

java - Incorrect order of records in M-M relationship in hibernate -

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -