Archive for June, 2009

June 29th, 2009

PHP vs Perl

What is PHP?

PHP is an extensible high level web language used for creating dynamical websites. It has typeless variables, thousands of functions, and a fast, svelte interface.

what is Perl?

Perl is a simple, high level programming language designed to produce scripts, create webpages, and using modules to extend its abilities. Perl also has typeless variables, user created modules, and documentation out the yin-yang.

Advantages of PHP

  • Easily mixed with HTML, either embedded with it, or using it to parse HTML.
  • Very easy to learn. PHP is similar to Java, C, C++, and Python.
  • Uses less overhead, so PHP scripts run faster.
  • More consistent code from site to site and version to version.
  • Easily create and link hundreds of webpages.

Disadvantages of PHP

  • A huge number of functions and modules. PHP has over 3000 functions in its main namespace, with lots of overlap between the functions.
  • On very busy websites, not running it in CGI mode will cause memory bloat, and long response times.
  • Inconsistent naming schemes between naming schemes.
  • Character arrays cannot be interpolated into strings.
  • No warnings automatically enabled.



Advantages of Perl

  • More documentation.
  • CPAN. ‘Nuff said.
  • More secure. (This one is hotly debatable.)
  • Lexical and dynamic scoping
  • Useful for much more then just working webpages.

Disadvantages of Perl

  • Which to use: mod_perl, CGI, FastCGI, SCGI, etc?
  • Not as intuitive to use as PHP
  • Not automatically integrable with SQL and its variants.
  • Not designed strictly for webpages, with little modules directly created for web support.
  • Horrible OOP structure. Perl has the worst OOP structure I have ever seen.

Although similar, a good web developer will know both PHP and Perl, as the two languages compliment each other in subtle ways. Both are powerful languages that can make web application programming, automation, and dynamic content a breeze to work with and develop. Indeed, I would say that learning both is crucial to the success of dynamic script driven sites, as both PHP and Perl have their advantages and disadvantages.

June 26th, 2009

JavaScript vs PHP

Both JavaScript and PHP are used with internet browsers to push interactive content on users. PHP is a server side language, while JavaScript is a client side language. Thus, in a perfect world, you can use PHP to generate a page, JavaScript to push dynamic content to users, and AJAX to stitch them together.

Both languages have their foibles and quirks, and using them is generally up to the individual programmer, however, the languages in general have strengths and weaknesses inherent in them.

Advantages of JavaScript

  • For users of object oriented languages, JavaScript is more natural.
  • Less functions, so smaller libraries
  • More often used for “eyecandy” sites, and is often used alongside DHTML, Coldfusion, or Flash

Disadvantages of JavaScript

  • Bugs and security holes
  • Slow execution, relative to PHP
  • Incompatible with some standards and browsers



Advantages of PHP

  • Allows access to databases, so community efforts, such as blogs and bulletin boards work
  • More universally supported
  • Larger libraries, so more can be done without a lot more coding

Disadvantages of PHP

  • Server Intensive
  • Many different versions, leading to naming inconsistencies.
  • Extensions can be written in C, thus pushing the faults and issues of memory management into the realm of user/ browser use, a major issue, especially when you consider that Firefox leaks memory like a sieve.

In conclusion, the use of PHP vs JavaScript is mainly dependent upon what you are trying to do, as there are some tasks each language performs well, and some tasks they cannot do at all. As a programmer, you must be able to recognize these tasks and choose the correct language. Thus, knowing both JavaScript and PHP is a must for the modern web programmer.

June 22nd, 2009

Maxwell's Equations

In physics, Maxwell’s equations are the equations that describe all electromagnetic phenomena in relation to their sources.

In their most commonly seen form, they are a set of four partial differential equations, which, along with the Lorentz force law form the complete set of laws for classical electromagnetism. Indeed, to quantize the fields, we have to delve into Quantum Electrodynamics, commonly referred to as QED.

Here, I will focus only on formulations of Maxwell’s equations in the classical sense. In this way, all of our equations are acting upon a test proton suspended in space, and influenced only by the electric and magnetic fields of other particles. Maxwell’s equations describe these interactions.

Legend

  • F is the force felt by our test particle
  • E is the electric field
  • B is the magnetic field
  • v is the velocity of the test particle
  • I is the electric current, that is \frac{dQ}{dt}
  • J is the current density
  • \epsilon_0 is the permittivity of free space, a constant
  • \mu_0 is the permeability of free space, also a constant

Above, I use bolded letters, while below I use explicit vector notation. Do not let this confuse you, as they are equivalent.

The Lorentz Force Law

\vec{F} = q(\vec{E} + \vec{v} \times \vec{B})

Maxwell’s equations in differential form

\nabla \cdot \vec{E} = \frac{\rho}{\epsilon_0}

\nabla \cdot \vec{B} = 0

\nabla \times \vec{E} = -\frac{\partial\vec{B}}{\partial{t}}

\nabla \times \vec{B} = \mu_{0}\vec{J} + \mu_{0}\epsilon_{0}\frac{\partial\vec{E}}{\partial{t}}

Maxwell’s equations in integral form

\oint_{\partial{V}}\vec{E}\cdot d\vec{A} = \frac{Q}{\epsilon_0}

\oint_{\partial{V}}\vec{B}\cdot d\vec{A} = 0

\oint_{\partial{S}}\vec{E}\cdot d\vec{l} = -\frac{\partial{\Phi_{B}}}{\partial{t}}

\oint_{\partial{S}}\vec{E}\cdot d\vec{l} = \mu_{0}I + \mu_{0}\epsilon_{0}\frac{\partial{\Phi_{E}}}{\partial{t}}

Technically, the first two integrals should be double integrals, but due to technical limitations, Wordpress LATEX cannot parse the equations with double integrals.

Maxwell’s Equations in Vacua

\nabla \cdot \vec{E} = 0

\nabla \cdot \vec{B} = 0

\nabla \times \vec{E} = -\frac{\partial\vec{B}}{\partial{t}}

\nabla \times \vec{B} = \mu_{0}\epsilon_{0}\frac{\partial\vec{E}}{\partial{t}}

The solution to this equation is the electromagnetic wave solution. This I will derive at a later date, and link back to here. The solution is a major motivator for relativity.

Two observers looking at a system that satisfy Maxwell’s equations can undergo a transformation from one observer to the other. This is exemplified by writing Maxwell’s equations in a manifestly covariant form.

Covariant form in Minkowski spacetime

Given a second rank tensor with indices alpha, beta, that range from 0-4, and following Einstein summation notation, we have:

F_{\alpha\beta} = \left( \begin{matrix}0 &  \frac{-E_x}{c} &  \frac{-E_y}{c} &  \frac{-E_z}{c} \\ \frac{E_x}{c} & 0 & B_z & -B_y \\ \frac{E_y}{c}  & -B_z & 0 & B_x \\ \frac{E_z}{c} & B_y & -B_x & 0 \end{matrix} \right)

F^{\mu\nu} = \eta^{\mu\alpha}F_{\alpha\beta}\eta^{\beta\nu} = \left( \begin{matrix} 0 &  \frac{E_x}{c} &  \frac{E_y}{c} &  \frac{E_z}{c} \\ \frac{-E_x}{c} & 0 & B_z & -B_y \\ \frac{-E_y}{c}  & -B_z & 0 & B_x \\ \frac{-E_z}{c} & B_y & -B_x & 0 \end{matrix} \right)

With these equations, we can write maxwell’s equations as

\mu_{0}J^\beta =\partial_\alpha F^{\alpha\beta}

0 = \partial_{\gamma}F_{\alpha\beta} + \partial_{\beta}F_{\gamma\alpha} + \partial_{\alpha}F_{\beta\gamma}

This is equivalent to the much more compact 0 = \epsilon^{\delta\alpha\beta\gamma}\partial_{\alpha}F_{\beta\gamma}, where \epsilon^{\delta\alpha\beta\gamma} is the Levi-Civita symbol, and \partial_\alpha = \frac{\partial}{\partial x^\alpha}

Maxwell’s equations in curved spacetime

\frac{4\pi}{c}j^\beta = \partial_{\alpha}F^{\alpha\beta} + \Gamma^{\alpha}_{\mu\alpha}F^{\mu\beta} + \Gamma^{\beta}_{\mu\alpha}F^{\alpha\mu}

0 = \partial_{\gamma}F_{\alpha\beta} + \partial_{\beta}F_{\gamma\alpha} + \partial_{\alpha}F_{\beta\gamma}

These equations are also written as:

F_{\alpha\beta} = \partial_{\alpha}A_\beta - \partial_{\beta}A_\alpha

D^{\mu\nu} = \frac{1}{\mu_0}g^{\mu\alpha}F_{\alpha\beta}g^{\beta\nu}\sqrt{-g}

J^\mu = \partial_{\nu}D^{\nu\mu}

f_\mu = F_{\mu\nu}J^\nu

Here, f_\mu is the density of Lorentz force, g^{\alpha\beta} is the reciprocal of the metric tensor g_{\alpha\beta}, and g is the determinant of the metric tensor. Notice that A_\alpha and F_{\alpha\beta} are (ordinary) tensors while D^{\mu\nu} , J^\mu, and f_\mu are tensor densities of weight +1.



June 17th, 2009

Iter Fusion

The BBC has a report on the Iter, the experimental international fusion reactor, located in southern France.

What is iter?

Iter is the international fusion reactor being built in France. It is 59 meters tall, weighs 23,000 tons, and is designed to produce 500 megawatts of power for every 50 megawatts put in. Iter has a fusion containment chamber of 850 cubic meters, a massive amount compared to the 100 m3 of current reactors.

Read about iter at their webpage.

How fusion works

A fusion reaction is a quantum mechanical process that can to bring two or more atoms close enough together so that the atoms can tunnel into one another such that the strong nuclear force in their nuclei will pull them together into one larger atom. When the two nuclei fuse, they will generally form a single nucleus with a slightly smaller mass than the sum of their original masses. The difference in mass is released as energy according to the mass-energy equivalence formula E = mc^{2}.

The easiest way to supply energy to allow the quantum tunnelling to overcome the electrostatic force is to heat the atoms, which has the side effect of stripping the electrons from the atoms and leaving them in a fluid known as a plasma. The energy, and thus, the temperatures required to provide the nuclei with enough energy to overcome their repulsion is a function of the charge, so hydrogen reacts at the lowest temperature.



Problems with Iter

Iter is a tokamak reactor, and as such it has several great technical hurdles to overcome before fusion becomes available. The protons and electrons in the plasma tend to recombine and become electrically neutral. These atoms then leak out of the magnetic confinement area and slam into the walls of the confinement vessel, damaging them.

Neutron bombardment will make the walls of the reactor radioactive. This poses a health risk to workers at iter. Neutron fluxes will also damage the superconductive coils that make the tokamak work.

Tritium is also radioactive. With a half life of 12.33 years, it decays quickly and becomes useless for fusion.

Iter requires massive amounts of power to generate the magnetic fields required to hold the plasma. Currently, the power required for nuclear fusion is greater then the power the fusion outputs. It is expected that the massive size of iter will help alleviate this problem.

Despite all these issues, it is expected that iter is a step forward towards viable commercial nuclear fusion. I hope that the day of fusion is dawning upon humanity soon.

June 12th, 2009

Semiclassical instability of dynamical warp drives

Warp speed

Warp drives are a unique feature of General Relativity. They allow us to go faster then the speed of light by moving spacetime itself at FTL speeds, while pinning the ship inside the spacetime region.

The best way to do this is by pulling up an Alcubierre drive generator, gathering enough dark energy to power it, and piling the dark energy around your ship until you take off. Note that you need dark energy, not dark matter.

However, This paper indicates that by building the drive up from initially flat spacetime will create an influx of particles via Hawking radiation; enough particles to fry anyone inside the drive.

Basically they look at the expanding spacetime and watch it blow up, playing with the quantum foam, and watching that explode into thermal Hawking radiation as well. Since the radiation is thermal, it carries no information, so the second law of thermodynamics still holds.



Since our universes spacetime is non-hyperbolic, creating the warp drive in curved space will only force us to expend more energy straightening spacetime into a flat configuration to morph it into the Alcubierre configuration.

June 12th, 2009

More math tricks

I once blogged about a bunch of quick division tricks, and it seems that post was a fairly big hit, with that page alone getting tens of hits. :p

So, I have decided to add a page with lots of little quick tricks that are useful in basic mathematics.

Triangles

To find the measure of any angle in a right triangle, we can just use sine, cosine, and tangent. Sine is Opposite/Hypotenuse, Cosine is Adjacent/Hypotenuse, Tangent is Opposite/Adjacent. Taking the bold, that forms the (bad) mnemonic soh cah toa. These three horrid little words have gotten me through more math crunches then I care to admit.

Multiply up to 20×20 in your head.

Take your two numbers, a1.a2 and b1.b2 and place the larger one above the smaller number.

Add a1.a2 + b2, then add a zero to the end of the new number.
Now multiply a2*b2, then add it to our new number.

Example

15×13

Add 15 + 3, then slap on a zero, to get 180.

Multiply 5*3 to get 15, then add it to 180 to get 195.

Multiply by 11.

Take the other number, say 52, and add the two digits together. 5+2=7. Stuff the number between the 5 and 2 to get 572. Thus, 52×11 is 572.

Multiply by 5

Divide the other number by two, then add a zero to the end.

Example

40*5

Divide 40 by 2 to get 20, then add a zero to the end to get 200.

Your Ad Here