- #1
Zavata
- 1
- 0
Hello,
I'm working on a simple electronic circuit with two resistors and two diodes.
I have experimental data of the current-voltage characteristic and am trying to fit the corresponding equation - the resistors and diodes are unknown.
With basic circuit analysis, I get this tricky (messy) equation:
Id - (Vd-Rs*Id)/Rsh - Is1*(Exp[(Vd-Rs*Id+n2*vt*Log[1-(Id-(Vd-Rs*Id)/Rsh)/Is2])/(n2*vt)] - 1) = 0
where the current-voltage characteristic is Id(Vd), Rs is a series resistor, Rsh is a parallel shunt resistor and Is1, n1, Is2, n2 are the saturation current and ideality factors of the two diodes.
To achieve this, I've installed Mathematica 8.0 for Students and have written a small code.
**************************
(* Creation of an implicit function *)
vt = 0.0256;
function =
Last[Last[
Last[NDSolve[{Id[Vd, Rs, Rsh, Is1, n1, Is2,
n2] - (Vd - Rs*Id[Vd, Rs, Rsh, Is1, n1, Is2, n2])/Rsh -
Is1*(Exp[(Vd - Rs*Id[Vd, Rs, Rsh, Is1, n1, Is2, n2] +
n2*vt*Log[
1 - (Id[Vd, Rs, Rsh, Is1, n1, Is2,
n2] - (Vd - Rs*Id[Vd, Rs, Rsh, Is1, n1, Is2, n2])/
Rsh)/Is2])/(n1*vt)] - 1) == 0,
Id[0, Rs, Rsh, Is1, n1, Is2, n2] == 0},
Id, {Vd, -1.5, 1.5}, {Rs, 1, 3000}, {Rsh, 100, 10000}, {Is1,
10^-7, 10^-2}, {n1, 1, 20}, {Is2, 10^-7, 10^-2}, {n2, 1, 20}]]]]
(* Data *)
data = {{-1.20006167888641, -0.000335911958245561}, \
{-1.00005328655243, -0.000308143673464656}, {-0.380005955696106, \
-0.000220252826693468}, {-0.119975663721561, -0.000175646884599701}, \
{-0.740023016929626, -0.000272983132163063}, {-0.0199853703379631, \
-0.0000520107132615522}, {0.0399897247552872,
0.0000320119106618222}, {0.0600147768855095,
0.0000576710590394214}, {0.119977183640003,
0.000138641073135659}, {0.3599793612957,
0.000222295187995769}, {0.76000714302063,
0.000279692729236558}, {1.30006861686707, 0.00035656921681948}};
ListPlot[data]
(* Fit *)
fit = NonlinearModelFit[
data, {function[Vd, Rs, Rsh, Is1, n1, Is2, n2]}, {{Rs, 400}, {Rsh,
8000}, {Is1, 2*10^-4}, {n1, 1}, {Is2, 2*10^-4}, {n2, 1}}, {Vd}]
**************************
I get three problems.
1. NDSolve doesn't converge conveniently for values of Vd near 0.
NDSolve::mconly: "For the method \!\(\"IDA\"\), only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions."
2. If I keep all these data points, there isn't enough memory for the fit calculation.
General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.
3. If I eliminate a few data points, I get the following error:
NonlinearModelFit::nrlnum: "The function value {0.000335912 +function[-1.20006,400.,8000.,0.0002,1.,0.0002,1.],0.000308144 +function[-1.00005,400.,8000.,0.0002,1.,0.0002,1.],0.000220253 +function[-0.380006,400.,<<4>>,1.],<<1>><<1>><<1>>,0.000272983 +function[-0.740023,400.,8000.,0.0002,1.,0.0002,1.],0.0000520107 +function[-0.0199854,400.,8000.,0.0002,1.,0.0002,1.]}\\n is not a list of real numbers with dimensions {6} at {Rs,Rsh,Is1,n1,Is2,n2} = {400.,8000.,0.0002,1.,0.0002,1.}."
I suspect this error is a consequence of the first one.
Some help please...
Does someone know if Mathematica can actually do this fit?
Or, is the function too messy?
Any idea for working out this problem?
Eventually, should I try another method or program?
Thanks in advance for any help.
A bright and sunshiny day to you!
Alexandre
I'm working on a simple electronic circuit with two resistors and two diodes.
I have experimental data of the current-voltage characteristic and am trying to fit the corresponding equation - the resistors and diodes are unknown.
With basic circuit analysis, I get this tricky (messy) equation:
Id - (Vd-Rs*Id)/Rsh - Is1*(Exp[(Vd-Rs*Id+n2*vt*Log[1-(Id-(Vd-Rs*Id)/Rsh)/Is2])/(n2*vt)] - 1) = 0
where the current-voltage characteristic is Id(Vd), Rs is a series resistor, Rsh is a parallel shunt resistor and Is1, n1, Is2, n2 are the saturation current and ideality factors of the two diodes.
To achieve this, I've installed Mathematica 8.0 for Students and have written a small code.
**************************
(* Creation of an implicit function *)
vt = 0.0256;
function =
Last[Last[
Last[NDSolve[{Id[Vd, Rs, Rsh, Is1, n1, Is2,
n2] - (Vd - Rs*Id[Vd, Rs, Rsh, Is1, n1, Is2, n2])/Rsh -
Is1*(Exp[(Vd - Rs*Id[Vd, Rs, Rsh, Is1, n1, Is2, n2] +
n2*vt*Log[
1 - (Id[Vd, Rs, Rsh, Is1, n1, Is2,
n2] - (Vd - Rs*Id[Vd, Rs, Rsh, Is1, n1, Is2, n2])/
Rsh)/Is2])/(n1*vt)] - 1) == 0,
Id[0, Rs, Rsh, Is1, n1, Is2, n2] == 0},
Id, {Vd, -1.5, 1.5}, {Rs, 1, 3000}, {Rsh, 100, 10000}, {Is1,
10^-7, 10^-2}, {n1, 1, 20}, {Is2, 10^-7, 10^-2}, {n2, 1, 20}]]]]
(* Data *)
data = {{-1.20006167888641, -0.000335911958245561}, \
{-1.00005328655243, -0.000308143673464656}, {-0.380005955696106, \
-0.000220252826693468}, {-0.119975663721561, -0.000175646884599701}, \
{-0.740023016929626, -0.000272983132163063}, {-0.0199853703379631, \
-0.0000520107132615522}, {0.0399897247552872,
0.0000320119106618222}, {0.0600147768855095,
0.0000576710590394214}, {0.119977183640003,
0.000138641073135659}, {0.3599793612957,
0.000222295187995769}, {0.76000714302063,
0.000279692729236558}, {1.30006861686707, 0.00035656921681948}};
ListPlot[data]
(* Fit *)
fit = NonlinearModelFit[
data, {function[Vd, Rs, Rsh, Is1, n1, Is2, n2]}, {{Rs, 400}, {Rsh,
8000}, {Is1, 2*10^-4}, {n1, 1}, {Is2, 2*10^-4}, {n2, 1}}, {Vd}]
**************************
I get three problems.
1. NDSolve doesn't converge conveniently for values of Vd near 0.
NDSolve::mconly: "For the method \!\(\"IDA\"\), only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions."
2. If I keep all these data points, there isn't enough memory for the fit calculation.
General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.
3. If I eliminate a few data points, I get the following error:
NonlinearModelFit::nrlnum: "The function value {0.000335912 +function[-1.20006,400.,8000.,0.0002,1.,0.0002,1.],0.000308144 +function[-1.00005,400.,8000.,0.0002,1.,0.0002,1.],0.000220253 +function[-0.380006,400.,<<4>>,1.],<<1>><<1>><<1>>,0.000272983 +function[-0.740023,400.,8000.,0.0002,1.,0.0002,1.],0.0000520107 +function[-0.0199854,400.,8000.,0.0002,1.,0.0002,1.]}\\n is not a list of real numbers with dimensions {6} at {Rs,Rsh,Is1,n1,Is2,n2} = {400.,8000.,0.0002,1.,0.0002,1.}."
I suspect this error is a consequence of the first one.
Some help please...
Does someone know if Mathematica can actually do this fit?
Or, is the function too messy?
Any idea for working out this problem?
Eventually, should I try another method or program?
Thanks in advance for any help.
A bright and sunshiny day to you!
Alexandre