0

I am trying to do a non linear regression to find the constants Is and n with the least square curve fitting.This is the formula Is(exp(1).^(V/26.*n)) And this is my code

fun = @(n,Is)Is(exp(1).^(V/26.*n));
x0 = [0,14];
x = lsqcurvefit(fun,x0,V,I)

It retruns the following

Matrix dimensions must agree.

Error in @(n,Is)Is(exp(1).^(V/26.*n))

Error in lsqcurvefit (line 202) initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});

Caused by: Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.

carloscc
  • 779
  • 3
  • 14
  • 20

1 Answers1

0

From https://www.mathworks.com/help/optim/ug/lsqcurvefit.html

Function you want to fit, specified as a function handle or the name of a function. fun is a function that takes two inputs: a vector or matrix x, and a vector or matrix xdata. fun returns a vector or matrix F, the objective function evaluated at x and xdata.

In your case your fun gets only your parameters to fit, not your data. I suggest changing it to

fun = @(X,V) X(2)*(exp(1).^(V/26.*X(1)));
Noel Segura Meraz
  • 2,265
  • 1
  • 12
  • 17