How to Blow Up The World
If you can't find the correct answer, keep making mistakes until you get better at it. Or just blow everything up.
Thursday, June 1, 2017
Wednesday, May 31, 2017
In general, you can't substitute an input variable into a function and expect the output of the function to be unchanged.
In general, you can't substitute an input variable into a function and expect the output of the function to be unchanged.
Even if the function equals a constant, it may depend on the input variable and its output may happen to equal a constant for all values of that particular variable - but not produce the same output for another variable.
Let v(t) = t^p / p!
Consider the function (d/dt)^p [ v(t) ] = 1
If we replace the input variable with (1-t), keeping the function itself (as a p-th derivative with respect to t) unchanged, we get
(d/dt)^p [ v(1-t) ] = { 1 if p even, -1 if p odd}
because each differentiation of v(1-t) = (1-t)^p / p! introduces a multiplicative factor of (-1)
If we take an additional derivative with respect to t, as in the case of (d/dt)^(p+1) [ v(t) ], we get a function that is zero for all values of (1-t). The function happens to be equal to its cousin (d/dt)^(p+1) [ v(1-t) ] = 0, only because (d/dt)^p [ v(t) ] and (d/dt)^p [ v(1-t) ] are both constants.
It would be incorrect and misleading to assert that because (d/dt)^(p+1) [ v(t) ] = 0, therefore (d/dt)^(p+1) [ v(1-t) ] = 0. Even if the function equals zero everywhere, we cannot simply substitute one input variable with another.
For example, if we had tried (d/dt)^(p+1) [ v(1-t^2) ], the function is not identically zero. It is a parabolic curve with squiggles crossing the x-axis between -1<t<1, as the graph for p=8 shows below.
Even if the function equals a constant, it may depend on the input variable and its output may happen to equal a constant for all values of that particular variable - but not produce the same output for another variable.
Let v(t) = t^p / p!
Consider the function (d/dt)^p [ v(t) ] = 1
If we replace the input variable with (1-t), keeping the function itself (as a p-th derivative with respect to t) unchanged, we get
(d/dt)^p [ v(1-t) ] = { 1 if p even, -1 if p odd}
because each differentiation of v(1-t) = (1-t)^p / p! introduces a multiplicative factor of (-1)
If we take an additional derivative with respect to t, as in the case of (d/dt)^(p+1) [ v(t) ], we get a function that is zero for all values of (1-t). The function happens to be equal to its cousin (d/dt)^(p+1) [ v(1-t) ] = 0, only because (d/dt)^p [ v(t) ] and (d/dt)^p [ v(1-t) ] are both constants.
It would be incorrect and misleading to assert that because (d/dt)^(p+1) [ v(t) ] = 0, therefore (d/dt)^(p+1) [ v(1-t) ] = 0. Even if the function equals zero everywhere, we cannot simply substitute one input variable with another.
For example, if we had tried (d/dt)^(p+1) [ v(1-t^2) ], the function is not identically zero. It is a parabolic curve with squiggles crossing the x-axis between -1<t<1, as the graph for p=8 shows below.
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.
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:
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:
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...
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:
gives the solution (B) for the current
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.htmlSo 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]
- 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 wantfprintf(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.
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...
EDIT: NVM I FOUND IT
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
- 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
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.
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
Subscribe to:
Comments (Atom)










