How can I fit a curve involving implicit variable?

I'd like to fit a diode I-V curve with serial and parallel resistance, this function has the V as the independent variable and I as the dependent variable, which appears on both sides of the function, i.e. implicit function. I have a set of I and V data, and want to find out the best fit with serial and parallel resistance. Below is the function I set up, but it doesn't give a right fitting anyhow.
function X = fitdiode %the main function
[V,I] = gettdata; %or pull from the same code
% Initialize the coefficients of the function.
X0=[1e-6 100 1e5 1.2];
X=lsqcurvefit(@mydiode,X0,V,I); %also tried lsqnonlin
end %end of main function
function output = mydiode(par, v) %this is the function calculate the I from V
I0= par(1); % saturation reverse current
Rs=par(2); % serieal resistance
Rp=par(3); %shunt resistance
n_ide = par(4); % ideality
m = length(v);
I_new=zeros (m,1);
for ii = 1:m % for each set of parameters there is one I at each point of V.
syms x
sol = solve (I0*(exp((v(ii)-Rs*x)/0.0259/n_ide)-1)-x + (v(ii)-x*Rs)/Rp == 0);
I_new(ii) = sol;
end
output = I_new;
end
I know a similar problem has been asked few years back, but was not answered yet. Hope you folks have some good idea about this. Thanks in advance.

3 Comments

I don't see the I variable passed into the mydiode function. What do you mean that it appears on both sides of the function?
lsqcurvefit does not need the y varible to be passed, ie I in this example. But lsqnonlin does, please visit the help file for more details on these two functions. appearing on both sides means implicit function.
I don't understand what you're doing with the for loop. The lsqcurvefit function passes the independent variable vector (in your application, V) to your objective function ( mydiode ), calculates a vector to approximate the dependent vector (in your application, I), and returns it.
What are you solving for in the for loop (that does not appear to be an implicit function), and why? I assume that sol = x, but it still is not obvious to me why you'd be doing that in an objective function.
What function are you actually trying to fit?

Sign in to comment.

Answers (0)

Categories

Products

Asked:

Jie
on 28 Aug 2012

Community Treasure Hunt

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

Start Hunting!