.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_08_child_langmuir.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_08_child_langmuir.py: Power law: vacuum diode ======================= In a vacuum diode, the space-charge limited anode current follows the Child–Langmuir law I = k · U^(3/2). Fitting a general power law tests whether the exponent really is 3/2. .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python import numpy as np import fitwise as fw rng = np.random.default_rng(10) voltage = np.linspace(10, 200, 25) # V current = 0.018 * voltage**1.5 * (1 + rng.normal(0, 0.02, voltage.size)) # mA dI = 0.02 * current result = fw.fit(fw.models.powerlaw, voltage, current, yerr=dI) print(result) .. rst-class:: sphx-glr-script-out .. code-block:: none Model: powerlaw(x; amp, exponent) Method: Trust Region Reflective (scipy least_squares) (auto: nonlinear) Converged: yes (14 evals) Data: 25 points, yerr given (absolute) Start: amp, exponent: log-log fit Parameter Value ± Std.Err Rel. Bounds amp 0.01786 0.00041 2.3 % – exponent 1.5002 0.0051 0.3 % – χ²/ndf = 0.532 (23 dof, p = 0.97) R² = 0.99976 AIC = -13.9 Correlations > 0.5: amp–exponent (-0.98) Warnings: none .. GENERATED FROM PYTHON SOURCE LINES 23-24 Is the exponent compatible with 3/2? .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python n = result.params["exponent"] deviation = (n.value - 1.5) / n.stderr print(f"exponent = {n.value:.4f} ± {n.stderr:.4f}, deviation from 1.5: {deviation:+.1f} σ") .. rst-class:: sphx-glr-script-out .. code-block:: none exponent = 1.5002 ± 0.0051, deviation from 1.5: +0.0 σ .. GENERATED FROM PYTHON SOURCE LINES 29-30 If theory fixes the exponent, fix it and fit only the prefactor: .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python fixed = fw.fit(fw.models.powerlaw, voltage, current, yerr=dI, fixed={"exponent": 1.5}) print(fixed) .. rst-class:: sphx-glr-script-out .. code-block:: none Model: powerlaw(x; amp, exponent) Method: Trust Region Reflective (scipy least_squares) (auto: nonlinear) Converged: yes (11 evals) Data: 25 points, yerr given (absolute) Start: amp: log-log fit · exponent: fixed Parameter Value ± Std.Err Rel. Bounds amp 0.017871 0.000071 0.4 % – exponent 1.5 – – fixed χ²/ndf = 0.51 (24 dof, p = 0.98) R² = 0.99976 AIC = -15.9 Warnings: none .. GENERATED FROM PYTHON SOURCE LINES 34-39 .. code-block:: Python fig, axes = result.plot() axes[0].set_xscale("log") axes[0].set_yscale("log") axes[0].set_ylabel("I (mA)") axes[1].set_xlabel("U (V)") .. image-sg:: /auto_examples/images/sphx_glr_plot_08_child_langmuir_001.png :alt: plot 08 child langmuir :srcset: /auto_examples/images/sphx_glr_plot_08_child_langmuir_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 18.503588541666673, 'U (V)') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.182 seconds) .. _sphx_glr_download_auto_examples_plot_08_child_langmuir.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_08_child_langmuir.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_08_child_langmuir.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_08_child_langmuir.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_