Wednesday, November 16, 2016

What good is multiple choice?

open question:
what is the expected percentage of examinees to answer a multiple choice question correctly, accounting for random guessing?

thoughts:
if a question has five multiple choice answers, a student has 20% chance to blind guess the correct answer. If the number of examinees to answer the question right is significantly lower than 20%, does that suggest that the question is unfair, intentionally misleading, or incorrect?

for example question 87 on GRE Physics 9677 had 6%! of students answering correctly. They'd have done better not studying ANY physics and blindly picking ABCD or E! Why did this question make more students answer INCORRECTLY than one could reasonably expect for a multiple choice answer!?

I think it shows a certain intelligence that the majority of students put similar thoughts to avoid the correct answer. Like when Muhammad Ali purposefully chose wrong answers on his IQ test to get out of the army, and the testers concluded that to answer that many answers wrong, far more than one would expect from just random guessing, he must be aware of the right answer and purposefully avoiding it. Here of course, the physics students have no reason to avoid answering correctly for a low score, but I believe that they are onto the right idea, but getting tricked by the question.

But were the 6% who answered correctly truly more expert in their knowledge, or were they 'worse thinkers' for not arriving at the same conclusions as their peers!? Or did they simply get lucky with a guess?

What value does a test have when over half the questions are expected to be answered incorrectly by the average test taker, and the majority of questions have a correct answer rate no better than guessing, and some significantly worse!??


OH I forgot there is a 1/4 point penalty for guessing. So that means a hard problem will have fewer people answering. And the percent answering correctly is out of all test takers, including those that didn't answer the question at all. So maybe 6% answered the question and 6% got it right with 0% answering the problem incorrectly, not necessarily that 100% answered and 94% got the question wrong.

I pick (E) Not enough information provided to arrive at a conclusion.

---

But even then, a multiple choice test is not a valid reflection of real life problem solving. You get better at these tests by practicing shortcuts to eliminate wrong answers, then quickly selecting the better choice of two or three candidates.

Solving worthwhile problems isn't like picking the most attractive bachelor on a TV dating show. You don't just take what has already been done. You have to create an answer nobody has found before.

GRE 9677 problem 2. Faraday's Law of Inductance

GRE Physics practice exam 9677

Problem:
 

2. The circuit shown above is in a uniform magnetic field that is into the page and is decreasing in magnitude at the rate of 150 tesla/second. The ammeter reads:

(A) 0.15 A
(B) 0.35 A
(C) 0.50 A
(D) 0.65 A
(E) 0.80 A



Solution:

Correct answer: (B) 0.35 A.
Percent of test takers answered correctly: 29%

By Faraday's Law of Inductance, a circuit in the presence of a changing magnetic field ... induces an emf voltage... with the direction of the magnetic field when the magnetic field is decreasing...

Stated in the Maxwell-Farady equation


In the simple arrangement of the problem, the magnetic field is uniform and the line and surface integrals are trivial so the equation has the simple form


With only one loop in the circuit, we reduce all this down to just:

|V| = (|rate of change in magnetic field|) x (area)
= (150 tesla/s) * (0.1 m x 0.1 m) = 0.15 V

Now we use the "right hand rule" to find that the magnetic field is producing a clockwise current. (Right hand thumb points with the magnetic field into the page, fingers curl clockwise with the direction of induced current.)

The voltage generated by the decrease in magnetic field acts against the direction of change...
"if the magnetic field is increasing, the induced field acts in opposition to it. If it is decreasing, the induced field acts in the direction of the applied field to try to keep it constant." Lenz's Law http://hyperphysics.phy-astr.gsu.edu/hbase/electric/farlaw.html
So in this case the induced current flows with the magnetic field, in the clockwise direction.
 
The current in the circuit diagram is in a counter-clockwise direction. (The little bar on the DC voltage source is the negative terminal and the big bar opposite is positive. By convention, current flows negative to positive.)

We have all then all the components to the circuit equation:

V_dc - V_induced = I x R

(5.0 V) - (0.15 V) =  I x (10 ohms)

gives the solution (B) for the current

I = 0.35 A



Sidenotes

Tesla is measure of magnetic field strength = Volt * second / meter^2

Wikipedia (tesla unit) gives some reference numbers for real world magnetic fields:
  • 31.869 µT (3.2 × 10−5 T) – strength of Earth's magnetic field at 0° latitude, 0° longitude
  • 5 mT – the strength of a typical refrigerator magnet
  • 1.25 T – magnetic flux density at the surface of a neodymium magnet
  • 1 T to 2.4 T – coil gap of a typical loudspeaker magnet
  • 1.5 T to 3 T – strength of medical magnetic resonance imaging systems in practice, experimentally up to 17 T[12]
So the 150 Tesla /s decrease in this problem is from a HUGE magnetic field holy crap! Any field with THAT much strength beats anything humans can generate. It would more likely come from some massive collapsing star!

  • 45 T – the current (2015) world record for continuous field magnets [19]
  • 108 - 1011 T (100 MT-100 GT) – magnetic strength of the average magnetar
So this problem seems like an academic textbook-ish exercise, not real world applicable!




Only 29% of test takers got this question right. I don't think people couldn't think of what to do. I think whether to add or subtract the induced voltage is what threw most test takers off.

A temptation is to point the current opposite to the magnetic field. But Lenz's Law states that the direction of the current opposes the change in magnetic field, not the magnetic field itself! In this case, the induced current went in the same direction as the magnetic field.

Tuesday, February 9, 2016

How to plot graphs automatically from C using GNUplot on Windows

An example plot made using GNUplot

 n=5 eigenfunction for the quantum harmonic oscillator
generated with a modified version of the code by PAOLO GIANNOZZI
harmonic1.c 


The Method

Following (i.e. copying word for word) an answer on StackOverflow given by Nidish Narayanaa

1. Create a script file that tells gnuplot to plot your data file.
  •  any filename and extension for the script file is fine. 
  •  put a line of text in the file, something like:
    plot "output.dat' with lines
  •  write the C program to generate this automatically, changing 'output.dat' to whatever file name the output data is called

        FILE *gnuscript;
        gnuscript = fopen("gnu_script.wtf", "w"); // file name for the script is whatever you want
        fprintf(gnuscript, "plot /"%s/" with lines", outputdata);
        fclose(gnuscript);

2. Use the system() function to make gnuplot run the script
  • import system() from the standard library <stdlib.h>
  • write the string as the cmd console would execute it, putting the entire command in quotes so that space characters ' ' in the file path are recognized and being careful to escape all the backward slashes '\'.
    #include <stdlib.h>
    system("\"\"c:\\program files (x86)\\gnuplot\\bin\\gnuplot.exe\" \"-p gnu_script.wtf");

Source:
 

 


 
Example Code

Here's a fake example to ask user for file name to output data, generate a gnuplot script file to plot the data, then call gnuplot to run the script.

 
    #include <stdlib.h>
    #include <stdio.h>

 
    // run your calculations...
    double *data;
    data = malloc (abagillion * sizeof(double));
    int i;
    for (i = 0; i < abagillion; i++){
      data[i] = put + yo + feengas + in + da + sky + ifu + know + i + am + dabessss;
      data[i] *= ideedit; 
 
    // ask user for file name to output data 
    FILE *out; 
    char outputdata[80];
    fprintf(stderr, "Output file name = ");
    scanf("%80s", outputdata);
    out = fopen(outputdata, "w");
 
    // print out to the data file
    for (i = 0; i < abagillion; i++){
      fprintf(out, "%d, %3.2f \n", i, data[i]);
    }
    fclose(outputdata);
    free(data); 
 
    // generate the script to plot the data
    FILE *gnuscript;
    gnuscript = fopen("gnu_script.wtf", "w"); // file name for the script is whatever you want
    fprintf(gnuscript, "plot /"%s/" with lines", outputdata);
    fclose(gnuscript);

    // call gnuplot (from wherever it is installed) to run the script
    system("\"\"c:\\program files (x86)\\gnuplot\\bin\\gnuplot.exe\" \"-p gnu_script.wtf");


Getting the full path of the gnuplot executable correct

For some reason, adding gnuplot directory to the PATH environment variable didn't do anything. Typing 'gnuplot' in cmd returns an error message. As expected, calling gnuplot in the system command with 'gnuplot' didn't work.

So I had to put in the full path to the gnuplot executable into the system call... carefully.

I'm using Windows, so that system call at the last line is Windows specific. There's spaces in the folder name, so you gotta put the whole command in quotations.



Thursday, February 4, 2016

Numerov Method for Solving Schrodinger's 1D Time Independent Wavefunction Equation

Numerov's Method


Below I summarize 'all I need to know' about the Numerov method for solving a family of second order differential equations, including the Schrodinger equation.


It's basically a sixth order error Taylor expansion in the wavefunction Psi, followed by a second order error central difference approximation for the fourth derivative of Psi. The combination of terms preserves a sixth order error in a single step.

Some sources say the accurate global error in this scheme is of fourth order, not fifth order as one might naively suppose, but I have not found or divined by my insufficient brainpower how one goes about proving this type of thing. So I'll duly report it's a fourth order scheme without any justification.

Typing this out in LaTex is beyond my current abilities with the language, and would require more hours, brain cells, and frustrations than I'm willing to invest right now. Also a liver transplant. So I'm just going to post the pictures of handwritten notes that I've carefully crafted.

Check the references if you want nicely formatted equations to steal using Copy & Paste. Cuz that's what I do.

Theory.  

(Derivation of the numerical formula)


Application. 

(Computing an explicit numerical formula to solve the dimensionless form of the 1D time independent harmonic oscillator)


References: 

(Where I learned/stole/plagiarized all this shit from)

  • main guide to follow

- http://www.fisica.uniud.it/~giannozz/Corsi/MQ/LectureNotes/mq-cap1.pdf

  • numerical difference formulas reference

- Numerical Methods Using Matlab, 4th Edition, 2004John H. Mathews and Kurtis K. FinkISBN: 0-13-065248-2

  • dimensionless form of the schrodinger equation

- https://en.wikipedia.org/wiki/Nondimensionalization

  • alternative explanation

- Generalized Matrix Numerov Solutions to the Schrodinger Equation http://www.physics.nus.edu.sg/student/Honours%20Projects%20Repository%202013-14/TANG_DONGJIAO%20thesis.pdf

Thursday, January 28, 2016

FML in Physics

Fuck my life in Physics, when...

  • when physics texts have a ton of unexplained calculations with lots of (often sloppy) notation. learning this stuff for the first time, not knowing whether the equation is right or not, and you can't tell if that minus sign or variable doesn't make sense because you fail to understand something, or it's simply a typo.
  • when you read 10 documents on the exact same problem, because none of them give a comprehensive explanation - so you need to piece together partial explanations from many sources.
  • when the equations from every source all look different... and you need to get one document's expression into the form of another document to check each step for errors. Cross-check, verify the information being presented to you is in fact, accurate, before you spend the following hours not knowing why it is correct, and being offered no explanation by the physicist author.
  • self-inconsistencies within the same document between the analytical theory equations and the actual numerical code implementation. 
Case in point:

Numerov Algorithm for numerical solution of the Schrodinger Equation (1-D time-independent simple harmonic oscillator) ref: http://www.fisica.uniud.it/~giannozz/Corsi/MQ/LectureNotes/mq-cap1.pdf

numerical code:

f[i] = ddx12 * 2. * (vpot[i] - e);

y[i + 1] = ((12. - f[i] * 10.) * y[i] - f[i - 1] * y[i - 1])
                 / f[i + 1];

where:
vpot[i] = 0.5 * x[i] * x[i];

ddx12 = dx * dx / 12.

you can see (by the expression for y[n+1] matching the theory presented below) that this f[i] is intended to be exactly the auxiliary function described in the notes.


First notice that f_n in the code is supposed to be a function of g_n, but it has no mention of mass m, Planck's constant hbar as the theory exposits. Did we assume the mass and hbar equal one? Not necessarily. Let's take a closer look at the definition of g_n:



We can rectify this discrepancy of g_n in the code vs theory by noticing that the code should use the dimensionless form of the Schrodinger equation, which have the mass and hbar constants built into the transformed, adimensional variable corresponding to x.


That would make g_n in the Schrodinger equation be equal to g(x~) = 2e - x~^2.


But despite this progress, another troubling observation persists. The coded function f_n is equal to
f_n = -g_n * dx^2 / 12...  
NOT  equal to
f_n = 1 + g_n * dx^2 / 12, 
as the theory stipulates!


So... why??? Unless somehow they are equal with additional physics assumptions, blatant arithmetic errors caused by my careless stupidity, or an obvious simplification that eludes me... the theory tells one story and the code acts out another!

This is so frustrating to learn from!

Don't get me wrong. I really appreciate the information contained in the notes and the code, honestly, I do, because it gives me lots of guidance and explanation that other texts gloss over - this document has the best treatment of the numerical method for a beginner that I have come across - but unexplained self-inconsistencies are huge roadblocks to understanding and I have trouble hurdling over them!


EDIT: NVM I FOUND IT
source code:

/* f(x) as required by the Numerov algorithm */
for (i = 0; i <= mesh; ++i) {
f[i] = 1. - f[i];
}

First, the solver calculates the expression -g_n * dx*dx/12 to check for positive or negative sign. Then before actually using it in Numerov's algorithm, it fixes the value to f_n = 1 + g_n * dx*dx /12

Wednesday, January 13, 2016

Calculus of Variations study notes

source: Calculus of Variations. Joel G. Broida. Lecture Notes. 2009. link
 
the derivative is same as saying, if you vary the input x by a little bit h... then what you get is the function at x, plus a linear term times h, plus a remainder term that goes away as h goes to zero.

A functional is differentiable, if when we vary the input by some additional function h, the difference in the outputs of the varied and original functional is a linear (first order) function of h, plus some remainder terms on the order of h^2 such that the remainder disappears as h goes to zero.


Let's find the differential for a Lagrangian type functional.

note: h is not a number like epsilon going to zero, it is a function. i assume we choose continuously differentiable functions. therefore we can take its derivatives.

so the way we go about varying the functional is we put the functional at the input point at which we want its derivative. we subtract this amount from the functional with inputs with additional h function in x, h' function in x', h'' in x'' etc. for all inputs it depends on.

Then use the linear expansion of the function (assuming that the function f is differentiable, we need that to make it work) at the point x, x', t. Separate second order or higher terms in h from the first order terms. 
These are the remainder and the linear part, respectively.
Assuming that the remainder term goes to zero, since it is of order h^2, when h goes to zero... we focus on the linear term L. Evaluate its integral. Integration by parts happens to be useful in this step.

The first term is simply evaluated at the bounds of integration. When we do physics with normalized wavefunctions, we require that the functions go to zero as x goes to positive or negative infinity, so this term usually becomes zero. If we use delta functions as our trial function h, this term evaluated at the bounds always equals zero, so long as we don't place a bound at the singularity of the delta function, which we won't LOL.

Remember that h is a function of t. and so are x, x', etc.
f( t, x, x' ) = f (t, x(t), x'(t))



Euler-Lagrange


the function h has to be completely arbitrary, so long as its continuous. This include the dirac delta function, which is within the closure, upper boundary of a series of continuous functions.

key for h is that it is nonzero between bounds and zero at bounds AND that we can pick h however we please. suppose that f is non-zero, so say it's positive at least a t a point. by continuity, there must be a region around this point where f is strictly positive and greater than some arbitrary but positive constant c. construct an h function that equals 1 across this region, and goes to zero outside of it. the integral in consideration must then be greater than the value of the integral over this positive region, whose width we denote d. then the integral is at least c * 1* d, which is greater than zero. by contradiction of the hypothesis, we have shown that f cannot be nono-zero. by picking h to be some value only when f is strictly positive, we made this argument possible.





Aside: Here's how to construct infinitely differentiable 'plateau' functions. that is, zero outside some interval, and equal to 1 or some other constant within a strictly smaller interior interval.

f satisfies the infinitely differentiable aspect.


g creates a situation where it becomes f over f = 1 if f is greater than or equal to t = 1. change the f (1 - t) term to f (R - t) for the radius R you wish for an interior interval.


h is the function that has all those plateau properties. zero outside an interval with radius of 2, equal to one within a radius of 1, and presumably a descreasing slope from 1 to zero in between.



finishing the Euler-Lagrange proof


the stationary point of a function has an analogous definition called the extremal curve of a differentiable functional. the extremal is by definition, the curve whose functional derivative equals zero. so the entire linear term equals zero

when we consider the space of curves passing through two points, at the bounds of integration of the functional the function h(t) must equal zero, for the curve to pass exactly through those boundary points.

the lemma preceding the euler-lagrange theorem says the first integrand term equals zero.



If we have multi-dimensional function with variables x, x', y, y', z, z', etc. the same thing is done separately for each dimension and associated variable. we vary y by y + h, y' by y' + h', etc. etc. do the linear approximation by Taylor expansion, integrate by parts, make the boundary terms vanish (by the argument that the curve passes through fixed points. so that the h function equals zero at the boundaries)



Shortest distance between two points in a plane is a straight line

a curve in two dimensions can be parameterized as a single variable s along the 1-dimension of the curve, or as two dimensions x, y in the Cartesian plane.

an incremental movement along the curve is given by the pythagorean theorem between a displacement in x, and a displacement in y as . Sqrt( dx^2 + dy^2).

if we then write the total derivative in terms of one variable, dx, we get dx sqrt(dx^2/dx^2 + dy^2/dx^2) = dx sqrt( 1 + y'(x)^2).


Apply the functional derivative to the integral of f(x, y(x), y'(x)).



t should be the first variable, it is independent in the theorem 1. anyways. x serves the place of t here.
f = sqrt( 1 + y'^2) . df/dy = 0. - d/dx (df/dy') = - d/dy (y')/sqrt(1 + y'^2). the last term is zero because h is zero at boundaries for the curve to pass through fixed points. so the whole thing being zero makes the middle term zero.

y' is a function of x. so d/dx of that expression = 0 means that the expression is a constant in terms of x, and of y(x), y'(x).
(y')/sqrt(1 + y'^2) = constant.

moving the y' terms all to one side, and c to the other, we find 0<c<1, so the radical term in the square root is non-negative.
then we can write y' in terms of c, so y' is another constant. then integrating y = mx+b where m and b are constants.