# Exponential trendline to best fit I-V curve data

I am trying to plot a best-fit trendline to an I-V curve for a Zener diode. The data is exponential so linear regression is not suitable in this instance.

Here is my data. The important columns are 2 and 3, which are current and voltage, respectively. In this case, the current data is being plotted as a function of voltage.

column 1,column 2,column 3

-15.0,-13.33,-0.71

-11.2,-9.71,-0.696

-7.50,-6.30,-0.675

-3.76,-3.45,-0.636

0,0,0

3.76,3.00,0.639

7.51,6.56,0.676

11.2,10.16,0.696

15,13.7,0.71

Here is part of the code I am working with:

\documentclass{article}
\usepackage{tikz, pgfplots, pgfplotstable, siunitx}

\usepgfplotslibrary{units}

\sisetup{
round-mode = places,
round-precision = 2,
}

\begin{document}

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=Voltage,
ylabel=Current,
x unit=\si{\volt},
y unit=\si{\milli\ampere},
legend style={at={(0.5,1.4)},anchor=north},
x tick label style={rotate=90,anchor=east}
]
\addplot [only marks, mark = *, blue] table[x=column 3,y=column 2,col sep=comma]{tables/Table 6.csv};
\addlegendentry{$y(x)$}
\end{axis}
\end{tikzpicture}
\caption{Zener diode reverse bias}
\end{center}
\end{figure}

\end{document}

• In my memory, linear regression is as far as what TikZ can do. You are asking too much for it to fit an exponential curve. Maybe you need to use some other programmes like MATLAB, Origin or others to calculate the curve first which is very easy. (By the way, matlab2tikz works well if you use MATLAB.) Feb 5, 2022 at 4:36
• By the way, it seems that the I-U characteristic of the diode is not actually exponential. Some smooth plot (for example smoothingspline fitting in MATLAB) will do. Feb 5, 2022 at 4:44
• Fair enough, thanks! Feb 5, 2022 at 11:47
• Look into sagetex package which gives you access to Sage, an open source CAS, as well as Python. I tried plotting your data and, assuming I did it correctly, got data that didn't look anything close to exponential; so exponential regression gave a poor fit.
– DJP
Feb 6, 2022 at 1:07