text:
Serial Programming/RS-232 Connections

Introduction
RS-232 is a standard for serial data communication between computing equipment. This standard dates back to 1962 but has been substantially revised over the years to accommodate changes to communications technology. At a minimum, an RS-232 connection may consist of a single wire connected between two pieces of equipment. The simplest connection in common usage contains three wires: transmit (tx), receive (rx), and ground (gnd). However, a fully implemented connection can contain as many as 25 wires. Early RS-232 connections were commonly used to connect terminal equipment to modems, so these topics are often intertwined.

Data Terminal/Communications Equipment
In the world of serial communications, there are two different kinds of equipment:

 * DTE - Data Terminal Equipment
 * DCE - Data Communications Equipment

Straight Serial Connections
In practice, the distinction between Data Terminal Equipment (DTE) and Data Communications Equipment (DCE) is simply a matter of function. This is an instance where the subjects of modems and serial communication equipment have been mixed together. Here, the modem can be thought of as the DCE and the terminal that faces a user is the DTE. Years ago, when the use of timeshare computing systems was common, the user would dial a telephone, place the telephone's handset against an acoustical modem, and that modem would be connected to a simple dumb terminal with an RS-232 cable. The typical connection speed was usually 50 baud or 110 baud, though very fast connections could reach 300 baud. As a side note, when the very first IMPs (Interconnection Message Processors) that formed the first nodes/routers of ARPAnet (the ancient predecessor of the Internet), this was exactly the connection system they were using. This later gave way to other communication systems, but this was the beginning of the Internet.

In a more modern setting, imagine a piece of equipment in a very dangerous place, like in a steel processing mill that measures the temperature of the rollers or other steel processing equipment. This would also be a form of what we now refer to as a piece of "Data Communication Equipment" that we would also want to be able to control remotely. The PC that is used in a control room of the mill would be the Data Terminal Equipment. There are many other similar kinds of devices, and RS-232 connections can be found on all kinds of equipment.

The reason this is called a "straight" connection is because when the cabling is put together, each wire on each end of the connection is connected to the same pin.

Null Modems
Often you don't always want to connect a piece of equipment to a computer, but you would also like to connect two computers together. Unfortunately, when connecting two computers with a "straight" serial connection, the two computers are fighting each other on the same wires.

One way to make this work is to connect the two computers to each other with a pair of modems. As explained earlier, this is a very common task, and in the 1980's and early 1990's it was common to have "Bulletin Board Systems" (BBS) where computers would call each other up with modems and exchange all sorts of information.

Now imagine if these two computers are in the very same room. Instead of going through the physical modems, they go through a "null modem", or a modem that really doesn't exist. In order to make this work you have to "cross" some of the wires so when you transmit some information on one end, the other computer is able to detect and receive that same information.

In addition to simply allowing a computer to communicate and transmit data to another computer, a null modem connection can be used to "simulate" the behavior of DCE equipment. This will be particularly important later on with some of the discussion in this series of articles, where you can experiment with writing some of your own serial communication software. In my own experience, I've had to write these "emulators" in many instances, either because the equipment that I was trying to communicate with wasn't finished, or it was difficult to obtain a sample of that equipment and all that I had available to me was the communication protocol specification.

Loopback Connectors
Sometimes instead of trying to communicate with another computer, you would like to be able to test the transmission equipment itself. One practical way of doing this is to add a "loopback" connector to the terminal device, like a PC with a serial data connection. This connector has no cable attached, but loops the transmit lines to the receive lines. By doing this, you can simulate both the transmission and receiving of data. Generally speaking, this is only done for actually testing the equipment, but can be used for testing software components as well. When this sort of connector is used, you will receive every byte that you transmit. If you separate out the transmission subroutines from the data capture subroutines, it can provide a controlled system for testing your application.

General
When it starts to get very difficult to examine the serial data being transmitted by the equipment, sometimes it is nice to be able to take a "snapshot" of the information being transmitted. This is done with a protocol analyzer of one kind or another.

What is done is a modification of the cabling that allows for a third computer to be able to simply read the data as it is being transmitted. Sometimes the communication protocol can get so complicated that you need to see the whole exchange, and it needs to be examined in "real-time" rather than going through some sort of software debugger. Another purpose of this is to examine the data exchange for purposes of doing some reverse engineering if you are trying to discover how a piece of equipment works. Often, despite written specifications, the actual implementation of what is occurring when transmitting data can be quite a bit different than what was originally planned. Basically, this is a powerful tool for development of serial communications protocols and software, and should not be ignored.

There are common ways to connect a protocol analyzer, which are discussed in the following.

One of the most convenient tool to monitor and analyze serial port data is RS232 Protocol Analyzer. This software allows to intercept all serial control codes and record detailed information about them. The data captured can be viewed in all 4 different views simultaneously that is, table, line, dump or terminal mode with each display providing a unique way of representing RS232 analyzer captured data.

Y "Cable"
A Y "Cable" is not just some cable, but also contains electronics - assuming it is not a low quality cable. It is supposed to be placed in between a serial line and it mirrors all signals on a third connector. This third connector can then be connected to a protocol analyzer (e.g. a PC with some display software):

+-+ serial  +-+  serial  +-+ | DTE |--| Y Cable |--| DCE | +-+         +-+          +-+                       |                       |                  +--+                  | Analyzer | +--+

It is recommended not to use a passive Y cable. Such a cable overloads the transmitters at the DTE and DCE, which might result in the destruction of the transmitters. The RS-233 standard requires that transmitters are short-circuit safe. However, modern, highly integrated equipment might no longer be compliant to that particular aspect of the standard.

Often, the line going to the analyzer is also just a serial line, and the analyzer is a PC with a serial interface and some display software. The disadvantage of such a simple Y cable solutions is that it only supports half-duplex communication. That is, only one site (DTE or DCE) can talk at any time. The reason for this is that the two TX lines from the DTE and DCE are combined into one TX line going to the analyzer. If the DTE and the DCE both send at the same time, their signals get mixed up on the third line going to the analyzer, and the analyzer probably doesn't see any decode-able signal at all.

See http://www.mmvisual.de/fbintermdspy.htm for an example of some simple circuitry for a Y cable.

More advanced Y cable solutions provide the TX data from the DTE and DCE separately to the analyzer. Such analyzers are capable of displaying full-duplex communication. Advanced professional systems not only display the decoded digital information, but also monitor the analog signal levels and timing.

Man-in-the-Middle
In this scenario the analyzer sits in the middle between the DTE and DCE. It is basically some device (e.g. a PC) with two serial interfaces. The analyzer mirrors each signal from one site to the other site, and also displays the traffic.

+-+ serial  +--+  serial  +-+ | DTE |--| Analyzer |--| DCE | +-+         +--+          +-+

In principle, a simple version of such an analyzer can be built with any PC with two serial interfaces. All that is needed is some software, which is not too difficult to write. Such a device will, however, lack a convenient feature. Professional analyzers are able to auto-sense the speed of the serial communication. A home made solution needs to be configured to match the speed of the serial communication. Professional devices are also optimized to ensure minimal delay in the circuitry. Also, a simple homegrown, PC-based analyzer can't be used to analyze faults due to signal voltage level problems. Nevertheless, any kind of protocol analyzer is much better than nothing at all. Even the most simple analyzer is very useful.

Others
See Setting up a Development Environment (for modem development) for some more information.

Breakout Box
An RS232 breakout box (a BOB) is a rather nifty piece of hardware which usually combines a number of functions into one. It basically consist of two RS232 connectors, and a patch field (or switches) which allows to change the wiring between the connectors. A patch field and small pieces of wires are preferable over (DIP) switches alone, since the patch field allows access to the signals for other purposes, too.

A breakout box is very useful if the pinout (DTE/DCE) of a particular device is not known. The patch field allows to quickly change the wiring from a straight connection to a null modem connection, or to set up a loopback connection.

Since the patch field provides access to all signals it also allows to use the breakout box to connect a protocol analyzer or an oscilloscope. Better breakout boxes also provide some signal level information on their own, by having LEDs who inform about the signal voltage. This information is useful when trying to identify an unknown pinout. High-end BOBs contain circuitry to measure ground potential difference and pulse traps circuitry to find signal glitches.

Commercial breakout boxes are available in many varieties. It is also possible to build a useful BOB from a handful of simple parts on a circuit board. The patch field can be made from DIL IC sockets, and the wiring of the LEDs is simple if 2-pin dual-color LEDs are used (3-pin LEDs will not work). Each signal line should be connected via such an LED and a 680 Ohm resistor in serial to GND (Signal Ground). The home-made breakout-box is completed with a couple of RS232 connectors, possibly also one to attach a protocol analyzer and some simple metal or plastic case.

Character Sequence Generator
Another nifty piece of hardware and/or software which is useful for developing and testing serial applications and equipment is a character sequence generator. Such a generator produces a repeated sequence of serial line data. For example such a generator might repeat the famous "The quick brown fox ..." sentence in an an endless loop. Another common test sequence is the generation of all 8-bit codes from 0x00 to 0xFF in a loop. Such a loop contains all 7-bit ASCII and 8-bit ISO Latin 1 characters, plus the first 32 non-printable control characters and can e.g. reveal decoding errors or transmission errors. Also very common is a modem test sequence, using generic modem commands (Serial Programming:Modems and AT Commands) to build up a modem connection, send some data and tear the modem connection down in a loop.

Commercial hardware character generators provide a heap of additional features, often combined with a protocol analyzer. As such they are rather expensive. However, just like with a BOB, it is possible to build a useful DIY character sequence generator for small cash. This can either happen with software on a normal computer (some simple endless software loop sending the same data again and again to a serial interface), or with a few pieces of cheap electronic components. Some small stand-alone hardware is often more convenient in the field and in development for quick tests than e.g. a PC or laptop with some software.

A simple classic hardware character generator basically consists of a baud-rate generator, a UART (Serial Programming:8250 UART Programming), an (E)EPROM, a binary counter and a line driver (Serial Programming:MAX232 Driver Receiver). Typically, each of these components is a simple single IC. The (E)EPROM is supposed to contain the character sequence(s). The baud-rate generator drives the UART and the binary counter. The binary counter drives the address lines of the (E)EPROM. The result is that the character sequence is produced at the data lines of the (E)EPROM. These data lines are feed into the UARTs input. The UARTs output is connected to the serial line driver. All this can be easily fitted on a small prototype board in a simple case.

A more modern hardware character generator can be build around one of these small micro controllers (e.g. Atmel AVR). This is particularly easy, since these micro controllers already contain serial interfaces, and just require a little bit of serial programming - which is the topic of this book.

Connection Types
If you wanted to do a general RS-232 connection, you could take a bunch of long wires and solder them directly to the electronic circuits of the equipment you are using, but this tends to make a big mess and often those solder connections tend to break and other problems can develop. To deal with these issues, and to make it easier to setup or take down equipment, some standard connectors have been developed that are commonly found on most equipment using the RS-232 standards.

These connectors come in two forms: A male and a female connector. The female connector has holes that allow the pins on the male end to be inserted into the connector.

EIA/TIA 574: DE9
This is a female DE9 (incorrectly known as "DB-9") connector (properly known as DE9F):

The female DE-9 connector is typically used as the "plug" that goes into a typical PC. If you see one of these on the back of your computer, it is likely not to be used for serial communication, but rather for things like early VGA or CGA monitors (not SVGA) or for some special control/joystick equipment.

And this is a male "DE-9" connector (properly known as DE9M):

This is the connector that you are more likely to see for serial communications on a "generic" PC. Often you will see two of them side by side (for COM1 and COM2). Special equipment that you might communicate with would have either connector, or even one of the DB-25 connectors listed below.

RS-232C: DB-25
This is a female DB-25 connector (also known as DB25S):

This DB25S is what you normally find on an IBM compatible PC used as the parallel (printer) port. It is also on the computer end of a modem cable in older PCs that have 25 pin serial port connectors. This connector type is also used frequently for equipment that conforms to RS-232 serial data communication as well, so don't always assume if you see one of these connectors that it is always parallel. When the original RS-232 specification was written, this was the kind of connector that was intended, but because many of the pins were seldom if ever used, IBM PC compatible serial ports were later switched to the DE-9 DE9S connectors carrying all the required signals as on the DB connectors in the original IBM-PC. (Yes, this is comparatively recent equipment for this standard).

This is a male DB-25P connector (also known as DB25P):

Male DB-25 connectors are usually used on one end of a PC printer cable for parallel data communication, which is beyond the scope of this series of articles. The DB25P is also used on the modem end of an external modem cable. You should be aware that this connector is also used for serial communications on many different types of equipment, using many different types of communications protocols. In fact, if you have a random piece of equipment that you are trying to see how it works, you can presume that it is a piece of serial equipment. Hacking random connectors is also beyond the scope of this document, but it can be an interesting hobby by itself.

mini-stereo plug connector
This is a male mini-stereo plug connector:

Some digital cameras and calculators come with a cable that has a mini-stereo plug connector on the end the plugs into the camera, and a DE-9 connector on the end that plugs into the PC.

It is a poor connector, as it short circuits segments while being plugged/unplugged.

The "PicAXE" systems use
 * 1: base ring: ground (pin 5 of DE9)
 * 2: middle ring: serial output from PicAXE to serial input of PC (pin 2 of DE9)
 * 3: tip of pin: serial output of PC to serial input of PicAXE (pin 3 of DE9)

The "LANC" systems often use a 2.5 mm stereo jack:
 * base ring: ground
 * middle ring: +5 to +8 VDC from the camera
 * tip: normally pulled high with a resistor to +5 V (idle; logical 1); pulled low (start bit and logical 0) to send commands or status. (open collector). Generally the remote control sends the first 2 byte command. The camera replies with 6 status bytes.

LANC uses 9600 bit/s serial.

RS-232D: RS232 on RJ45
RS-232D defines a standard connector much smaller than a DE-9 plug. .

(RS-232 on a RJ45 modular jack is also known as "EIA/TIA - 561")

RS232 on RJ11
Is there a standard for connecting the TX, RX, GND of RS-232 to the 4 pins of a RJ11 connector ?
 * Luhan Monat uses DE9-5 ---> RJ11-1; DE9-3 ---> RJ11-2; DE9-2 ---> RJ11-3. (RJ11-2 and RJ11-3 are the "inner pair").
 * Paul Campbell says "I wired the GND to the yellow line, TXD to the black line and RXD to the red line."
 * Russell McMahon mentions several different "standards" for wiring RS-232 to the 4 pins of a RJ11 connector or the 8 pins of a RJ45 connector.

Wiring Pins Explained
The wiring of RS-232 devices involves first identifying the actual pins that are being used.

Please note also that in the "PC COMx Port context" end of things some signals are 'inputs' while others are 'outputs' while in the "Modem context" those same signal names referred to now become as 'outputs' where they were just before 'inputs' and vice versa. That is where much confusion has arisen from over the years, as the 'Input' or 'Output' -sense- nature is not noted in most diagrams on the subject in general, yet in the real world two 'Out' pins seldom can ever work in harmony in RS-232 related ±[3–10] V stuff where the range from -3 V to +3 V is not a true high or low, except to possibly burden drivers towards their undesired burnout.

Here is how a female DE-9 connector is numbered (Note, the connector on a computer is usually a male connector, so it is mirrored compared to the following image):

If the numbers are hard to read, it starts at the top-right corner as "1", and goes left until the end of the row and then starts again as pin 6 on the next row until you get to pin 9 on the bottom-left pin. "Top" is defined as the row with 5 pins.

Here are what each pin is usually defined as on the PC COMx end of things:

One thing to keep in mind when discussing these pins and their meaning, is that they are very closely tied together with modems and modem protocols.

Whenever interconnecting any serial ports it will be well to note that whatever the case, it should always follow that only one should ever be tied to one or more generally speaking. Further, be it noted that signal names at the COMx end will generally be opposite of the - -sense- at the modem end of things, even though carrying the same mnemonic names.

Often you don't have a modem attached in the loop, but you still treat the equipment as if it were a modem on a theoretical level. At least such that you minimally have an going to every in some manner, with no two in conflict or without any 'floating' tied to no at all.

The following are more formal explanations regarding each signal function in the general sense of its use:

DCD (Data Carrier Detect)
This is a signal to indicate from the communications equipment (DCE) that the phone line is still "connected" and receiving a carrier signal from the modem at the other end. Presumably well-written software or serial equipment could detect from this logic state when the telephone has been "hung up" on the other end. Null-modems often tie DCD to DTR at each end since there is no carrier signal involved.

RX (Receive Data)
Input to receive the data from another transmitter.

TX (Transmit Data)
The reverse of RX, this is where the terminal equipment (DTE) is transmitting serial data, using the same format and protocol that the receiver is expecting. More on the exact protocol further below. Like RX, think along the lines of "Terminal Transmit" when designing equipment that will be using this pin.

DTR (Data Terminal Ready)
Basically a signal from the DTE that says "Hello!, I'm ready if you are". This is a general indicator to the DCE that the terminal is ready to start sending and receiving data. If there is some initialization that needs to happen in the communications equipment, this is a way for the terminal equipment to "boot" the receiving equipment. In a null modem setup this signal is often connected to DCD, so the device signals itself that an (imaginary) carrier has been detected, indication that the transmission line is up.

GND (Signal Ground)
This is an interesting pin to look at. What it does is try to make a common "ground" reference between the equipment that is being connected to compare the voltages for the other signals. Normally this is a good thing, because sometimes different pieces of equipment have different power supplies and are some distance away. The not so pleasant thing about this wire is that it usually is a physical piece of copper that can conduct electricity that is not normally supposed to go down the wire, like a short-circuit or worse yet a bolt of lightning (it happens far more often that you would normally think for this sort of equipment). That can fry both the DCE as well as the DTE. Things like fiber converters and ground isolators can help prevent this from happening, but can still be something to worry about. Over short distances this is generally not a problem.

DSR (Data Set Ready)
This is the counterpart to DTR with the communications equipment (or computer peripheral on the serial line). When the DTR is sent as a signal, the communications equipment should change this signal to logic "1" to indicate that it is ready to communicate as well. If the DCE goes through a "boot" sequence when the DTR gets signaled, it should not signal DSR until it is complete. But many connectors "hard wire" this pin to be directly connected to the DTR pin at each end to reduce the number of wires needed in the cable. This can be useful for connecting devices using existing telephone wires, but prevents applications from using the DTR and DSR for handshaking.

RTS (Request To Send)
Setting the RTS signal to logic "1" indicates to the DCE that the DTE wants to send it data. Resetting the RTS signal to logic "0" indicates to the DCE that the DTE has no more data to send.

CTS (Clear To Send)
This is the response signal from the DCE regarding if the terminal equipment should be transmitting any data. When this signal is at logical "1", the terminal is "permitted" to transmit data. Like the DTR/DSR pins, this one can be directly connected to the RTS pin to reduce the number of wires needed, but this eliminates the possibility of hardware flow control. Some software ignores this pin and the RTS pin, so other flow control systems are also used. That will be explained when we get to actual software.

RI (Ring Indicator)
Again, thinking back to a telephone modem, this is a signal that indicates that the telephone is "ringing". Generally, even on a real telephone modem, this is only occasionally set to -15 V for the signal. Basically, when you would normally be hearing a "ring" on your telephone, this pin would be signaled. On Null-modems, often this wire isn't even connected to anything. If you really are connected to a real modem, this does have some strong uses, although there are other ways to have the terminal equipment (like a PC connected to an external modem) be informed that there are ways to communicate this information through the data pins as well. This will be covered lightly in the software section.

Other RS-232 Pins
There are other pins that the DB-25 has implemented that the DE-9 doesn't normally use, such as a secondary transmit and receive pin, Secondary CTS/RTS for those alternate pins, a -15 V signal for power, a clock, and a couple of other good ideas as well. The problem with implementing all of these pins is that you also need to run separate wires, and a full set of DB-25 connectors would also mean having 25 physical wires going the full distance between the DTE and DCE. If this is more than a foot or so, it gets to be a big hassle, particularly if you are going through walls or in a more permanent setting. If the wrong wire gets clipped in the bundle, the whole thing must be restrung again, or you must go through wire testing like the old-fashioned telephone linemen used to have to do when fixing a phone distribution box. Often only three physical copper lines are used to connect the DTE to DCE, and that is simply RX, TX, and GND. The rest can be easily "faked" on the connector end in a manner sufficient for most software and hardware applications.

Baud Rates Explained
Baud and BPS (Bits Per Second) are usually not the same thing, although they are often used interchangeably, particularly in marketing literature. There are several ways to determine what the actual data rate of a particular piece of equipment is, but in popular marketing literature, or even general reference texts, they will almost always refer to "Baud Rate", even if they are referring to bits per second.

Baud means the number of changes to the transmission media per second in a modulated signal. If each transmission event contains more than one bit of information, then Baud and BPS are not the same. E.g. if each event contains two bits (two bits modulated in an event), then the BPS of such a transmission would be twice as large as the Baud rate. This is not a theoretical case. Typical "high speed" modems use sophisticated modulation on the telephone line, where the bit rate and Baud rate differ significantly on the line. It is important to know this when you build measurement equipment, decoders (demodulators), encoders (modulators), and all sorts of transmission equipment for a particular protocol.

However, software developers typically like to ignore the difference of bit rate and baud rate, because a bit can either have the value true or false - an "event" (a bit) always only has two possible states. They have no basic unit which can e.g. hold four different states. In other words, on the software side the modulation has already been flattened by the demodulator. If a modulation was used which can e.g. transmit 8 bits in an event, the software developer sees them already as a series of 8 consecutive bits, each either true or false. The demodulator took care of that. When it got an event it turned the single 8-bit event into eight single-bit events. Software developers don't see the original single entity with 256 different states (voltages, phases). Since the modulation has been flattened they don't experience the difference between Baud rate and bit rate any more. This is not the fault of the people who defined a Baud or a BPS. It is just a (welcome) limitation of digital computer hardware.

Baud is actually a shortened term named in honor of Émile Baudot, a French inventor of early teleprinter machines that replaced the telegraph key using Morse Code. Basically two typewriters that could be connected to each other with some wires. He came up with some of the first digital character encoding schemes, and the character codes were transmitted with a serial data connection. Keep in mind this was being done largely before computers were invented. Indeed, some of these early teleprinter devices were connected to the very first computers like the ENIAC or UNIVAC, simply because they were relatively cheap and mass-produced at that point.

In order for serial data communication to happen, you need to agree on a clock signal, or baud rate, in order to get everything to be both transmitted and received properly. This is where the language purists get into it, because it is this clock signal that actually drives the "baud rate". Let's start more at the beginning with Émile Baudot's teleprinters to explain baud rate.

Émile's early teleprinters used 5 data bits and 1 stop bit to transmit a character. We will go onto formatting issues in a second, but what is important is that six signals are sent through a wire in some fashion that would indicate that a character is transmitted. Typically the equipment was designed to run at 50 baud, or in other words the equipment would transmit or receive a "bit" of data 50 times per second. Not coincidentally, French power systems also ran on an alternating current system of 50 Hz, so this was an easy thing to grab to determine when a new character should be transmitted.

Teleprinters evolved, and eventually you have Western Union sending teleprinter "cablegrams" all around the world. If you hear of a TELEX number, this is the relic of this system, which is still in use at the present time, even with the Internet. By rapidly glossing over a whole bunch of interesting history, you end up with the United States Department of Justice (DOJ) in a lawsuit with AT&T. Mind you this was an earlier anti-trust lawsuit prior to the famous/infamous 1982 settlement. The reason this is important is because the DOJ insisted that Western Union got all of the digital business (cable grams... and unfortunately this got to be read as computer equipment as well), and AT&T got modulated frequencies, or in other words, you could talk to your mother on Mother's Day on their equipment. When computers were being built in the 1950s, people wanted some way to connect different pieces of computer equipment together to "talk" to each other. This finally resulted in the RS-232 standard that we are discussing on this page.

While Western Union was permitted to carry digital traffic, often the connections weren't in or near computer centers. At this time AT&T found a loophole in the anti-trust settlement that could help get them into the business of being a "carrier" of computer data. They were also offering to transmit computer data at rates considerably cheaper than Western Union was going to charge. Hence, the modem was born.

Modems Explained
The long description of a modem is a "Modulator/Demodulator", and this description is important. Since AT&T could only carry "tones", like music from a radio network or the voice of your mother, they created a device that would electronically create "music" or "tones" that could be carried on their network. They would then take a computer "1" or "0" and "modulate" the bit to a frequency, like say 2600 Hz. (The exact tones varied based on baud rate and other factors, but there were exact frequency specs here.) A matching device would be able to look for that "note" or "tone" in the "music" and be able to convert that back to a computer "1" or "0", or in other words, demodulate the music. Since all you and your buddy on each end of the telephone are only playing music to each other, it was legal for AT&T to have that music on their network. That only computers could possibly understand this music is besides the point, and the DOJ turned a blind eye on the whole practice, despite objections from Western Union.

The original modems you could rent were AT&T Bell 103 modems. These were clunky boxes about the size of a shoe box that had a bunch of switches on the outside and an RS-232 cable that connected to the computer equipment you were using. These boxes were designed for the old-fashioned handset telephones and had pieces of rubber that would go around the "speaker" and "mic" portion of the telephone (no direct copper connection to the telephone equipment back then). If you wanted to dial the telephone, you had to use the rotary dial on the phone itself... the computer didn't have access to that sort of equipment. Keep in mind that the FCC regulated just about everything that happened with phone equipment, and AT&T owned everything related to telephones. You even had to "rent" the modem from AT&T, and that rental charge was on your monthly phone bill.

The Bell 103 was originally 110 baud, although it eventually had a switch to "move up" to 220 baud. 300 baud modems were also fairly common throughout the 1960's and 1970's. Keep in mind that AT&T (or your local phone company) was the only company you could even rent a modem from, whether you wanted one or not. By 1982, modems were so commonly used and the POTS telephone network so widespread that this same system of sending "music" over the telephone has been preserved, even though the legal reasons for doing it are no longer valid. With the advent of ISDN and DSL lines, this is no longer the case and the phone companies are now sending pure digital signals instead. This is also why DSL lines can carry much more data than an ordinary phone line, even though it is the same pair of copper wires going into your home.

When modems started going to very high speeds, they hit a brick wall of sorts. It was decided back in the 1950's that telephone equipment would only have to carry tone signals going to about 10kHz. For normal voice conversations this is sufficient, and you can even tell the difference between a man and a woman on the telephone. The problem comes in that this means the highest normal "baud rate" that you can send over a home telephone network is about 9600 baud, usually about 4800 baud, because the telephone equipment itself is going to be dropping "bits" as you switch from one tone to another. Without going into the heavy math, you need to have at least one full "sound wave" in order to be able to distinguish one tone or note from another. Modem manufacturers did think of something else that could be done to overcome this limitation, however. Instead of just sending one tone at a time, you could play a whole "chord", or several distinct tones at the same time. Finally back to baud vs. bits per second. With higher speeds, instead of simply sending only one bit, you are sending two or as many as sixteen bits at the same time with varying "chords" of "music". This is how you get a 56K BPS modem, even though it is still only transmitting at 9600 baud.

More about modems in Serial Programming:Modems and AT Commands.

Signal Bits
There are four sets of transmission bits that are used in the RS-232 standard. The positioning of these bits in the RS-232 data stream is all that distinguishes one bit from the other. This is also where serial communication really hits the "metal", because each bit follows in a sequence, or in a serial fashion. All of the other wires, pins, baud rate, and everything else is to make sure that these bits can be understood. Keep in mind that at this point the entire protocol is based on the transmission of a single character. Multiple characters can be sent, but they are a sequence of single character transmission events. How the characters relate is based on what the software does with the data on the next protocol "layer".

Start Bit
When a transmission line is not sending anything, it remains in a logical state of "1", or -15 V on the wire. When you want to send a character, you start by changing the voltage to +15 V, indicating a logical "0" state. Each subsequent bit is based on the baud rate that is established for communication between each device. This bit signals that the receiving device should start scanning for subsequent bits to form the character.

Data Bits
This is the primary purpose of serial communications, where the data actually gets sent. The number of bits here can vary quite a bit, although in current practice the number of bits typically transmitted is eight bits. Originally this was five bits, which was all that the early teleprinters really used to make the letters of the Alphabet and a few special characters. This has implications for Internet protocols as well, because early e-mail systems transmitted with only seven bits when they were connected over some RS-232 links. This worked because the early character encoding schemes, mainly ASCII, only used seven bits to encode all characters commonly used for the English language. Because computer components work best on powers of 2 (2,4,8,16,32, etc.), eight bits became more commonly used for data storage of individual characters. Unicode and other coding schemes have moved this concept forward for languages other than English, but eight bits still is a very common unit for transmitting data, and the most common setting for RS-232 devices today.

The least significant bit (LSB) is transmitted first in this sequence of bits to form a character.

Parity Bit
To help perform a limited error check on the characters being transmitted, the parity bit has been introduced. Parity can detect some transmission errors but not correct. The value of the parity bit depends on the number of bits set to "1" in the string of data bits.

There are four different kinds of parity configuration to consider:

Odd Parity
When the sum of bits ends up coming up with an odd number (like the sequence 01110101), this bit will be set to a logical state of "0".

Even Parity
This uses the formula of trying to determine if there are an even number of bits set to "1". In this regard, it is the exact opposite state of the Odd Parity. For e.g., for a frame with seven bits that has an odd number of ones, the parity bit will be set to one. So essentially, the entire byte, including parity must have an even number of ones for even parity.

Mark Parity
Using this concept, the transmission protocol is essentially ignoring the parity bit entirely. Instead, the transmission configuration is sending a logical "1" at the point that a parity bit should be sent, regardless of if the sequence should have an odd or even count. This configuration mode is useful for equipment that may want to be testing parity checking software or firmware in the receiving equipment.

Space Parity
The opposite of Mark parity, this sends a logical "0" for the parity checksum. Again, very useful for equipment diagnostics.

Parity None
This isn't really a parity formula, but rather an acknowledgment that parity really doesn't work, so the equipment doesn't even check for it. This means the parity bit isn't even used. This can cause, in some circumstances, a slight increase in the total data throughput. More on that below.

Stop Bits
This really isn't a bit at all, but an agreement that once the character is sent that the transmitting equipment will return to a logical "1" state. The RS-232 specification requires this logical state of "1" to remain for at least one whole clock cycle, indicating that the character transmission is complete. Sometimes the protocol will specify two stop bits. One reason that this might be done is because the clock frequencies being used by the equipment might have slightly different timing, and over the course of hundreds or thousands of characters being transmitted the difference between two clocks on the two different pieces of equipment will cause the expected bits to be shifted slightly, causing errors. By having two stop bits the transmission is slightly slower, but the clock signals between the two pieces of equipment can be coordinated better. Equipment expecting one stop bit can accept data transmitted by equipment sending two stop bits. It won't work the other way around, however. This is something to try if you are having problems trying to get two pieces of equipment to communicate at a given baud rate, to add the second stop bit to the transmitter.

Data Transmission Rates
We got into a discussion of baud rate vs. bits per second. Here is where baud as the number of bits being transmitted is still off, even if the nominal bits per second is also the same as the baud rate. By adding start bits, stop bits, and parity bits, that is going to add overhead to the transmission protocol. All digital transmission protocols have some sort of overhead on them, so this shouldn't be that much of a surprise. As we get more into data packets and other issues, the actual amount of data being transmitted will drop even further.

Keep in mind that if you are transmitting with 6 data bits, 2 Stop bits, and Even Parity, you are transmitting only six bits of data and four other bits of extra information. That means even with 9600 baud, you are only transmitting 5,760 bits of data per second. This really is a big difference, and that is still only raw bits once it gets through the actual serial communications channel. A more typical 8 data bits, 1 Stop Bit, No Parity will be a little bit better at 9600 baud, with eight bits of data and only two bits used for overhead. That gives a total throughput of 7,680 bits per second. A little bit better, but you can't simply presume that the baud rate indicates how much data is going to be transmitted.

Relationship of Baud Rate to Maximum Distance
There are physical limits to how far serial data communication can occur over a piece of wire. When you apply a voltage onto a wire it takes time for that voltage to traverse the wire, and there are other unstable conditions that happen when you send a "pulse" down the wire and change voltages too quickly. This problem is worse as wires become longer and the frequency (i.e. baud rate) increases. This distance can vary based on a number of factors, including the thickness of the wires involved, RF interference on the wires, quality of the wires during the manufacturing process, how well they were installed... e.g., are there any "kinks" in the wires that force it into a sharp bend, and finally the baud rate that you are transmitting the data.

This table presumes a fairly straight and uniform cable that is typical for most low-voltage applications (i.e., not a power circuit that uses 110 V to run your refrigerator, toaster, and television). Typically something like a CAT-5 cable (also used for local networks or phone lines) should be more than sufficient for this purpose.

The distance limitation can be mitigated. There are "short haul modems" that can extend this distance to several miles of cable. There are also telephone lines, or conventional modems, and other long-distance communications techniques. There are other ways to handle data in situations like this, and those signals can be converted to simple RS-232 data formats that a typical home computer can interpret. Distance still can be a limiting factor for communication, although when you are talking about distances like to Saturn for the Cassini mission, serial data communication has other issues involved than just data loss due to cable length. And yes, NASA/ESA is using serial data communication for transmitting those stunning images back to Earth.

External References

 * RS-232 wiring standards explained
 * RS-232 connection types explained
 * Wikipedia article on RS-232
 * RS-232 standards explained by HW-Server
 * Serial Pinouts (D25 and D9 Connectors) (also has more technical information about the UARTs used in PCs)
 * RS232 Connections, and wiring up serial device has several diagrams, including one showing how to let one PC monitor the serial communication between 2 other RS232 devices.
 * Lammert Bies, RS232 Specifications and standard Includes technical specs on RS-232 signals and more detailed information about parity checking.
 * Tronisoft's Printable ASCII Serial Port Crib Sheets
 * jSSC library (Java Simple Serial Connector). Work under Win32 and Win64

Other Serial Programming Articles
Typical RS232-Hardware Configuration

title: Serial Programming/RS-232 Connections


text:
User talk:65.6.23.59

User edited AASF Cheat Detection page just to add "SUCK ME".

Sigh...

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: User talk:65.6.23.59


text:
User talk:80.185.175.193

Please note capitalization in pages - the standard format is to only capitalize the first letters and proper nouns. However, you've done some great work on the vi book, keep it up :) Dysprosia 04:28, 19 Jun 2004 (UTC)

title: User talk:80.185.175.193


text:
Cookbook:Fruit Whip

| Dessert

Fruit mixture

 * ¾ cup white granulated sugar
 * 4 Tbsp cornstarch
 * 1 pinch each of salt
 * 1 pinch fine-ground ginger
 * 3 egg yolks
 * Juice of 1 small lime
 * 2 cups fruit nectar (peach, pear, apricot, or tropical fruits)

Whipped egg whites

 * 3 egg whites
 * 1 pinch salt
 * 1 pinch cream of tartar
 * 3 Tbsp white granulated sugar

Procedure

 * 1) In a saucepan, beat together the sugar, cornstarch, salt, ginger, yolks, and lime juice until pale and creamy.
 * 2) Beat in fruit nectar.
 * 3) Bring to a full boil over medium heat, stirring constantly, especially towards the end.
 * 4) Cool the pan in cold water.
 * 5) Beat egg whites with salt and cream of tartar, sprinkling in the tablespoons of sugar, to form soft peaks.
 * 6) When fruit mixture is lukewarm, gently fold in the whipped egg whites.
 * 7) Transfer the mousse into stemmed glasses, and chill in the fridge.

Notes, tips, and variations

 * This dessert is excellent half-frozen.
 * If pear nectar is used, try substituting one drop of peppermint oil for the ginger.

title: Cookbook:Fruit Whip


text:
Learning the vi Editor/Authors

This book has many authors, including the public: it is open for anyone and everybody to improve. Therefore, this is more properly a list of acknowledgements of contributors than a list of authors. Whoever we are, this is where we get to brag about our accomplishments in writing this book.

List of major contributors

 * Dysprosia (Contributions)
 * Martin Krischik Learning the vi Editor/Vim (Contributions)
 * N.N.(anonymous): The advanced/Power User/Extra Details part (Learning the vi Editor/Details) - whatever it is currently called.
 * Others (add your name and description if you made a major contribution)
 * Various anonymous persons

title: Learning the vi Editor/Authors


text:
Genealogy/China

Many Chinese families have extensive genealogical records, and in most cases there will be copies of these records at the local records division which is under the jurisdiction of the Public Security Bureau (i.e. the police). However, because the records people generally have a police/bureaucratic mindset, it is unlikely that you will get access to the records by going directly to them.

Instead, the easiest way to get access to these records is to go through the local overseas Chinese bureau of the particular village that you are interested in. Because overseas Chinese bureaus are specifically tasked with increasing links with overseas Chinese in the hopes of getting investment, they are usually extremely helpful and generally have the bureaucratic pull necessary to gain access to genealogical records.

The type of records that you will find will usually contain a family tree of male members, often going back several hundred years, with a paragraph of noteworthy accomplishments of the male members of a family going back several hundred years.

title: Genealogy/China


text:
General Relativity/Metric tensor

<General Relativity

Recall that a tensor is a linear function which can convert vectors into scalars. Recall also that a distance can be stated as a formula that converts vectors to a scalar. So can we express distance with tensors formulas? Yes, we can.

The first problem comes in, in that tensors are linear functions, but we have some squares in our distance formula. We can deal with this with a mathematical trick. Consider the formula for distance in normal three dimensional Euclidean space using cartesian coordinates:

$$\mathbf{d}s^2 = \mathbf{d}x^2 + \mathbf{d}y^2 + \mathbf{d}z^2$$

We can rewrite this as:

$$\mathbf{d}s^2 = \delta_{ij} \mathbf{d}x^i \mathbf{d}x^j$$

Now $$\delta_{ij}$$ is obviously a tensor. What type of tensor is it? Well it takes two contravariant vectors and turns them into a scalar $$ds^2$$. So it must be a covariant tensor of rank 2. $$\delta_{ij}$$ is called the Kronecker delta tensor, which is 1 whenever $$i = j$$ and 0 otherwise. In general, instead of components $$\delta_{ij}$$, we have $$g_{ij}$$ :

$$\mathbf{d}s^2 = g_{ij} \mathbf{d}x^i \mathbf{d}x^j$$

This leads us to a general metric tensor $$g_{ij}$$. As shown earlier, in Euclidean 3-space, $$ \left( g_{ij} \right)$$ is simply the Kronecker delta matrix.

And that is the equation of distances in Euclidean three space in tensor notation.

Now let's do special relativity using this notation:

$$\mathbf{d}s^2=g_{\mu \nu} \mathbf{d}x^\mu \mathbf{d}x^\nu $$

where the Greek letters just remind us that we are summing over four dimensional space time. Now in the case of special relativity $$g_{\mu\nu}$$ is zero for where $$\mu$$ and $$\nu$$ are different, +1 for the space indices 1,2,3 and $$-c^2$$ for the time index. We can call this special matrix $$\eta$$, giving us the formulas:

$$\mathbf{d}s^2=\eta_{\mu \nu} \mathbf{d}x^\mu \mathbf{d}x^\nu $$

In general, however, $$g_{ij}$$ will not be a constant. A simple example where we can see that is spherical coordinates, with the metric

$$\mathbf{d}s^2 = \mathbf{d}r^2 + r^2 \mathbf{d}\theta^2 + r^2 \sin^2\theta \mathbf{d}\phi^2$$

Here, $$x^1 = r$$, $$x^2 = \theta$$, $$x^3 = \phi$$, $$g_{11} = 1$$, $$g_{22} = r^2$$, $$g_{33} = r^2 \sin^2\theta$$, and $$g_{12} = g_{13} = g_{23} = 0$$.

Also, a metric may have off-diagonal terms, as in

$$\mathbf{d}s^2 = 2 \mathbf{d}x \mathbf{d}y$$

It is easy to see that $$g_{12} = 1$$ and $$g_{11} = g_{22} = 0$$.

title: General Relativity/Metric tensor


text:
User:Adorton

PHP Programming Manual
Currently working on sections in the PHP Basics chapter.

Summary

 * Wrote initial "Nuts and Bolts" section.
 * Wrote initial conditional structures section.
 * Made some minor revisions to main page.
 * Major update to Intermediate section; added structure, new sections and sub-sections.

title: User:Adorton


text:
User:Roadrunner~enwikibooks

Roadrunner is Joseph Wang []. See my blog at http://twofish.wordpress.com/

title: User:Roadrunner~enwikibooks


text:
Classical Mechanics/Introduction

Physics - Classical Mechanics

Up Next

Overview: What is classical mechanics
As a prelude to this course, let me describe what classical mechanics is about.

Classical mechanics is a part of physics that deals with the motion of point masses (very small things) and rigid bodies (large things that can rotate as a whole but cannot change their shape). This is very useful in practice, since many objects in real life can be approximately considered to be either point masses or rigid bodies in most situations.

Typical problems solved in classical mechanics are:

Of course, one can consider also much more complicated problems than these. For example:
 * To find the trajectory of a stone thrown into the air with known initial velocity. (The stone is considered to be a point mass.)
 * To predict the motion of a spacecraft approaching some planet, if its initial position and velocity far from the planet are known. (The spacecraft is considered to be a point mass.)
 * To find out how many revolutions per minute a disc will be executing if we know the strength of the engine driving the rotation. (The disc is considered to be a rigid body rotating as a whole.)
 * To find how much energy and how much time is needed to accelerate a small object to a given speed. (Point mass.)
 * To find the frequency of oscillations in a system of point masses connected by springs.
 * A light spinning top stands at an angle on the surface of a heavy cylinder that can roll along a horizontal plane without sliding. Determine the conditions that would allow the top to avoid falling off the cylinder. (Both the cylinder and the top are considered rigid bodies.)
 * A spacecraft launched from the Earth needs to reach the surface of Mars within a certain time. Predict the most appropriate time of year for this mission and determine the least amount of rocket fuel needed. (The spacecraft is considered a point mass moving in the gravitational field of the Sun, the Earth, and Mars.)

Mathematical methods used
Classical mechanics uses ordinary differential equations (ODEs) to describe the properties of bodies mathematically. Thus, coordinates, angles, etc. are numbers that depend on time, e.g. $$x(t),y(t),z(t),\phi(t),\theta(t)$$, and satisfy certain (systems of) ODEs.

One can use several mathematical methods to solve such equations. In some cases, solutions can be found exactly, for instance: $$\ddot{x}(t)+x(t)=0$$ has the general solution $$A\sin(t)+B\cos(t)$$. In other cases, solutions are found only in terms of integrals that one cannot evaluate in closed form. Sometimes, one can solve the equation approximately using some method such as perturbation theory. Finally, any ODE can be solved numerically (using a computer program) up to a certain precision.

Students of mechanics are expected to learn methods of solving certain standard differential equations that are exactly solvable, for instance: multidimensional harmonic oscillators, motion in 1-dimensional force field, motion in 3-dimensional central force field. Numerical methods for solving ODEs are important in practice but are usually not studied as part of classical mechanics because these methods are not specific to mechanics but are equally applicable to every differential equation. Numerical methods for solving various equations are best studied in a dedicated course that involves hands-on computer programming.

Newtonian mechanics
The first successful theory of classical mechanics is contained in Newton's three laws of mechanics that govern the motion of point masses:

 * 1) There exist reference frames where a point mass not interacting with other bodies will move with constant speed in the same direction. (If this is not true in some reference frame, then that reference frame is not inertial. Further laws are formulated in inertial frames.)
 * 2) A point mass interacting with other bodies moves with the acceleration $$\vec{a}$$ found from $$\vec{F}=m\vec{a}$$, where $$\vec{F}$$ is the sum of all forces acting on the body, $$m$$ is the mass of the body, and $$\vec{a}$$ is the acceleration, i.e. the second derivative of the position vector $$\vec{r}$$ with respect to the time.
 * 3) All forces are caused by other point masses, and whenever a point mass 1 exerts a force $$\vec{F}$$ on a point mass 2, the point mass 2  also exerts the force $$-\vec{F}$$ on the point mass 1.

The motion of all point masses is described by differential equations which can be solved directly as long as all relevant forces could be predicted or measured. I assume that you are already familiar with these laws and with typical situations where they apply (e.g. motion of bodies thrown at an angle near Earth) before you start studying theoretical mechanics.

In Newtonian mechanics, a rigid body is simply a collection of point masses connected by "rigid sticks." These sticks are "rigid" because they always produce exactly such forces as to keep constant distances between all points, regardless of any other forces or motions. Thus the motion of rigid bodies can be described without introducing any other special rules. One derives the concept of angular momentum, torque, etc., from Newton's laws without any additional postulates.

From Newtonian mechanics to "theoretical" mechanics
The necessity to consider point masses is certainly inconvenient if one needs to describe liquids and gases, so a special branch of mechanics with its own formalism was developed for that purpose, namely continuum mechanics (mechanics of continuous media). The formalism of continuum mechanics is generalized to field theory where the basic object is not a point mass but a field, i.e. some abstract "substance" that is present at all points in space and shows its influence at every point at once. (Examples are: gravitational field, electric field, and magnetic field.) Such substances may be described by a function of space and time, for example the vector field $$\vec E(t,\vec{r})$$ describes the electric field. The behavior of fields is usually governed by partial differential equations; for example, the electric field $$\vec E(t,\vec x)$$ and the magnetic field $$\vec B(t,\vec x)$$ satisfy Maxwell's equations.

As more and more complicated problems needed to be solved, various mathematical tools were developed to simplify and to generalize the mathematical description of mechanics. Finally, the Lagrangian and the Hamiltonian formulations of mechanics were discovered. These two formulations still remain the cornerstones of classical mechanics and field theory, as well as Einstein's theory of relativity, and thus indirectly of all modern theoretical physics. These formulations of mechanics are not based on the assumption of "forces" and are equally applicable to point masses, rigid bodies, fields, and continuous media. The main subject of theoretical mechanics (sometimes also called "analytical mechanics") is the study of these more refined and more general mathematical formulations of classical mechanics.

Overview: what is this "minimal standard course"
Much of theoretical physics is based on concepts from theoretical mechanics, such as the variation of the action, symmetry transformations, or the Hamiltonian. The goal of this course is to introduce the material that you absolutely need to learn if you would like to have a solid foundation for the study of theoretical physics.

In this text, I do not write the words "definition", "theorem", or "proof" like one does in mathematical texts. However, the same structure is present. I show new concepts in boldface within the sentence where they are defined.

Prerequisites

 * You can solve simple algebraic equations, such as $$x-\frac{2}{x}-1=0$$.
 * You can solve simple differential equations such as $$\ddot x(t)+2x(t)=3$$ with initial conditions such as $$x(0)=1,\dot x(0)=2$$.
 * You can manipulate three-dimensional vectors, compute vector sums, scalar products, vector (cross) products, projections on axes, angles between lines.
 * You are familiar with basic linear algebra (matrices, matrix multiplication, eigenvectors, diagonalization of matrices).
 * You can compute (or quickly look up) elementary integrals such as $$\int\limits_3^4 \sqrt{5x^2+8}~dx$$.
 * You are familiar with multivariate calculus, can compute partial derivatives, for example $$\partial_y\sqrt{x^2+y^2}$$.
 * You are familiar with (European) school-level mechanics, including Newton's laws, forces in static configurations, motion in straight lines and in circles, and basic ideas about rotation of rigid bodies and torque.

Core material
The minimal standard course in theoretical mechanics consists of:

 * Initial study of the Lagrangian and the Hamiltonian formalisms.
 * A general formulation of mechanics, applicable to all systems, can be achieved using a variation principle (also known as the action principle). All information about a particular mechanical system is encapsulated by its Lagrangian, which is a function $$L(q_i,\dot q_i,t)$$ . We derive the equations of motion in the general case, for an arbitrary mechanical system.
 * You already know how simple mechanical problems can be solved by elementary methods using forces, torques, etc., and now you will see how the same problems are reformulated using Lagrangians. You will see that is rather straightforward to find the Lagrangian for any particular system. Then it becomes apparent that many problems are much easier to solve using these formulations.
 * You need to gain some experience formulating various mechanical problems in terms of Lagrangians. Basically, you should be able to deal with any practical situation involving point masses, springs, sticks, ropes, frictionless rails, pendulums, balls rolling along cylinders rolling along planes, and so on. You need to learn how to best choose the coordinates or how to discover conservation laws in such systems. This comes only with experience solving practice problems.
 * Rotation of rigid bodies presents extra difficulties because of the complicated geometry. You need to learn some methods for dealing with these situations efficiently (tensor of inertia, Euler angles, rotating frames of reference).
 * The Hamiltonian formulation of mechanics is derived from the Lagrangian formulation. (For solving practical problems, the Hamiltonian formalism is less useful than the Lagrangian one, although it is somewhat more elegant mathematically. However, the Hamiltonian formalism is of such extraordinary importance in theoretical physics that it is usually studied early on, within the course of theoretical mechanics.)
 * Special relativity is usually introduced at this point using the formalism of four-dimensional vectors. In the Lagrangian formulation, this is a perfectly ordinary mechanical theory with a somewhat unusual Lagrangian. You need to develop some physical intuition for the various relativistic effects and also become familiar with the four-dimensional description of the world as a spacetime. Without special relativity and the four-dimensional view of the world, the road to much of theoretical physics is essentially closed.
 * Study of the mathematical methods needed to actually solve practical problems.
 * You need to learn how to solve various differential equations and systems of such equations. The typical equation is that of the harmonic oscillator with a driving force, $$\ddot{x}+\omega^2 x=f(t)$$ . Typically, you need to be able to find general solutions as well as particular solutions for given initial conditions. At this point we study only equations that can be solved exactly.
 * You need to gain experience analyzing the behavior of solutions of various types of equations: linear systems, oscillations and resonance, and some simple kinds of solvable nonlinear equations such as the Kepler problem. These are very old problems that occur time and again in physics, so you should become very familiar with the qualitative features of their solutions.
 * You need to learn some basic ideas of the calculus of variations. In particular, you need to understand the concept of a functional, and to learn to compute functional derivatives (i.e. "variations" of functionals). Otherwise you cannot really understand the use of the variational principle, which is very important in all of theoretical physics.

You usually need to solve several practice problems for each mathematical method, so that you can see how these methods work and gain experience.

Extra material
The above topics are considered standard because one cannot continue studying theoretical physics without having mastered them. There are also more advanced topics that build upon the standard ones and lead to other areas of physics:

 * Methods of perturbation theory, nonlinear oscillations, parametric resonance, adiabatic invariants (useful for celestial mechanics, chaos, and other things).
 * Use of quaternions instead of Euler angles to describe the position of rigid bodies (useful for numerical simulations of missile motion).
 * Elements of scattering theory: elastic/inelastic scattering; cross-sections in central potentials (preparation for particle physics).
 * A general definition of "symmetry" and the derivation of conservation laws (Noether's theorem). This is essentially a preparation for gauge field theory, which is the basis for particle physics.
 * Symmetries and oscillations in multi-dimensional systems (e.g. oscillations of molecules).
 * The action-angle variables and questions of integrability (preparation for chaos theory).
 * Canonical transformations, Hamilton-Jacobi equation -- tools to discover integrable systems. (Needed mostly for mathematical physics.)
 * Integral invariants, symplectic structures (tools to discover conservation laws and to explain the structure of the theory more deeply; useful in field theory).
 * Dealing with constrained degenerate systems (preparation for gauge theories).
 * Elements of continuous mechanics; continuity equations, stress-energy tensor, Euler equation. (Useful in hydrodynamics, electrodynamics of media, kinetics, etc.)

Some of these topics are usually included in a theoretical mechanics course at the lecturer's preference. History of theoretical mechanics is usually not studied; rather, students learn the contemporary, very much streamlined and simplified formulation of mechanics.

Suggested books to study
There is an extraordinarily large number of textbooks in theoretical mechanics, because it is a fairly old and well-studied subject. You need any textbook on classical mechanics that you can understand and that talks about "Lagrangians" early on. (Books that only talk about accelerations, forces, and torques may be quite advanced but they do not cover the subject of theoretical mechanics.)

 * H. Goldstein. Classical mechanics. - Has everything standard in it and quite a few advanced topics. An old classic.
 * L.N. Hand, J.D. Finch. Analytical mechanics (Cambridge, 1998). - A fresher, more didactic exposition of mechanics. Standard material.
 * V.I. Arnold. Mathematical methods of classical mechanics. -- Has almost nothing standard in it but is excellent for a more mathematically minded student.

authors: יהודה שמחה ולדמן

title: Classical Mechanics/Introduction


text:
Classical Mechanics/Lagrangian

Physics - Classical Mechanics

Prev Up Next

Mechanics considered using forces
In Newtonian mechanics, a mechanical system is always made up of point masses or rigid bodies, and these are subject to known forces. One must therefore specify the composition of the system and the nature of forces that act on the various bodies. Then one writes the equations of motion for the system. Here are some examples of how one describes mechanical systems in Newtonian mechanics (these examples are surely known to you from school-level physics).

 * Example: a free mass point.

This is the most trivial of all mechanical systems: a mass point that does not interact with any other bodies and is subject to no forces. Introduce the coordinates $$x,y,z$$ to describe the position of the mass point. Since the force is always equal to zero, the equations of motion are $$\ddot x=0, \ddot y=0, \ddot z=0$$. The general solution of these equations describes a linear motion with constant velocity: $$x=x_0 + v_x t$$, etc.

 * Example: two point masses with springs attached to a motionless wall.

Two masses can move along a line (the $$x$$ axis) without friction. The mass $$m_1$$ is attached to the wall by a spring, and the mass $$m_2$$ is attached to the mass $$m_1$$ by a spring. Both springs have spring constant $$k$$ and the unstretched length $$L$$.

To write the equations of motion, we first introduce the two coordinates $$x_1, x_2$$ and then consider the forces acting on the two masses. The force on the mass $$m_1$$ is the sum of the leftward-pointing force $$F_1$$ from the left spring and the rightward-pointing force $$F_2$$ from the right spring. The force on $$m_2$$ is a leftward-pointing $$F_2$$. By definition of a "spring" we have $$F_1 = k (x_1-L)$$ and $$F_2 = k (x_2 - x_1 - L)$$. Therefore we write the equations for the accelerations $$a_1, a_2$$ of the two masses: $$a_1 = \ddot {x_1} = \frac{F_2 - F_1}{m_1} = \frac{k}{m_1} (x_2 -x_1 -L) - \frac{k}{m_1} (x_1 -L),$$ $$a_2 = \ddot {x_2} = - \frac{F_2}{m_2} = - \frac{k}{m_2} (x_2 -x_1 -L).$$ At this point we are finished describing the system; we now need to solve these equations for particular initial conditions and determine the actual motion of this system.

Introducing the action principle
The Lagrangian description of a mechanical system is rather different: First, we do not ask for the evolution of the system given some initial conditions, but instead assume that the position of the system at two different time moments $$t_1$$ and $$t_2$$ is known and fixed. For convenience, let us collect all coordinates (such as $$x,y,z$$ or $$x_1,x_2$$ above) into one array of "generalized coordinates" and denote them by $$q_i$$. So the "boundary conditions" that we impose on the system are $$q_i(t_1)=A_i$$ and $$q_i(t_2)=B_i$$, where $$A_i,B_i$$ are fixed numbers. We now ask: how does the system move between the time moments $$t_1$$ and $$t_2$$. The Lagrangian description answers: during that time, the system must move in such a way as to give the minimum value to the integral $$\int _{t_1}^{t_2} L(q_i,\dot q_i) dt$$, where $$L(q_i, \dot q_i)$$ is a known function called the Lagrange function or Lagrangian. For example, the Lagrangian for a free mass point is $$L(x,y,z,\dot x, \dot y, \dot z) = \frac{m}{2} [\dot x^2 +\dot y^2 +\dot z^2].$$ The Lagrangian for the above example with two masses attached to the wall is $$L(x_1,x_2,\dot x_1, \dot x_2) = \frac{m}{2} [\dot x_1^2 +\dot x_2^2] - \frac{k}{2} (x_1-L)^2 - \frac{k}{2}(x_2-x_1-L)^2.$$

For instance, according to the Lagrangian description, the free point mass moves in such a way that the functions $$x(t),y(t),z(t)$$ give the minimum value to the integral $$\int _{t_1}^{t_2} \frac{m}{2}[\dot x^2 +\dot y^2 +\dot z^2]dt$$, where the values of $$x(t),y(t),z(t)$$ at times $$t_{1,2}$$ are fixed.

In principle, to find the minimum value of the integral $$\int _{t_1}^{t_2} L(q_i,\dot q_i) dt$$ one would have to evaluate that integral for each possible trajectory $$q_i(t)$$ and then choose the "optimal" trajectory $$q_i^{*}(t)$$ for which this integral has the smallest value. (Of course, we shall learn and use a much more efficient mathematical approach to determine this "optimal" trajectory instead of trying every possible set of functions $$q_i(t)$$.) The value of the mentioned integral is called the action corresponding to a particular trajectory $$q_i(t)$$. Therefore the requirement that the integral should have the smallest value is often called "the principle of least action" or just action principle.

At this point, we need to answer the pressing question: The short answer is that the least action requirement is mathematically equivalent to the consideration of forces if the Lagrangian $$L$$ is chosen correctly. The condition that some integral has the minimum value (when the integral is correctly chosen) is mathematically the same as the Newtonian equations for the acceleration. The point masses perhaps "know" nothing about this integral. It is simply mathematically convenient to formulate the mechanical laws in one sentence rather than in many sentences. (We shall see another, more intuitive explanation below.)
 * How can it be that the correct trajectory $$q_i^{*}(t)$$ is found not by considering the forces but by requiring that some integral should have the minimum value? How does each point mass "know" that it needs to minimize some integral when it moves around?

Suppose that we understand how the requirement that an integral has the minimum value can be translated into equations for the acceleration. Obviously the form of the integral needs to be different for each mechanical system since the equations of motion are different. Then the second question presents itself: This is a more complicated problem and one needs to study many examples to gain a command of this approach. (In brief: the Lagrange function is the kinetic energy minus the potential energy.)
 * How can we find the Lagrange function $$L(q_i, \dot q_i)$$ corresponding to each mechanical system?

Before considering Lagrange functions, we shall look at how the mathematical requirement of "least action" can be equivalent to equations of motion such as given in the examples above.

Variation of a functional
A function is a map from numbers into numbers; a functional is a map from functions into numbers. An application of a functional to a function is usually denoted by square brackets, e.g. $$S[f(x)]$$.

Random examples of functionals, just to illustrate the concept: $$S[f(x)] = \int _0 ^\infty \sqrt{f(3x)}dx$$ $$S[f(x)] = \int _{-1} ^1 \frac{f(x)}{1-x^2}dx$$ $$S[f(x)] = f(15) - 8 f'(3) - \int _0 ^1 \sin\left[(f(x-2)+\sqrt{x}e^{-x})^3\right] dx$$ In principle, a functional can be anything that assigns a number to any function. In practice, only some functionals are interesting and have applications in physics.

Since the action integral maps trajectories into numbers, we can call it the action functional. The action principle is formulated as follows: the trajectory $$q_i(t)$$ must be such that the action functional evaluated on this trajectory has the minimum value among all trajectories.

This may appear to be similar to the familiar condition for the mechanical equilibrium: the coordinates $$x,y,z$$ are such that the potential energy has the minimum value. However, there is a crucial difference: when we minimize the potential energy, we vary the three numbers $$x,y,z$$ until we find the minimum value; but when we minimize a functional, we have to vary the whole function $$q_i(t)$$ until we find the minimum value of the functional.

The branch of mathematics known as calculus of variations studies the problem of minimizing (maximizing, extremizing) functionals. One needs to learn a little bit of variational calculus at this point. Let us begin by solving some easy minimization problems involving functions of many variables; this will prepare us for dealing with functionals which can be thought of as functions of infinitely many variables. You should try the examples yourself before looking at the solutions.

Example 1: Minimize the function $$f(x,y) = x^2+xy+y^2$$ with respect to $$x,y$$.

Example 2: Minimize the function $$f(x_1,...,x_n) = x_1^2+x_1 x_2+x_2^2+x_2 x_3+...+x_n^2$$ with respect to all $$x_j$$.

Example 3: Minimize the function $$f(x_0,...,x_n) = (x_1-x_0)^2+(x_2-x_1)^2+...+(x_n-x_{n-1})^2$$ with respect to all $$x_j$$ subject to the restrictions $$x_0=0, x_n=A$$.

Solution 1: Compute the partial derivatives of $$f$$ with respect to $$x,y$$. These derivatives must both be equal to zero. This can only happen if $$x=0, y=0$$.

Solution 2: Compute the partial derivatives of $$f$$ with respect to all $$x_j$$, where $$j=1,...,n$$. These derivatives must all be equal to zero. This can only happen if all $$x_j=0$$.

Solution 3: Compute the partial derivatives of $$f$$ with respect to $$x_j$$, where $$j=2,...,n-1$$. These derivatives must all be equal to zero. This can only happen if $$x_j-x_{j-1}=x_{j+1}-x_j$$ for $$j=1,2,...,n-1$$. The values $$x_0, x_n$$ are known, therefore we find $$x_j=jA/n$$.

Intuitive calculation
Let us now consider the problem of minimizing the functional $$S[x]=\int _0 ^1 {\dot x(t)}^2 dt$$ with respect to all functions $$x(t)$$ subject to the restrictions $$x(0)=0, x(1)=L$$. We shall first perform the minimization in a more intuitive but approximate way, and then we shall see how the same task is handled more elegantly by the variational calculus.

Let us imagine that we are trying to minimize the integral $$L[x]$$ with respect to all functions $$x(t)$$ using a digital computer. The first problem is that we cannot represent "all functions" $$x(t)$$ on a computer because we can only store finitely many values $$x(t_0), x(t_1), ..., x(t_N)$$ in an array within the computer memory. So we split the time interval $$[0,1]$$ into a large number $$N$$ of discrete steps $$[0,t_1], [t_1, t_2], ..., [t_{N-1}, 1]$$, where the step size $$t_j-t_{j-1}\equiv \Delta t = 1/N$$ is small; in other words, $$t_j = j/N, j=1, ..., N-1$$. We can describe the function $$x(t)$$ by its values $$x_j$$ at the points $$t_j$$, assuming that the function $$x(t)$$ is a straight line between these points. The time moments $$t_1, ..., t_{N-1}$$ will be kept fixed, and then the various values $$x_j$$ will correspond to various possible functions $$x(t)$$. (In this way we definitely will not describe all possible functions $$x(t)$$, but the class of functions we do describe is broad enough so that we get the correct results in the limit $$N\to\infty$$. Basically, any function $$x(t)$$ can be sufficiently well approximated by one of these "piecewise-linear" functions when the step size $$\Delta t$$ is small enough.)

Since we have discretized the time and reduced our attention to piecewise-linear functions, we have $$\dot x = \frac{x_j-x_{j-1}}{\Delta t}$$ within each interval $$t\in[t_{j-1}, t_j]$$. So we can express the integral $$S[x]$$ as the finite sum, $$ S[x] =\int _0^1 {\dot x(t)}^2 dt = \sum_{j=1}^N \frac{{(x_j-x_{j-1})}^2}{\Delta t^2} \Delta t, $$ where we have defined for convenience $$t_0 =0, t_N = 1$$.

At this point we can perform the minimization of $$S[x]$$ quite easily. The functional $$S[x]$$ is now a function of $$N-1$$ variables $$x_1, ..., x_{N-1}$$, i.e. $$S[x]=S(x_1,...,x_{N-1})$$, so the minimum is achieved at the values $$x_j$$ where the derivatives of $$S(x_1,...,x_{N-1})$$ with respect to each $$x_j$$ are zero. This problem is now quite similar to the Example 3 above, so the solution is $$x_j = jL/N, j=0,...,N$$. Now we recall that $$x_j$$ is the value of the unknown function $$x(t)$$ at the point $$t_j=j/N$$. Therefore the minimum of the functional $$S[x]$$ is found at the values $$x_j$$ such that would correspond to the function $$x(t)=Lt$$. As we increase the number $$N$$ of intervals, we still obtain the same function $$x(t)=Lt$$, therefore the same function is obtained in the limit $$N\to\infty$$. We conclude that the function $$x(t)=Lt$$ minimizes the functional $$L[x]$$ with the restrictions $$x(0)=0, x(1)=L$$.

Variational calculation
The above calculation has the advantage of being more intuitive and visual: it makes clear that minimization of a functional $$S[x(t)]$$ with respect to a function $$x(t)$$ is quite similar to the minimization of a function $$S(x_1, ..., x_N)$$ with respect to a large number of variables $$x_j$$ in the limit of infinitely many such variables. However, the formalism of variational calculus provides a much more efficient computational procedure. Here is how one calculates the function $$x(t)$$ that minimizes $$S[x]$$.

Let us consider a very small change $$\epsilon(t)$$ in the function $$x(t)$$ and see how the functional $$S[x]$$ changes: $$\delta S[x(t), \epsilon(t)] \equiv S[x(t)+\epsilon(t)]-S[x(t)].$$ (In many textbooks, the change in $$x(t)$$ is denoted by $$\delta x(t)$$, and generally the change of any quantity $$Q$$ is denoted by $$\delta Q$$. We chose to write $$\epsilon(t)$$ instead of $$\delta x(t)$$ for clarity.)

The functional $$\delta S[x, \epsilon] $$ is called the variation of the functional $$S[x]$$ with respect to the change  $$\epsilon(t)$$ in the function $$x(t)$$. The variation is itself a functional depending on two functions, $$x(t)$$ and $$\epsilon(t)$$. When $$\epsilon(t)$$ is very small, we expect that the variation will be linear in $$\epsilon(t)$$, just like the variation in the value of a normal function is linear in the amount of change in the argument, e.g. $$f(t+\alpha)-f(t)=f'(t) \alpha$$ for small $$\alpha$$. So we expect that the variation $$\delta S[x, \epsilon] $$ of the functional $$S[x]$$ will be a linear functional of $$\epsilon(t)$$. To understand what a linear functional looks like, consider a linear function $$f(\epsilon_j)$$ depending on several variables $$\alpha_j$$, $$j=1,2,...$$. This function can always be written as $$f(\epsilon_j) = \sum_{j}^{} A_j \epsilon_j$$ where $$A_j$$ are suitable constants. Since a functional is like a function of infinitely many variables, the index $$j$$ becomes a continuous variable $$t$$, the variables $$\epsilon_j$$ and the constants $$A_j$$ become functions $$\epsilon(t),A(t)$$, while the sum over $$j$$ becomes an integral over $$t$$. Thus, a linear functional of $$\epsilon(t)$$ can be written as an integral, $$\delta S[x, \epsilon]=\int _0^1 A(t) \epsilon(t) dt,$$ where $$A(t)$$ is a suitable function. In the case of the usual function $$f(t)$$, the "suitable constant $$A$$" is the derivative $$A=df(t)/dt$$. By analogy we call $$A(t)$$ above the variational derivative of the functional and denote it by $$\delta S[x]/\delta x(t)$$.

A function has a minimum (or maximum, or extremum) at a point where its derivative vanishes. So a functional $$S[x(t)]$$ has a minimum (or maximum, or extremum) at the function $$x(t)$$ where the functional derivative vanishes. We shall justify this statement below, and for now let us now compute the functional derivative of the functional $$S[x(t)]=\int_0^1 \dot x^2 dt$$.

Substituting $$x(t)+\epsilon(t)$$ instead of $$x(t)$$ into the functional, we get $$\delta S[x,\epsilon]=\int _0^1 [(\dot x+\dot \epsilon)^2-\dot x^2]dt=2\int_0^1\dot x \dot \epsilon dt +O(\epsilon^2),$$ where we are going to neglect terms quadratic in $$\epsilon(t)$$ and so we didn't write them out. We now need to rewrite this integral so that no derivatives of $$\epsilon(t)$$ appear there; so we integrate by parts and find $$\delta S[x(t),\epsilon(t)]= \left. \epsilon(t)\dot x(t)\right| _0^1 - 2\int _0^1 \ddot x(t) \epsilon(t) dt.$$ Since in our case the values $$x(0),x(1)$$ are fixed, the function $$\epsilon(t)$$ must be such that $$\epsilon(0)=\epsilon(1)=0$$, so the boundary terms vanish. The variational derivative is therefore $$\delta S/\delta x(t) = -2\ddot x(t).$$

The functional $$S[x]$$ has an extremum when its variation under an arbitrary change $$\epsilon(t)$$ is second-order in $$\epsilon(t)$$. However, above we have obtained the variation as a first-order quantity, linear in $$\epsilon(t)$$; so this first-order quantity must vanish for $$x(t)$$ where the functional has an extremum. An integral such as $$\int_0^1 A(t) \epsilon(t)$$ can vanish for arbitrary $$\epsilon(t)$$ only if the function $$A(t)$$ vanishes for all $$t$$. In our case, the "function $$A(t)$$," i.e. the variational derivative $$\delta S/\delta x(t)$$, is equal to $$-2\ddot x(t)$$. Therefore the function $$x(t)$$ on which the functional $$S[x]$$ has an extremum must satisfy $$-2\ddot x(t)=0$$ or more simply $$\ddot x=0$$. This differential equation has the general solution $$x(t)=a+bt$$, and with the additional restrictions $$x(0)=0,x(1)=L$$ we immediately get the solution $$x(t)=Lt$$.

General formulation
To summarize: the requirement that the functional $$S[x(t)]$$ must have an extremum at the function $$x(t)$$ leads to a differential equation on the unknown function $$x(t)$$. This differential equation is found as $$\delta S[x]/\delta x(t) =0. $$ The procedure is quite similar to finding an extremum of a function $$f(t)$$, where the point $$t$$ of the extremum is found from the equation $$df(t)/dt=0$$.

Suppose that we are now asked to minimize the functional $$S[x(t)]=\int _0^1 (x^2+\dot x^2-x^4\sin t)dt$$ subject to the restrictions $$x(0)=0,x(1)=1$$; in mechanics we shall mostly be dealing with functionals of this kind. We might try to discretize the function $$x(t)$$, as we did above, but this is difficult. Moreover, for a different functional $$S[x]$$ everything will have to be computed anew. Rather than go through the above procedure again and again, let us now derive the formula for the functional derivative for all functionals of this form, namely $$S[x_i(t)]=\int_a^b L(x_i,\dot x_i,t)dt,$$ where $$L(x_i,v_i,t)dt$$ is a given function of the coordinates $$x_i$$ and velocities $$v_i\equiv \dot x_i$$ (assuming that there are $$n$$ coordinates, so $$i=1,...,n$$). This function $$L(x_i,v_i,t)dt$$ is called the Lagrange function or simply the Lagrangian.

We introduce the infinitesimal changes $$\epsilon_i(t)$$ into the functions $$x_i(t)$$ and express the variation of the functional first through $$\epsilon_i(t)$$ and $$\dot\epsilon_i(t)$$, $$\delta S[x_i(t),\epsilon_i(t)]=\int_a^b \sum _{i=1}^n\left[ \frac{\partial L}{\partial x_i}\epsilon_i(t)+\frac{\partial L}{\partial v_i}\dot \epsilon_i(t) \right] dt.$$ Then we integrate by parts, discard the boundary terms and obtain $$\delta S[x_i(t),\epsilon_i(t)]=\int_a^b \sum _{i=1}^n\left[ \frac{\partial L}{\partial x_i}-\frac{d}{dt}\frac{\partial L}{\partial v_i} \right] \epsilon_i(t)dt.$$ Thus the variational derivatives can be written as $$\frac{\delta S[x]}{\delta x_i(t)}=\frac{\partial L}{\partial x_i}-\frac{d}{dt}\frac{\partial L}{\partial v_i}.$$

 * Further reading: Notes on functionals by B. Svetitsky

Euler-Lagrange equations
Consider again the condition for a functional to have an extremum at $$x_i(t)$$: the first-order variation must vanish. We have derived the above formula for the variation $$\delta S[x_i, \epsilon_i]$$. Since all $$\epsilon_i(t)$$ are completely arbitrary (subject only to the boundary conditions $$\epsilon_i(a)=\epsilon_i(b)=0$$), the first-order variation vanishes only if the functions in square brackets all vanish at all $$t$$. Therefore we obtain the Euler-Lagrange equations $$\frac{\partial L}{\partial x_i}-\frac{d}{dt}\frac{\partial L}{\partial v_i} = 0.$$ These are the differential equations that express the mathematical requirement that the functional $$S[x_i(t),\dot x_i(t),t]$$ has an extremum at the set of functions $$x_i(t)$$. There are as many equations as unknown functions $$x_i(t)$$, one equation for each $$i=1,...,n$$.

Note that the Euler-Lagrange equations involve partial derivatives of the Lagrangian with respect to coordinates and velocities. The derivatives with respect to velocities $$v=\dot x$$ are sometimes written as $$\partial L/\partial \dot x$$ which might at first sight appear confusing. However, all that is meant by this notation is the derivative of the function $$L(x,v,t)$$ with respect to its second argument.

The Euler-Lagrange equations also involve the derivative $$d/dt$$ with respect to the time. This is not a partial derivative with respect to $$t$$ but a total derivative. In other words, to compute $$\frac{d}{dt}\frac{\partial L}{\partial \dot x_i}$$, we need to substitute the functions $$x_i(t)$$ and $$\dot x_i(t)$$ into the expression $$\frac{\partial L}{\partial \dot x_i}$$, thus obtain a function of time only, and then take the derivative of this function with respect to time.

Remark: If the Lagrangian contains higher derivatives (e.g. the second derivative), the Euler-Lagrange formula is different. For example, if the Lagrangian is $$L=L(x,\dot x, \ddot x)$$, then the Euler-Lagrange equation is $$\frac{\partial L}{\partial x}-\frac{d}{dt}\frac{\partial L}{\partial \dot x} + \frac {d^2}{dt^2}\frac{\partial L}{\partial \ddot x}= 0.$$ Note that this equation may be up to fourth-order in time derivatives! Usually, one does not encounter such Lagrangians in studies of classical mechanics because ordinary systems are described by Lagrangians containing only first-order derivatives.

Summary: In mechanics, one specifies a system by writing a Lagrangian and pointing out the unknown functions in it. From that, one derives the equations of motion using the Euler-Lagrange formula. You need to know that formula really well and to understand how to apply it. This comes only with practice.

How to choose the Lagrangian
The basic rule is that the Lagrangian is equal to the kinetic energy minus the potential energy. (Both should be measured in an inertial system of reference! In a non-inertial system, this rule may fail.)

It can be shown that this rule works for an arbitrary mechanical system made up of point masses, springs, ropes, frictionless rails, etc., regardless of how one introduces the generalized coordinates. We shall not study the proof of this statement, but instead go directly to the examples of Lagrangians for various systems.

Examples of Lagrangians
$$L=\frac{1}{2} m {\dot x}^2.$$
 * The Lagrangian for a free point mass moving along a straight line with coordinate $$x$$:
 * {| class="toccolours collapsible collapsed" width="80%" style="text-align:left"

!Solution $$\frac{\partial L}{\partial x}-\frac{d}{dt}\frac{\partial L}{\partial\dot x}=0$$

$$\frac{\partial}{\partial x}\left(\frac{1}{2} m {\dot x}^2\right)=0$$

$$\frac{\partial}{\partial\dot x}\left(\frac{1}{2} m {\dot x}^2\right)=m\dot x$$

$$\frac{d}{dt}\frac{\partial}{\partial\dot x}\left(\frac{1}{2} m {\dot x}^2\right)=m\ddot x$$

The Euler-Lagrange equation reduces to, $$ 0 - m\ddot x=0$$ or $$\ddot x=0$$, which states that a particle experiencing no forces will have no acceleration. $$L=\frac{1}{2} m {\dot x}^2 - V(x).$$
 * }
 * A point mass moving along a straight line with coordinate $$x$$, in a force field with potential energy $$V(x)$$:
 * {| class="toccolours collapsible collapsed" width="80%" style="text-align:left"

!Solution $$\frac{\partial L}{\partial x}-\frac{d}{dt}\frac{\partial L}{\partial\dot x}=0$$

$$\frac{\partial}{\partial x}\left(\frac{1}{2} m {\dot x}^2 - V(x)\right)=-V'(x)$$

$$\frac{\partial}{\partial\dot x}\left(\frac{1}{2} m {\dot x}^2 - V(x)\right)=m\dot x$$

$$\frac{d}{dt}\frac{\partial}{\partial\dot x}\left(\frac{1}{2} m {\dot x}^2 - V(x)\right)=m\ddot x$$

The Euler-Lagrange equation reduces to,$$ -V'(x) - m\ddot x=0$$ or $$m\ddot x=-V'(x)$$. If $$V(x)$$ is the gravitational potential $$V(x) = mgx$$, then $$V'(x) = -mg$$ and the Euler-Lagrange equation becomes $$\ddot x=-g$$. This aligns with the Newtonian result that the acceleration of an object in a gravitational field is $$-g$$. $$L=\frac{1}{2}\sum_{i=1}^3 \left( m {\dot x_i}^2\right) - V(x,y,z)=\frac{m}{2}|\dot\vec x|^2-V(\vec x).$$
 * }
 * A point mass moving in three-dimensional space with coordinates $$x_i\equiv (x,y,z)$$, in a force field with potential energy $$V(x,y,z)$$:

$$L=K-U=\frac{m}{2}R^2\dot\theta^2-mgR\cos\theta.$$ Note that we have written the Lagrangian (and therefore we can derive the equations of motion) without knowing the force needed to keep the mass moving along the circle. This shows the great conceptual advantage of the Lagrangian approach; in the traditional Newtonian approach, the first step would be to determine this force, which is initially unknown, from a system of equations involving an unknown acceleration of the point mass.
 * A point mass constrained to move along the circle $$x^2+z^2=R^2$$ in the gravitational field near the Earth (the $$z$$ axis is vertical). It is convenient to introduce the angle $$\theta$$ as the coordinate, with $$z=R\cos\theta, x=R\sin\theta$$. Then the potential energy is $$U=mgz=mgR\cos\theta$$, while the kinetic energy is $$K=mv^2/2=mR^2\omega^2/2=mR^2\dot\theta^2/2$$. So the Lagrangian is

$$L=\frac{m}{2}(\dot x_1^2 + \dot x_2^2)-\frac{k}{2}(x_1-x_2-l)^2.$$
 * Two (equal) point masses connected by a spring with length $$l$$:

$$L=\frac{m}{2} l^2 \dot \theta^2 +mgl\cos\theta .$$
 * A mathematical pendulum, i.e. a massless rigid stick of length $$l$$ with a point mass attached at the end, that can move only in the $$x-z$$ plane in the gravitational field near the Earth (vertical $$z$$ axis). As the coordinate, we choose the angle $$\theta$$ between the stick and the $$z$$ axis. The Lagrangian is

$$K=\frac{m}{2} (\dot x^2 + \dot y^2 + \dot z^2)=\frac{m}{2} (\dot x^2/\cos^2\alpha + \dot y^2).$$ Hence, the Lagrangian is $$L=K-U=\frac{m}{2} (\dot x^2/\cos^2\alpha + \dot y^2) -mgx\tan\alpha.$$
 * A point mass $$m$$ sliding without friction along an inclined plane that makes an angle $$\alpha$$ with the horizontal, in the gravitational field of the Earth. As the coordinate, we choose $$x,y$$, where $$y$$ is parallel to the incline. The height $$z$$ is then $$z=x\tan\alpha$$, so the potential energy is $$U=mgz=mgx\tan\alpha$$. The kinetic energy is computed as

Further work
Exercise: You should now determine the Euler-Lagrange equations that follow from each the above Lagrangians and verify that these equations are the same as would be obtained from school-level Newtonian considerations for the respective physical systems. This should occupy you for at most an hour or two. Only then you will begin to appreciate the power of the Lagrangian approach.

Some more Lagrangian exercises here.

For more examples of setting up Lagrangians for mechanical systems and for deriving the Euler-Lagrange equations, ask your physics teacher or look up in any theoretical mechanics problem book. Much of the time, the Euler-Lagrange equations for some complicated system (say, a pendulum attached to the endpoint of another pendulum) would be too difficult to solve, but the point is to gain experience deriving them. Their derivation would be much less straightforward in the old Newtonian approach using forces.

See here for a very brief primer on differential equations.

If this is your first time looking at Lagrangians, you might be still asking yourself: how could the motion of a system be described by saying that some integral has the minimal value? Is it a purely formal mathematical trick, and if not, how can one get a more visually intuitive understanding? A partial answer is here.

title: Classical Mechanics/Lagrangian


text:
User talk:80.185.185.15

That's cute, very cute!

How about getting an account? :) Dysprosia 08:01, 20 Jun 2004 (UTC)

title: User talk:80.185.185.15