Fitting nonlinear transcendental equation to data Via lsqcurvefit function
Show older comments
I want to fit J-V curve of a solar cell and the resultant equation is a transcendental equation. I am attaching my code below.
clear all;clc;close all;
load 'J-V curve.mat';
plot(v_save,j_save);hold on
F=@(k,xdata,ydata) (k(1)-k(2)*exp((xdata+ydata*k(3))/(0.025887*k(4)))...
-((xdata+ydata*k(3))/k(5)));
k0=[18 2e-8 .005 1 5];
[k,resnorm,~,exitflag,output] = lsqcurvefit(F,k0,v_save,j_save);
plot(v_save,F(k,v_save,j_save));
Here, F is a transcendental equation. However the code gives the following error. Not enough input arguments.
Error in
fitting_j_v>@(k,xdata,ydata)(k(1)-k(2)*exp((xdata+ydata*k(3))/(0.025887*k(4)))-((xdata+ydata*k(3))/k(5)))
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in fitting_j_v (line 7)
[k,resnorm,~,exitflag,output] = lsqcurvefit(F,k0,v_save,j_save);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
Will someone please help me to solve out the problem?
Answers (1)
Walter Roberson
on 18 Sep 2017
0 votes
lsqcurvefit() only passes x and xdata to the function. It subtracts off ydata itself. The function needs to be of the form predicted_ydata = function NAME(x, xdata) . Implicit functions are not supported. You need to isolate the ydata out of the function. If that is not possible then you cannot use lsqcurvefit()
1 Comment
Saravanakumar Dharmaraj
on 8 Jun 2022
Is it impossible to do curve fitting for transcendental equation in matlab?
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!