Dept. Logo

Main   |   PHY 121   |   PHY 122   |   PHY 133   |   PHY 134

Overview

This tool fits a resonance curve of the form:

$$y=\frac{V_0\gamma\omega}{\sqrt{(\omega^2-\omega_0^2)^2+\gamma^2\omega^2}}$$

This curve forms an asymmetric peak, and predicts the voltage across a resistor in a forced RLC circuit.

Back to Top
Manual Interface

Plot title:

x-axis label:
y-axis label:

x-axis range: Min: Max:
y-axis range: Min: Max:
(Leave these blank for automatic range selection, which should usually work fine.)

Parameter guesses (generally optional, but may be needed depending on data quality):
Peak height, \(V_0\) (in y-units):
Peak location, \(\omega_0\) (in x-units):
Peak width, \(\gamma\) (in x-units):

Use x-error bars?   
Use y-error bars?   
Legend location?   

x1:   +/-     y1:   +/-
x2:   +/-     y2:   +/-
x3:   +/-     y3:   +/-
x4:   +/-     y4:   +/-
x5:   +/-     y5:   +/-
x6:   +/-     y6:   +/-
x7:   +/-     y7:   +/-
x8:   +/-     y8:   +/-
x9:   +/-     y9:   +/-
x10: +/-     y10: +/-
x11: +/-     y11: +/-
x12: +/-     y12: +/-
x13: +/-     y13: +/-
x14: +/-     y14: +/-
x15: +/-     y15: +/-
x16: +/-     y16: +/-
x17: +/-     y17: +/-
x18: +/-     y18: +/-
x19: +/-     y19: +/-
x20: +/-     y20: +/-

                    

Back to Top
Google Sheets Interface
To use this section, you need to enter your data into a copy of the Google Sheet for Resonance Plotting Tool Data. You then need to click "File>Download as>Comma-separated values (.csv, current sheet)" to download the file in a form that is processed by this program. Then, you upload that file here, and click the button to make your plot.

Upload your .csv file here:

Back to Top
Plotting Tool FAQ

Debugging (Nonlinear Fit & Parameter Guesses)

This plotting tool performs a nonlinear fit. It does so by starting with a "guess" and optimizing the fit iteratively from there.

The tool attempts to make a "guess" on its own, based on your data; however, sometimes your data won't be good enough for this guess to be accurate (requiring a negative square root or something like that). In such circumstances, it looks to your provided parameter guesses (or 1, if those guesses are missing).

If you're having problems (if it crashes or gives a terrible fit), try entering/tweaking those guesses. It may be that your data is just bad, but hopefully you can find a reasonable fit just by changing what you're guessing.

Debugging (Other)

Hopefully, the warnings and error messages you receive will help your resolve any technical issues you have. If you are unable to solve your issues on your own, come to the help room.

Report any bugs to phy_introlabs@stonybrook.edu (but please make your own attempts, with TAs in the help room, to resolve said bugs first). Please include a screenshot of inputs (if using the manual interface) or the CSV file used (if using the CSV file interface).

Do not take a lack of warnings to indicate a perfect plot. Other errors (especially misplaced decimal points) can still cause problems, and you are responsible for making sure these do not occur.

You should check your data and make sure it follows the fit, and check that your error bars are reasonably sized (in particular, not larger than the range of your data!).

Additionally, a few technical things to be careful about:

  • DO NOT copy and paste unusual characters (like \(\omega\)) directly into the text boxes; this will cause the plotting tool to crash. (The reason is similar to why things might break if you tried to paste an emoji into Notepad.) Instead, if you wish to enter Greek characters, use \(\LaTeX\) (see below).
  • When extracting data with very large or small magnitude, be sure to note any relevant scientific notation factors.
  • Check that your error bars fit on your plot. (The auto-scale we use is not always perfect about this.)

Advanced Techniques for Plotting Tool Use

Here are a few more technical features that can either make your life easier or can make your plot look nicer:

  • To input in scientific notation, format your numbers as "1.2e-6" (this is valid for any numerical input).
  • To input mathematical expressions (such as \(x^2\)) in your title or axis labels, first write your expression in \(\LaTeX\), then enclose it between dollar signs. E.g.: "$\sqrt{\frac{L}{g}}$" will output as \(\sqrt{\frac{L}{g}}\); "$ax^2+bx+c$" will output as \(ax^2+bx+c\).
    • An equation editor (which will give you the \(\LaTeX\) code for a mathematical expression) is available here.
    • As a special case: to input Greek letters, write them in \(\LaTeX\). E.g.: to get \(\alpha\), write "$\alpha$"; to get \(\Delta\), write "$\Delta$" (note that the capital D in "Delta" gives you a capital \(\Delta\); a lowercase d would give you a lowercase \(\delta\)).
  • To have a multi-line title (or axis label), type a "\n" where you want the line break.
Back to Top
How It Works

Your inputs here are first forwarded to a PHP script. This PHP script compiles your data (extracting it from the CSV file if you choose to use that interface) and runs basic validation on it (giving warnings or errors if something is wrong, and doing its best to fix such issues in a minimally-intrusive way).

This script then saves your actual data to a file, and calls a Python script (from the command line) with your other plot parameters. This python script reads your data back from that file, runs the fitting algorithm, and makes the plot. It then saves the plot as an image which is read by the (HTML surrounding the) PHP script.

The python script makes the plot using the Matplotlib library. If you want to make a plot with a similar style, you can read the documentation provided there.

We first run a linearized fit. Plotting \(\frac{1}{y^2}\) vs. \(\omega^2\) gives a quadratic relationship, so we can fit this model with purely linear optimization. We thus fit this model and extract from its coefficients initial guesses for \(F_0\), \(\omega_0\), and \(\gamma\) to be entered into our nonlinear optimization routine. If any of these fails (due to negative square roots), we fall back on the "guesses" provided, or \(1\) if a guess is missing or invalid.

The procedure of the script from there depends on what error bars you are using. If you have no error bars, then we run a vertical least-squares fit using scipy.optimize.curve_fit. If you enter error bars on both axis, we assume those uncertainties and perform an orthogonal distance regression using scipy.odr. If you enter only one, we do a weighted (vertical or horizontal) least squares fit using scipy.odr: we use the given uncertainty as weights on the relevant axis, and assume the uncertainty in the other number is tiny (\(10^{-150}\), to be precise).

For a slightly more thorough discussion, see our standard plotting tool here.

Back to Top