text:
CAT-Tools/MemoQ/Tips and Tricks

MemoQ
You probably want to create regular back-ups of your resources (projects, translation memories, term bases, settings, etc.) for disaster recovery. As MemoQ stores resources as files, it is fairly easy to create backups by simply copying folders or files. The below instructions let you create backups that you can quickly restore if your resources become corrupted. The backups created this way are not meant for "long term" usage though: trying to restore a backup created in an older version might cause problems.

Before backing up or restoring any files, make sure that MemoQ is not running. MemoQ might hold some files open or may even be writing into one of them, which might prevent a successful backup or restore.

You need to back up the following folders:

(In Windows Vista: C:\ProgramData\MemoQ) (In Windows Vista: C:\Users\(your username)\AppData\Roaming\MemoQ)
 * C:\Documents and Settings\All users\Application Data\MemoQ
 * C:\Documents and Settings\(your username)\Application Data\MemoQ
 * My Documents\My MemoQ Projects

(The above assumes that C:\ is the system drive.) For projects, translation memories, term bases, and filter configurations, the default storage paths can be changed in MemoQ under Tools > Options > Appearance, Locations. If you have changed the default paths for any of the above, make a backup of your new paths.

MemoQ Server
If you are using a server solution, it is also advisable to regularly back up the SQL database that contains information about the users, groups, permissions and projects. By default, it is found in the following folder, which also contains the project folder and some configuration files that you may also want to back up:

(In Windows Vista: C:\ProgramData\MemoQ Server)
 * C:\Documents and Settings\All Users\Application Data\MemoQ Server

The SQL database file and the transaction log are stored under the names MemoQServer.mdf and MemoQServer_log.ldf. Both are needed for a successful backup and restore. During the server installation you might have changed the path where the server database is stored. If you did change it, make sure that you back up the new path as well. The folder where server project documents are stored can also be changed from the Server Administrator, so if you are not using the default folder, back up the actual project folder as well.

Before the backup or restore operation, you will need to stop the MemoQ Server service and the service of the SQL Server instance pertaining to the MemoQ Server (in that order). Failure to do so may stop you from successfully finishing the operation, or might even leave the server in an unworkable state. After the backup or restore operation, start the SQL instance service and the MemoQ Server service (in that order) again.

Never try to restore a database backup if you have upgraded your server to a newer version since the backup was taken. The database schema often gets modified between versions, and a database created by an older version might not work with the current version of the server. If you need to restore a database that was created in an older version of MemoQ Server, you first need to uninstall you current version of MemoQ Server, and install the version the database was created in. After this, you can restore the backup of the database, and install the current version. The installer will upgrade the restored database to the current version.

License files
By following the above instructions, your backups might contain the license files of MemoQ and/or MemoQ Server. However, if there are frequent licensing related changes (e.g. you are using mobile licenses or have acquired new licenses recently), it might not be a good idea to restore earlier versions of your license files when you restore a backup. In this case, do not include the license files in your backup packages. (Or, if they are already backed up, do not restore them.) License files are named LicenseNN.dat (where N is a digit, e.g. License11.dat, License02.dat etc.). They can be found in the following folders:

MemoQ: (In Windows Vista: C:\ProgramData\MemoQ)
 * C:\Documents and Settings\All users\Application Data\MemoQ

and/or

(In Windows Vista: C:\Users\(your username)\AppData\Roaming\MemoQ)
 * C:\Documents and Settings\(your username)\Application Data\MemoQ

MemoQ Server: (In Windows Vista: C:\ProgramData\MemoQ Server)
 * C:\Documents and Settings\All Users\Application Data\MemoQ Server

If you have licensing problems after restoring a backup, update your licenses online first. To do this, click Activation (or Server Activation for the server) in the Help menu, and click Update licenses online. If this does not solve the problem, turn to Kilgray support.

Purge older (multiple) translations from the TM
Task: How to purge older translations in cases where there are multiple translations for a certain segment.

Solution: This is in fact possible in MemoQ, with or without a bit of trickery, depending on the settings of your TM.

 * 1) By default, a TM only allows one entry for the same source segment; this is a setting you can specify when you create the TM. You can also configure which entries will be kept: again, by default, the translation you commit later will overwrite the previous one. In this case, then, the issue of multiple translations does not exist in the first place.
 * 2) If your TM allows multiple translations and you want to purge it, there is also a way. When you open the TM for editing, you can specify filtering/sorting criteria. If you sort by entry date&time, and then export to TMX, the entries will be listed chronologically. Importing back into a TM that only allows a single translation will have the effect that only the most recent translations are kept.

This is perhaps not an extremely easy way; but again, perhaps if one chooses to allow multiple translations, this is also not what you want to do on a regular basis.

Working with TTX files using MemoQ 2.0 - alternate workflow
Recent versions of MemoQ (2.1 and above) have full support for TTX files, but for older versions, there is still a solution to work on TTX files. Here is how to proceed.

First of all, you will need to download a doc file, PlusToyz, containing Word macros and freely available from the Wordfast Yahoo group (in the Files section, at http://tech.groups.yahoo.com/group/wordfast/files). You have to join the group to be able to download that file.

Using any Web search engine, you may find several links to direct downloads, but 99% of them are old versions of this file and hence results wouldn't be guaranteed.

So, here is how to proceed:

 * Open the PlusToyz.doc file using Word
 * Use the bottom macro (TTX file to Trados-like segmented text) to convert your TTX file to word "Trados tagged" bilingual doc
 * Import the resulting tagged Word file using MemoQ, making sure to add tw4winMark as an excluded style (make sure you also check the External box)
 * Translate every *second* segment, leaving all "source" (first) ones blank
 * Once translation if finished and you are sure all due segments are properly confirmed, select Copy source to target where empty... from the Translation menu
 * Now that all segments are populated, press CTRL+SHIFT+A to select all segments and select Confirm without update from the Translation menu
 * You now have a fully exportable doc file (and proper TM, without useless source=source stuff)!
 * Export the document
 * Open the PlusToyz.doc Word file again
 * Select the Segmented text to TTX macro to convert your translated file back to TTX
 * Open the resulting TTX file using TagEditor and see by yourself, a properly translated file !

Please note that, although split/join operations during translation should not and may not alter the end result, it is better to restrain playing with it too much till we get large and solid reports that it won't affect the final TTX.

You can import DOCX files directly in current versions of memoQ.

Translating a docx file (Word 2007) using MemoQ
You can import a .docx file directly in current versions of memoQ.

 * Rename your .docx file and add the .zip suffix.
 * Open the new "zip" file, and you will see several folders. Browse to the Word folder and extract only the document.xml file, which contains the text of the document that you will need to translate
 * Start MemoQ and create a new project
 * Select Add document as and browse to the document.xml file
 * In the Document import settings dialog, you will have the XML filter already selected
 * We will now create an XML filter for DOCX documents. Later on, you'll just have to double click on it to select it
 * Click Manage XML formats to display the XML Format administrator dialog
 * Now select the Create new format option
 * Give a name to this brand new custom XML filter. Let's call it DOCX(Word2007)
 * Make sure Create from scratch is checked and click OK
 * In the XML format settings dialog, click Add file and browse to the document.xml file
 * Now select the Tags and attributes tab and click Populate. MemoQ will analyse the file and automatically cerate the proper tagging settings.
 * Click OK. You now have a proper DOCX xml filter. Click Close to close this window.
 * Now that you have an appropriate xml filter, double click on the custom DOCX(Word2007) filter.
 * The file is imported. You can now safely translate it using MemoQ.
 * Once translation is finished, just export the document.xml file
 * Replace the old document.xml in the .zip archive with the translated one
 * Rename the file to remove the .zip suffix and restore the former .docx extension

You now have a translated DOCX file!

Changing a TTX file source/target language using MemoQ 2.x and above
Sometimes, when your client sends you a TM using a specific source language (ex. EN-CA), you may import your TTX files into a project using another regional language (ex. EN-GB) only to discover later that, when you export the resulting TTX, the source language has changed! This may lead to problems, as TagEditor refuses to edit a TTX using language settings different than the TM it is currently associated with.

In fact, MemoQ sets the source and target language of your TTX files to those chosen for the current project. You may sometimes want to turn that to your advantage and deliberately chose whatever source and target language you see fit.

To do that, proceed as follows:

special note here: MemoQ defaults to EN-US if you chose only "English" without specifying the locale
 * export the translated TTX file(s) from your current project as MBD (MemoQ bilingual document)
 * create a new project using any source or target language you need.
 * import your MBD files into this new project
 * select all segments and copy source text to target
 * export those TTX files using either "export selected" or "export all"

And here you are, you now have fully working bilingual TTX files you can open using TagEditor with the source/target language you chose!

Showing spaces and other special characters
MemoQ does not have a built-in switch to show or hide spaces and other non-printing characters. You can display them by using a specially adapted font. The font in question, Veronika, was developed by Endre Both, and with the author's kind permission it is also available from the Kilgray site at the links:

http://kilgray.com/memoq/VeronikaSans.ttf

http://kilgray.com/memoq/VeronikaSerif.ttf

Note: Both Veronika fonts display rectangles instead of extended CEE (Central & Eastern Europe) characters.

Denis Hay created similar fonts based on Calibri; these are also available from the Kilgray site with his kind permission:

http://kilgray.com/memoq/CALIBRI_MQ.ttf http://kilgray.com/memoq/CALIBRI_MQ2.ttf http://kilgray.com/memoq/CALIBRI_MQ3.ttf

A description of the fonts by Denis:

Calibri MQ just adds a smallish triangle-shaped glyph to display unbreakable spaces.

Calibri MQ2 also adds to that a tiny-weeny dot to display ordinary spaces. This dot does not hinder reading, unlike the usual modified fonts, but it allows easy spotting of double spaces when looking at it closely. That's the one I prefer.

Calibri MQ3 is quite similar to MQ2, but with a larger dot glyph for ordinary spaces, for those who may prefer that.

To show spaces while translating in MemoQ, follow these steps:

 * 1) Download the fonts from the links above
 * 2) Go to Control Panel / Fonts and choose Install New Font... from the File menu
 * 3) Browse to the folder where you saved the fonts, select them from the list at the top, and click OK
 * 4) In MemoQ, open Tools / Options and go to the Appearance, locations category. In the Font family drop-down list, select any of the newly installed fonts

MemoQ will now show small dots for every space character in the translation grid.

Entering non-breaking spaces
Although this is not a documented feature, MemoQ can enter non-breaking spaces useful e.g. in the case of French quotation marks. To enter a non-breaking space press ctrl+shift+space instead of space.

Getting rid of "rogue codes" in Word documents
For certain Word documents, MemoQ will show superfluous tags that apparently serve no purpose. Once you import your document, there's no way to delete these tags; the best you can do is to insert them by pressing F8 or put them at the end of the target segment by hitting Alt+F8.

There are several possible ways to reduce such tags prior to importing:

 * Select the whole document and set the right Language
 * Accept all changes
 * Turn off track changes
 * Turn off smart tags
 * Select the whole document and set character spacing - Scale 100%; Spacing: Normal; and Position: Normal
 * Save as Open Office and then back to Word (this may result in some loss of formatting)
 * Save doc as Word 6.0/95 (this may result in some loss of formatting)
 * TRADOS segment and clean up

These and other methods are discussed here: http://www.necco.ca/dv/word.htm#Rogue_codes

Some of these pre-import tips and others have been automated in a set of macros that I've assembled in a Word template with a custom toolbar (CodeZapper_2.3). This template also includes a few other pre- and post-processing macros that may be useful. It was principally intended for use with Deja Vu but MemoQ users may also find it useful in some circumstances. You can find it in the files section (http://tech.groups.yahoo.com/group/MemoQ/files/). Dave Turner

More ideas on removing rogue codes from Jim Wardell :

If Word files cause rogue codes in MemoQ, pre-edit them looking for the problems suggested above by Dave. Also:

Make sure autohypenation is deactivated in the entire Word file.

Use Find and Replace to remove all optional hyphens.

Make sure the Word setting "Hyphenate words in CAPS" is off.

Sometimes rogue codes are caused when the font size in the source PDF text hovers between two integer sizes. The OCR output (which even allows half-point sizes) then can contain embedded font size changes (e.g. 11 pt. --> 11.5 pt. --> 11 pt --> 10.5 pt.). If you get a lot of these, and the Word file itself contains several font sizes that you want to retain, you may need to go through and select the continuous font-size passages and apply the font size you want to use (in the above case, for example, perhaps Arial 11 pt.). A slicker, more professional way to do this would be to apply a style definition to such passages. Your style definition would also include No Autohypenation and normal character spacing.

If your source document does not contain bold or italics, select the entire file and change all to Bold + Italics. Then select the entire file again and remove the bold and italics.

If you are scanning PDF files using OCR software (and therefore are the one who created the rogue codes in the first place!), take a close look at the detailed settings options that were in effect when you exported from OCR to Word. Only use those settings that you need, the others may be generating rogue codes.

The Arial Unicode font is installed by OmniPage. OmniPage inserts tags around umlauts in Word files. I've solved this problem by removing the Arial Unicode font from my system. It's also a good idea when using OCR software to use font matching to restrict the fonts that are allowed in OCR output, e.g. to Times New Roman and Arial.

If your client offers to convert PDF files to Word for you, consider that he/she may be using a cheap PDF converter program to do this and might not have the slightest clue what he/she is doing. In this case, you're better off getting the PDF file yourself and using high-quality OCR software to do the conversion yourself. Be aware that PDF converters, even the best ones, are likely to cause more problems with rogue codes and formatting than professional quality OCR software. You get what you pay for. There also are major differences between the two leading professional-grade OCR programs in their ability to reduce rogue codes and produce TM-friendly formatting. Test both carefully and see which gives the more TM-friendly results in your situation.

The suggestions offered by Dave and myself should help you eliminate nearly all rogue codes, however if you are still getting too many, open MQ and notice where a given rogue code occurs, then open the offending file in Word at the same time. Try selecting the characters around the offending location and check for any changes in settings. If you learn something useful, please register as a Wikibooks author and add them to this page.

A suggestion that worked well for us (a gaming related company) was to delete specific kinds of these tags by simply using the regex ]*>, enabling regular expressions in find&replace, enabling source replacement, and enabling find&replace within tags within the checkbox. In 99% of docx documents with a flood of excessive tags, this solved the issue without any noticeable impact on formatting or quality. This also works in Excel files with similar issues. It'd still be best to do a test export afterwards to see if you broke anything, but usually this works without any problem whatsover. So yes, you CAN in fact delete them after the import with a bit of find&replace!

Disable case conversions in "Translation Results"
For some languages, you may want to disable the case conversions in the "Translation Results" pane.

 * "Tools" > "Options" > "TM defaults, user info"
 * Disable "Toggle all replacements"

Filter out unwanted languages
Having to scroll through the list of languages during project configuration is tedious. In a future build Kilgray are likely to make MemoQ remember a list of recently used languages and display those at the top of the list.

Meanwhile, users can eliminate unwanted languages using the following simple procedure (based on a suggest by Gregory in ).

If you don't have an XML editor you can download the free XML Marker software from here:

Open XML Marker and open the file LangInfo.xml. This is likely to be located at 'C:\Documents and Settings\All Users\Application Data\MemoQ' or it may be somewhere else, depending on your installation options.

Note: Under Windows 7, the file may well be located at "C:\ProgramData\MemoQ". This is important to note, since a Windows Search will not commonly (?) find files in this special, hidden system folder. --Drawdenrubdarb (discuss • contribs) 08:14, 15 May 2012 (UTC)

In XML Marker highlight the language codes you don't require, right-click and select "Comment out Selection". Once all unwanted languages have been commented out, save the file and live happily ever after :-)

--HerbEppel 15:49, 17 November 2007 (UTC)

Reducing increased size of RTF files converted from DOC format containing images
MemoQ does not work with DOC files, instead, during import, it converts your files from DOC format to rich-text format (RTF) using your Microsoft® Office™ Word application. When the DOC files contain images, the images are converted to a useless, but huge windows metafile. This ensures compatibility with ANCIENT word processors, but does nothing for you. In fact, a simple company logo can expand the size of a short letter from 20 KB, to 1,200 KB (or 1.2 MB). And that is before you start adding text. The solution is a simple change in the registry for WORD on each machine. To keep Word from saving two copies of the graphic in your RTF file do the following:

 * 1) Close Word (if it’s running.)
 * 2) Click Start > Run. The Run dialog box appears.
 * 3) In the Open box, type regedit and click OK. The Registry Editor opens.
 * 4) Navigate to HKEY_CURRENT_USER > Software > Microsoft > Office > Version > Word > Options. (Replace Version with the version of Word you are using.)
 * 5) In the right pane of the window, right-click and choose New > String Value. A new string is created called New Value #1.
 * 6) Rename the value to ExportPictureWithMetafile. (To do this, you can choose Rename from the shortcut menu.)
 * 7) Once the name is changed, right-click on the string and choose Modify. The Edit String dialog box appears.
 * 8) In the Value data box, enter 0.
 * 9) Click OK.

This method is discussed here:

Using MemoQ postcardware and MemoQ Translator Pro (full version) on the same computer
If you want to use MemoQ 2.0, but at the same time install the full or trial version of MemoQ on the same computer, please do the following:

 * 1) Install MemoQ 2.0.
 * 2) Copy everything under C:\Program Files\Kilgray\MemoQ into a different folder, and make a shortcut to MemoQ.exe.
 * 3) Install MemoQ Translator Pro.

Now you can use both programs at the same time - but make sure you use different resources.

Avoiding hangs when copying large blocks of text from source to target
If you want to copy large blocks of text from the source to the target during the translation process, MemoQ may currently hang or crash if the Quality Assurance module is running in the background.

Go to the Project QA Settings in the main settings area and make certain that none of the boxes above the tabs are checked. Wait until you really get to the point where you really want to start doing quality assurance checking before you actually start to run the QA features.

Using auto-translatables for number format conversion
Among other things, the auto-translatables function in MemoQ can be used to convert numbers from one language format to another. For example, English uses the comma as a thousands separator, and the full stop as a decimal separator. Italian uses them the opposite way. With the proper auto-translatable rules set, MemoQ will provide the "localized" version of numbers found in the source segment. These localized numbers are shown in the Translation results list. These auto-translated hits can be inserted quickly into the translation just like hits from translation memories or term bases. Auto-translatables are also used by the fragment assembly function.

Auto-translatables can be set at the project level (in the settings page of the project) or the global level for every project with the same source and target languages (in Tools menu > Options > Auto-translatables).

English to Danish/Dutch/Croatian/German/Romanian/Slovenian/Spanish
Below are the rules to enter for a project translated from English to the above (and possibly other) languages. It will localize numbers containing decimal separators or thousands separators (not both). The rules need to be entered exactly as below in exactly the same order to ensure that they work correctly. For information on entering auto-translatable rules, see the MemoQ help topics under Language specific settings > Auto-translations.

Rule 1 (changes 1.234 to 1,234)

Auto-translatable rule:

Replace order rule:

Explanation: If a sequence of digits is followed by a full stop and another sequence of digits, this rule will replace the full stop with a comma.

Rule 2 (changes 12,345,678 to 12.345.678)

Auto-translatable rule:

Replace order rule:

Explanation: If a sequence consisting of 1 to 3 digits is followed by a comma, which is followed by three digits, another comma and thrre digits again, the rule will replace the commas with full stops.

Rule 3 (changes 12,345 to 12.345)

Auto-translatable rule:

Replace order rule:

Explanation: If a sequence consisting of 2 to 3 digits is followed by a comma, which is followed by three digits, the rule will replace the comma with a full stop.

title: CAT-Tools/MemoQ/Tips and Tricks


text:
User:Vininche

$$ \left\{ \begin{matrix} \vec \nabla \times \vec B = \mu_0 \vec j + \epsilon_0 \mu_0 \frac {\partial \vec E}{\partial t}\\ \vec \nabla \times \vec E = -\frac {\partial \vec B}{\partial t}\\ \vec \nabla \cdot \vec B = 0\\ \vec \nabla \cdot \vec E = \frac {\rho}{\epsilon_0}\\ \end{matrix} \right. $$J. C. Maxwell M. C. Escher & Sir Roger Penrose "At last the anchor was up, the sails were set, and off we glided......"

- Herman Melville,Moby Dick, Cap. XXII

"Life's but a walking shadow, a poor player That struts and frets his hour upon the stage And then is heard no more: it is a tale Told by an idiot, full of sound and fury, Signifying nothing."

- William Shakespeare,Macbeth,Act V,scene V

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

title: User:Vininche


text:
Linux Guide/Linux and Bluetooth

Forewords
The following is just a simple example on how to connect a Bluetooth device, in this case a Nokia phone, in a Linux environment.

For the purpose of this article we assume to have installed Linux Mandrake 10.0 (Kernel 2.6.13, X86) on our computer.

Configuration and Connection
First we need the Bluez protocol, usually available as a RPM package on your distribution, then we have to start bluetooth service:

[user@domain.org user]# service bluetooth start

now it's necessary to setup the PIN code and (if you want) the local device name link, for that purpose we edit (e.g. using JOE) the file /etc/bluetooth/hcid.conf:

[user@domain.org user]# joe /etc/bluetooth/hcid.conf

modify the following excerpts:

excerpt for PIN:

# PIN helper pin_helper /etc/bluetooth/mypin.sh;

where mypin.sh is a file created ad-hoc.

Excerpt for name:

# Local device name # %d - device id # %h - host name name "userdomain (%d)";

N.B.: file mypin.sh contains:

#!/bin/bash echo "PIN:XXX"

where XXXX means your PIN.

Now it's time to search for devices:

[user@domain.org user]# hcitool scan

that should returns something like:

12:34:56:78:90:12 user1

in other words bdaddr (BT address) and device name, please take note of bdaddr, now it's time to discover available services an the remote device and on which channels:

[utente@dominio.org utente]# sdptool records 12:34:56:78:90:12

depending on the type of device we are analysing the request returns a long list of profiles, in this case we are interested in the dialup one, so let see it available on channel 1:

Service Name: Dial-Up Networking Service RecHandle: 0x10007 Service Class ID List:  "Dialup Networking" (0x1103) Protocol Descriptor List:  "L2CAP" (0x0100)  "RFCOMM" (0x0003)    Channel: 1 Language Base Attr List:  code_ISO639: 0x454e  encoding: 0x6a  base_offset: 0x100 Profile Descriptor List:  "Dialup Networking" (0x1103)    Version: 0x0100

then:

[user@domain.org user]# rfcomm bind 0 12:34:56:78:90:12 1

in other words I bind a virtual serial port, rfcomm0 (/dev/bluetooth/rfcomm/0), by means of the tool rfcomm to the remote device modem, not connected yet but ready for software's requests, let see:

[user@domain.org user]# rfcomm show 0

that results in:

rfcomm0: 12:34:56:78:90:12 channel 1 clean

BT modem ready as serial peripheral at /dev/bluetooth/rfcomm/0

No need to mention that you in the meantime have already accepted the connection on your remote device.

Or to connect from the linux side, prepare an agent to respond properly to a pin request, then connect:

[user@domain.org user]# bluetooth-agent 1234 12:34:56:78:90:12 [user@domain.org user]# rfcomm connect 0 12:34:56:78:90:12

Then, in another terminal, you can for example open a terminal on /dev/rfcomm0:

[user@domain.org user]# minicom /dev/rfcomm0

Bluetooth device as a modem
To use this ready to use device as a modem I suggest as dialer the program wvdial, for this purpose we need to edit it's configuration file /etc/wvdial.conf, like this:

[Dialer Defaults] Modem = /dev/bluetooth/rfcomm/0 Baud = 460800 Dial Attempts = 1 Init1 = ATZ Init3 = AT+CGDCONT=1,"IP","web.omnitel.it" Phone = *99# Carrier Check = no Stupid Mode = yes Username = "" Password = ""

N.B.: this example is from a working configuration for Vodafone Italy on a Nokia phone, for different countries/operators/brand configuration, please google with keyword +CGDCONT and operator's name, mostly you need to modify just the string

Init3 = AT+CGDCONT=1,"IP","web.omnitel.it"

according to your operator's specifications, and

Phone = *99#

according to your phone's brand.

Dialup and connect...:

[user@domain.org utente]# wvdial

Good Luck!!!

Other useful commands
BT_ADDRESS may be like, 00:89:34:62:67:52
 * hciconfig
 * hcitool scan
 * hcitool info BT_ADDRESS
 * l2ping BT_ADDRESS
 * sdptool browse BT_ADDRESS
 * sdptool search DUN
 * hciattach -l

title: Linux Guide/Linux and Bluetooth


text:
Cookbook:Sausage and Tortellini Soup

| American cuisine | Pasta | Soups

Ingredients

 * Vegetable spray or 1 teaspoon olive oil
 * 2 packages (2½ pounds) sweet Italian sausage
 * 2 cartons (1 pound) sliced, fresh mushrooms
 * 1 bag (9 ounces) fresh baby spinach
 * 2 cans (1¾ pounds) diced tomatoes
 * 2 cartons (2 quarts / 4 pounds) low-sodium chicken broth
 * 1 package (1¾ pounds) fresh Three Cheese Tortellini (from dairy case)
 * Grated Parmesan cheese for garnish (optional)

Procedure

 * 1) Coat a large stock pot with vegetable spray or 1 teaspoon olive oil.
 * 2) Remove sausage from casings and heat over medium heat in stock pot until sausage is crumbled and no longer pink.
 * 3) When the sausage is completely cooked, add sliced mushrooms and cook, stirring occasionally, until they are sautéed.
 * 4) Add the entire bag of baby spinach.
 * 5) Cook, stirring occasionally, until spinach is lightly sautéed.
 * 6) Add diced tomatoes and stir thoroughly.
 * 7) Add chicken broth and bring to a boil.
 * 8) Add tortellini and simmer on low for 10–15 minutes until the pasta is cooked.
 * 9) Ladle into soup bowls and sprinkle generously with Parmesan cheese.

title: Cookbook:Sausage and Tortellini Soup


text:
User talk:ChristianC~enwikibooks

Hello and welcome to Wikibooks!

Here are some tips to help you get started:
 * You should sign your name on Talk and vote pages using four tildes, like this: ~~~~.
 * Remember to conduct any editing experiments in the sandbox.
 * If you're a Wikipedian, see Wikibooks for Wikipedians for a primer on how things work here (it's a little different).
 * If you want to base your work here on materials from Wikipedia, please use WB:RFI to bring the material over in compliance with the GFDL.
 * If you're an instructor and plan on using wikibooks for a class project, see Guidelines for class projects
 * Please say hello at the Staff Lounge with any questions or ideas.
 * Eventually, you might want to read the Manual of Style and Policies and Guidelines.
 * Please take a look at Naming policy before starting a new book.
 * Remember to maintain a Neutral point of view.
 * Explore, be bold in editing pages, and have fun!

You will find more resources in Community Portal. If you want to ask a question, visit the Study help desk, the Staff lounge, IRC channel or ask me personally on my talk page. For site news, see the Bulletin board. It might be an idea if you add this page to your "watchlist" so that you can see when any new information is posted there.

Good luck! -- Herby talk thyme 10:48, 15 February 2007 (UTC)

Wikiversity/Wikibooks
I see you have created School of Very Small Information Systems/SS2007. Unfortunately Wikiversity is now a site in its own right at Wikiversity and your material probably should be there so that it is incorporated in the way you wish it to be - thanks -- Herby talk thyme 10:48, 15 February 2007 (UTC)

Your account will be renamed
Hello,

The developer team at Wikimedia is making some changes to how accounts work, as part of our on-going efforts to provide new and better tools for our users like cross-wiki notifications. These changes will mean you have the same account name everywhere. This will let us give you new features that will help you edit and discuss better, and allow more flexible user permissions for tools. One of the side-effects of this is that user accounts will now have to be unique across all 900 Wikimedia wikis. See the announcement for more information.

Unfortunately, your account clashes with another account also called ChristianC. To make sure that both of you can use all Wikimedia projects in future, we have reserved the name ChristianC~enwikibooks that only you will have. If you like it, you don't have to do anything. If you do not like it, you can pick out a different name.

Your account will still work as before, and you will be credited for all your edits made so far, but you will have to use the new account name when you log in.

Sorry for the inconvenience.

Yours, Keegan Peterzell Community Liaison, Wikimedia Foundation 23:06, 17 March 2015 (UTC)

Renamed
 This account has been renamed as part of single-user login finalisation. If you own this account you can |log in using your previous username and password for more information. If you do not like this account's new name, you can choose your own using this form after logging in: . -- Keegan (WMF) (talk) 04:48, 19 April 2015 (UTC)

title: User talk:ChristianC~enwikibooks


text:
IB Maths Studies

The IB Mathematical Studies SL curriculum consists of eight compulsory topics (for first examinations in 2006) In addition, students are required to take part in a project that requires them to take measurements or collect data, and subsequently analyse and evaluate it in a report.

Topics
Topic 1—Introduction to the graphic display calculator. Teaching Hours - 3

Topic 2—Number and algebra. Teaching Hours - 14

Topic 3—Sets, Logic, and Probability. Teaching Hours - 20

Topic 4—Functions. Teaching Hours - 24

Topic 5—Geometry and trigonometry. Teaching Hours - 20 Topic 6—Statistics. Teaching Hours - 24 Topic 7—Introductory differential calculus. Teaching Hours - 15

Topic 8—Financial mathematics. Teaching Hours - 10

/Project/ Internal Assessment. Teaching Hours - 20

Total Hours - 150

Assessment
Mathematical Studies SL is graded through an external and internal assessment. The external assessment, worth 80% of the final mark, is composed of a Paper 1 and a Paper 2. The internal Assessment is marked by your teacher, and is worth the remaining 20% of your mark.

Paper 1
Composed of 15 required short answer questions based on the entire syllabus. Weighted equally with Paper 2 (worth 40% of final mark)

Exam duration: 1 hour 30 minutes.

Paper 2
Composed of 6 required extended response questions based on the whole syllabus. Accounts for 40% of the candidates final mark.

Exam Duration: 1 hour 30 minutes

title: IB Maths Studies


text:
Cookbook:Sweet Mole with Vanilla Bean Ice Cream

| American cuisine | Mexican cuisine | Vegetarian Cuisine | Dessert

Ingredients

 * 1 whole dried ancho chile
 * ¾ cups (4 ounces) piloncillo (brown sugar cane)
 * 1 clove
 * ½ teaspoon ground cinnamon
 * 4 ounces semi-sweet dark chocolate bar, cut into pieces
 * 2 cups high-quality vanilla bean ice cream

Procedure

 * 1) Wash, devein, and remove seeds from chile ancho.
 * 2) Boil the chile, then blend with the smallest amount of water possible.
 * 3) Strain off water.
 * 4) In a saucepan, add pureed chile, piloncillo, clove, cinnamon and chocolate.
 * 5) Boil for 3 minutes.
 * 6) Remove clove.
 * 7) To serve, allow vanilla ice cream to soften slightly in a bowl and stir in mole.


text:
User talk:Shyam

Hello and welcome to Wikibooks!

Here are some tips to help you get started:
 * You should sign your name on Talk and vote pages using four tildes, like this: ~~~~.
 * Remember to conduct any editing experiments in the sandbox.
 * If you're a Wikipedian, see Wikibooks for Wikipedians for a primer on how things work here (it's a little different).
 * If you want to base your work here on materials from Wikipedia, please use WB:RFI to bring the material over in compliance with the GFDL.
 * If you're an instructor and plan on using wikibooks for a class project, see Guidelines for class projects
 * Please say hello at the Staff Lounge with any questions or ideas.
 * Eventually, you might want to read the Manual of Style and Policies and Guidelines.
 * Please take a look at Naming policy before starting a new book.
 * Remember to maintain a Neutral point of view.
 * Explore, be bold in editing pages, and have fun!

You will find more resources in Community Portal. If you want to ask a question, visit the Study help desk, the Staff lounge, IRC channel or ask me personally on my talk page. For site news, see the Bulletin board. It might be an idea if you add this page to your "watchlist" so that you can see when any new information is posted there.

Good luck! -- Herby talk thyme 12:28, 15 February 2007 (UTC)

title: User talk:Shyam


text:
CAT-Tools/DéjàVu X/assign toolbar buttons to the Filter on Selection feature

Filter on Selection is one of the best features of DVX.

By default, the Filter on Selection feature is only available from the Context menu in the translation grid. One drawback of this feature, that one easily forgets that it is activated, because there is no visual indication on-screen. By customizing the interface and adding the functions to the toolbar, you will always have a visual indication when the FoS feature is activated.

http://tech.groups.yahoo.com/group/dejavu-l/files/Miscellaneous/filter_buttons.zip
 * Download the zip file containing the buttons created by Allessandra Muzzi:
 * Unzip the file and follow the instructions in the readme.txt file

When you have activated the Filter on Source/Target button, simply clicking the button again will deactivate it.


text:
General Astronomy/An Accelerating Universe

Space is flat. This is shown by the density of matter, and cosmic background radiation.

The radiation left over from the Big Bang is about 3 Kelvin.

The rate of expansion of the universe is greater in proportion to the distance.

Other Cosmological Models
Throughout history, astronomers have been seeking models of the universe. The three best known are those by Ptolemy, Newton, and Einstein. They all had an explanation why the universe didn't collapse.

Ptolemy's model had the Earth at the center, surrounded by an "8th Sphere" of stars. The sphere held up the stars, so the universe didn't collapse.

Newton's universe was infinitely large. He postulated a universe where the gravitational force was in balance. In an infinitely large area, there is no center of mass; therefore, the universe could not collapse. Like many of his time, Newton also believed in an infinitely old universe. Given an infinite amount of time, if the universe was going to collapse, it would've done it already.

Flaws with Newton's model were apparent even in his time. Heinrich Olbers wondered: If the universe is infinitely large and infinitely old, why isn't the night sky as bright as the sun? This question became known as Olbers' Paradox. Olbers' proposed solution was that the universe was filled with dust, obscuring some of the starlight. However, this only appeared to solve the problem. Dust absorbs and radiates energy, so that the light being obscured would be transmitted anyway.

Einstein's model for the universe was a constant size. He postulated a repulsive $$\lambda$$ (lambda) force that counterbalanced gravity and kept everything from collapsing.

Immanuel Kant, a philosopher, proposed a disc-shaped universe.


text: Template:Tajik

title: Template:Tajik


text:
Tajik

Хуш омадед! (/xuʃ omaded/)
Welcome, to Wikibooks Tajik. This is a work in progress, but can help you learn some Tajik. Don't hesitate to add little things or correct mistakes (in English or Tajik).

 * Introduction Learn about the Tajik Language, and why you should learn it.
 * Lesson 1 - the alphabet, and Tajik words that are similar to English words, familiar names and places
 * Lesson 2 - introducing yourself
 * Lesson 3 - Grammar
 * Lesson 4 - Vocabulary—alphabetical
 * Vocabulary
 * Tajik Names
 * Useful Words and Expressions.

See the alphabet for an overview of the alphabet and the pronunciation. It also contains information about typing Cyrillic characters. Check Loanwords and geographical names for some stuff to practice your Cyrillic.

Wikipedia has an academic article on the Tajik language. There is also a Wikipedia in Tajik.

Grammar

 * Numbers
 * Declensions
 * Adjectives
 * Conjugations
 * Prepositions
 * Verbal Aspect
 * Pronouns
 * Interrogative Pronouns
 * Personal Pronouns
 * Possessive Pronouns
 * Various Stuff is a collection of stuff that can be used at other places later.

title: Tajik


text:
Tajik/Introduction

Welcome to the English Wikibook for learning the Tajik Language.

This course requires no prior knowledge of Tajik. It aims to teach grammar, vocabulary, common phrases, conversational language, and formal/literary Tajik. By the end, you should be able to read and write Tajik but will probably need a human teacher to help with listening and speaking. The book is meant to be read starting with lesson 1 and moving forward. It will move slowly.

The Persian Language
The Tajik language (sometimes written Tadjik or Tadzhik; тоҷикӣ, تاجیکی, tojikí [tɔːdʒɪˈki]) is a variant of the Persian language spoken in Central Asia. It is an Indo-European language, more specifically part of the Iranian language group. Speakers of Tajik live mostly in Tajikistan, Uzbekistan, Afghanistan, and western Pakistan. Tajik is the official language of Tajikistan. It is written in the Cyrillic alphabet.

Knowledge of the Tajik language will let you fully appreciate a rich and diverse body of literature.

Vocabulary and grammar
In learning to read or speak any language, the two aspects to be mastered are vocabulary and grammar. Acquiring vocabulary is a matter of memorization. Children learn thousands of words of their native language by the time they are conscious of the learning process, so it is easy to underestimate importance of having a large vocabulary. This process can be reactivated by immersion: moving to where the language is spoken and one’s native tongue cannot be used for daily communication.

Without the opportunity to move to a Tajik-speaking area, a student must make a substantial effort to learn the meaning, pronunciation, and proper use of words. Be sure to learn all of the vocabulary words in each lesson. Early lessons have simple sentences because the student’s vocabulary is presumably limited, but more complex sentences in later lessons demonstrate more typical Tajik. It may be helpful to translate these using a Tajik-English dictionary. Access to a print dictionary is very helpful. Other sources of Tajik, such as newspapers, magazines, and web sites can help to build vocabulary and to develop a sense of how Tajik sentences are put together.

title: Tajik/Introduction


text:
Tajik/Lesson 1

Some words that are very similar in Tajik and English
Try to sound out each of the following words using the phonetic mapping above.

title: Tajik/Lesson 1


text:
XForms/eXist

eXist is a native XML database that has a full REST interface. This allows you to use eXist to save form data without writing any middleware glue.

eXist REST interface
eXist provides a full REST interface that is easy to call from an XForm.

eXist WebDAV interface
eXist also provides a full WebDAV interface. This allows you to do HTTP "PUT" operations directly from your forms.

eXist Example
In this example, we will create a user named "juser" (Jane User) and setup a collection to read and write form data.

Sample Program
To run this program, just install eXist from the web site. use the eXist admin menu to create a user called "juser". Then create a home collection for juser at /db/home/juser. Then login as juser and create a collection called "test". You will put a form and instance data into this file.

To read and write instance data into a form just use the following example:

Note that if the data is in the same collection as the form (not a good long term design) you can use a relative path reference. Also note that we are doing an HTTP PUT operation to the webdav (not rest) interface to exist.

Using eXist URLs
It is easy to load XML data directly into your XForms application. In the instance statement in your model just add a src attribute and put a path name to the file you want to edit. The key is to put the word "rest" in the URL when you are reading data into your form:

Always put the word "webdav" in the URL path when doing an HTTP PUT.

http://localhost:8080/exist/ webdav/db/home/juser/test/data.xml

That is all there is to it!

For more information see the eXist manual on using the REST and WebDAV interfaces for eXist.

Using XQuery to return Document IDs
When using an XML database, you sometimes wish to have the database receive an XML document and store it in the correct location based on business rules such as the content of an XML document and the date. This can be done in relational databases using stored procedures.

XQuery can be thought of as an XML-oriented stored procedure. eXist allows you to save directly to the URL of an XQuery and the XQuery can store the document based on a number of rules.

Here is an example eXist XQuery that that takes HTTP POST and creates a path name to a collection based on the county in input document and the date. After it saves the file and checks that the save has worked it increments a counter similar to the AUTOINCREMENT property of some relational databases.

Processing the Results
This XQuery returns an XML message such as the following

Assuming you have a hostname, port and application-name variables are set up, the XForms application would contain the following code:

Setting the mime type for XQuery Results
If you want your XQuery to return the correct mime type put the following in the preamble:

(This suggestion from Kurt Cagle)

title: XForms/eXist


text:
CAT-Tools/DéjàVu X/Stemming

DVX should recognie the German 'Hauses' as a form of 'Haus'. (Fuzzy terminology recognition isn't of much use for German.) (Hans List)

title: CAT-Tools/DéjàVu X/Stemming


text:
User talk:216.20.1.211

Welcome to Wikibooks. We invite everyone to contribute constructively to our collection. Take a look at the welcome page if you would like to learn more about contributing. However, unconstructive edits are considered vandalism, and if you continue in this manner you may be blocked from editing without further warning. Please stop, and consider improving rather than damaging the hard work of others. Thanks. -- Herby talk thyme 15:19, 15 February 2007 (UTC)

And maybe you should know - I am a fencer, I am not gay and I am an admin -- Herby talk thyme 15:19, 15 February 2007 (UTC)

title: User talk:216.20.1.211


text:
XForms/Apache

The Apache web server is the most popular web server on the Internet. It provides high-performance web pages serving and is very secure.

By default, the out-of-the box Apache server does not allow users to write files to a web server. This is done for security reasons.

WARNING: The following should only be used on Intranet servers and should be reviewed by security professionals in your organizations.

Steps to Configure Apache HTTP Server to Enable "PUT" Operations

 * 1) Download and install the HTTP Server from apache.org. I am using v2.2.4
 * 2) Verify that it is serving up regular xhtml files like you think it should
 * 3) Stop the service
 * 4) In your httpd.conf uncomment the LoadModule for dav_module and dav_fs_module also uncomment the line "Include conf/extra/httpd-dav.conf" so that the httpd-dav.conf is loaded
 * 5) edit conf/extras/httpd-dav.conf and change the 'uploads' alias and directory to be what you want them to be. They should match, of course.
 * 6) To authenticate users you can use the htpasswd command line program to create the password and put it in the uploads directory. Of course, you can also disable password protection during the testing phase of your project.

Sample httpd-dav.conf file
This is what the beginning of my httpd-dav.conf looked like when it was done:

DavLockDB "E:/httpd/Apache2.2/var/DavLock" Alias /uploads "C:/www/xforms/uploads"

 Dav On

Order Allow,Deny Allow from all

 * 1) AuthType Digest

AuthType Basic AuthName DAV-upload

AuthUserFile "C:/www/xforms/uploads/user.passwd"
 * 1) You can use the htdigest program to create the password database:
 * 2) htdigest -c "E:/httpd/Apache2.2/user.passwd" DAV-upload admin
 * AR: I used htpasswd -> htpasswd -c "C:/www/xforms/uploads/user.passwd" admin
 * 1) AuthUserFile "E:/httpd/Apache2.2/user.passwd"

 require user admin
 * 1) Allow universal read-access, but writes are restricted
 * 2) to the admin user.

Restarting Apache
After you make any changes to the Apache config files you must restart Apache using the Apache restart command such as:

apachectl restart

or

apachectl stop apachectl start

If you have problems, make sure to check the Apache log file. If you get errors you may not have the permissions set correctly for the folder that your form is writing to.

Checking the Access Log File
If your forms do not save, you can also check the Apache access log files. They are usually located in a directory such as: Windows: C:\Program Files\Apache Software Foundation\Apache2.2\logs\access.log

If you see a line such as: 192.168.1.105 - - [08/Feb/2007:16:58:01 -0600] "PUT /forms/data.xml HTTP/1.1" 405 235

This indicates that you are getting a HTTP 405 error: Method Not Allowed. A 405 status code is returned when the client has tried to use a "request method" such as PUT or POST that the server does not allow. This means you don't yet have your configuration correct and that your XForms will not save its data.

title: XForms/Apache


text:
XForms/IIS

The authors have not yet tried to configure IIS to work with XForms but there is plenty of documentation on the web about how to do this. One example is:

This example includes screen images of the IIS administration tool.

IIS also has an access log file that will put 405 errors in it if there are still problems.

Any contributions would be helpful.

title: XForms/IIS


text:
User:Tpartee7712

Hello Tiffany, I saw that you had tried to sign up for your article. Make sure you are logged in and then do exactly what you tried to do again except use the tildae key - it is located under the escape key. It looks like this ~. It should work. Emily

title: User:Tpartee7712


text:
Octave Programming Tutorial/Getting started

The aim of this tutorial is to give you a quick introduction to basic Octave and to show that you know a lot of it already. If you should ever get stuck or need more information on an Octave function or command, type

help command

at the Octave prompt. is the name of the Octave command or function on which to find help. Be warned though that the descriptions can sometimes be a bit technical and filled with jargon.

Starting Octave
Type  in a terminal window to get started. You should see something like the following, depending on the version that you have installed: GNU Octave, version 3.6.4.0 Copyright (C) 2013 John W. Eaton and others. This is free software; see the source code for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'. Additional information about Octave is available at http://www.octave.org. Please contribute if you find this software useful. For more information, visit http://www.octave.org/get-involved.html Report bugs to  (but first, please read http://www.octave.org/bugs.html to learn how to write a helpful report). octave:1> To exit Octave, type quit or exit.

Entering commands
The last line above is known as the Octave prompt and, much like the prompt in Linux, this is where you type Octave commands. To do simple arithmetic, use  (addition),   (subtraction), (multiplication),  (division), and   (exponentiation).

Many mathematical functions are available and have obvious names (with many of those similar to other programming languages). For example, we have:

 * trigonometric functions :,  ,
 * inverse trigonometric functions:,  ,
 * natural and base 10 logarithms: ,
 * exponentiation:
 * absolute value:

Various constants are also pre-defined:,   (Euler's number),   and   (the imaginary number sqrt(-1)),   (Infinity),   (Not a Number - resulting from undefined operations, such as  .)

Here are some examples showing the input typed at the prompt and the output returned by Octave.

Some things to note:
 * Octave requires parentheses around the input of a function (so,  is fine, but  is not).
 * Any spacing before and after arithmetic operators is optional, but allowed.
 * Not all Octave functions have obvious names (e.g.  above). Don't panic for now. You will get to know them as we go along.

Plotting
You are going to plot the following pictures using Octave:

Figure 1 contains a plot of sin x vs x and is generated with the following commands. While this is a simple example, it is meant to illustrate the basic functionality. We will see more elaborate examples later.

x = linspace(0, 2*pi, 100); y = sin(x); plot(x, y); figure;

The command that actually generates the plot is, of course,. Before executing this command, we need to set up the variables, x and y. The  function simply takes two vectors of equal length as input, interprets the values in the first as x-coordinates and the second as y-coordinates and draws a line connecting these coordinates.

The first command above,, uses the   function to make a vector of equally spaced intervals (sometimes also called "linearly spaced values"). The first value in the vector is 0, the final value is 2π and the vector contains 100 values. This vector is assigned to the variable named.

The second command computes the sin of each value in the vector variable,, and stores the resulting vector in the variable.

(As an aside: the name of a variable can be any sequence of letters, digits and underscores that does not start with a digit. There is no maximum length for variable names, and the case of alphabetical characters is important, i.e.  and   are two different variable names.)

Exercise
Plot the function $$y = \lfloor x\rfloor$$ for $$x\in[0, 15]$$. (This is Figure 2). Note : The graph may appear slightly inaccurate if the length(3rd) parameter of linspace is not sufficiently large. See the next heading for more information.

More on commands
The following commands and functions are useful for setting up variables for plotting 2D graphs.

 * creates a vector of evenly (linearly) spaced values.

Usage:. The  parameter is optional and specifies the number of values in the returned vector. If you leave out this parameter, the vector will contain 100 elements with  as the first value and stop as the last.

 * plots a 2-dimensional graph.

Usage:  where   and   are vectors of equal length.

 * creates a new plotting window.

This is useful for when you want to plot multiple graphs in separate windows rather than replacing your previous graph or plotting on the same axes.

 * and  sets whether you want successive plots to be drawn together on the same axes or to replace the previous plot.

 * The  at the end of a line suppress the display of the result. Try to remove it, and see !

Example
We are going to plot Figures 3 and 4. Figure 3 contains the 3 trigonometric functions on one set of axes. Figure 4 contains the sum of these 3 functions.
 * $$\cos 2x$$,
 * $$\sin 4x$$, and
 * $$2\sin x$$

Firstly, we use  to set up a vector of x-values. octave:1> x = linspace(0, 2*pi);

Then, we compute the y-values of the 3 functions. octave:2> a = cos(2*x); octave:3> b = sin(4*x); octave:4> c = 2*sin(x);

The following plots the first graph. octave:5> figure; octave:6> plot(x, a); octave:7> hold on; octave:8> plot(x, b); octave:9> plot(x, c);

We use line 5 to tell Octave that we want to plot on a new set of axes. It is good practice to use  before plotting any new graph. This prevents you from accidentally replacing a previous plot with the new one.

Note that on line 7,  is used to tell Octave that we don't want to replace the first plot (from line 6) with subsequent ones. Octave will plot everything after  on the same axes, until the   command is issued.

The figure you see shows all three plotted functions in the same color. To let Octave assign different colors automatically plot all functions in one step. octave:10> plot(x, a, x, b, x, c);

Finally, we plot the second graph. octave:11> figure; octave:12> hold off; octave:13> plot(x, a+b+c);

Line 11 creates a new graph window and line 12 tells Octave that any subsequent plots should simply replace previous ones. Line 13 generates the plot of the sum of the 3 trigonometric functions. A small note for mac users, if plot figure commands do not work first use this command: > setenv ("GNUTERM", "x11")

Exercises

 * Plot the absolute value function for $$x\in[-5, 5]$$.
 * Plot a circle of radius 1, centered at the origin. (This is not so easy.)
 * Plot your favourite function(s) like sin and cos

Warning
If you try (or have tried) to plot something like $$x^2$$ or $$\sin x \times\cos x$$, you will run into trouble. The following error messages are common. In the case of : error: for A^b, A must be square In the case of : error: operator *: nonconformant arguments (op1 is 1x100, op2 is 1x100)

This error occurs whenever you try multiply or divide two vector variables (remember that  and   are vectors). For now, you can do one of two things.
 * 1) use plot(sin(x).*cos(x)) - notice the '.' between sin(x) and *. For x^2 plot(x.*x)
 * 2) Read the section on vectors and matrices.

Challenge
Since Octave is a numerical (and not symbolic) mathematics package, it does make numerical errors and does not handle some operations well. To confirm this, make a plot of tan x, for x between -π and π. What is wrong with the resulting picture?

Your task is to generate the (much better looking) graph below using what you have learned so far and the  function. can be used to adjust which part of the plot is actually displayed on screen. Use the command  to determine how this function works.

It might take some thinking to get the asymptote lines at $$x = \pm\pi/2$$ right. You can use  to find out how to plot dotted lines. (Try to make the plot yourself before looking at the solution below.)

Following commands could be used to generate the plot shown above.

octave:1> x_part_left = linspace(-pi,  -pi/2-0.001, 100); octave:2> x_part_mid  = linspace(-pi/2, pi/2, 100); octave:3> x_part_right = linspace( pi/2+0.001, pi,  100); octave:4> plot(x_part_left, tan(x_part_left)); octave:5> hold on; octave:6> plot(x_part_mid, tan(x_part_mid)); octave:7> plot(x_part_right, tan(x_part_right)); octave:8> y_limit = 4; octave:9> axis([-pi, pi, -y_limit, y_limit]); octave:10> plot(linspace(-pi/2, -pi/2, 100), linspace(-y_limit, y_limit, 100), '.'); octave:11> plot(linspace( pi/2, pi/2, 100), linspace(-y_limit, y_limit, 100), '.'); octave:12> hold off;

The horizontal plot range -π to π is split into three vectors such that singular points are skipped for the plot. In lines 4-7 the separate parts of the tan function are plotted. Thereafter, in line 8, we choose a limit for the y-axis and use it to constrain the vertical plot range (using the  command [line 9]). Finally we add the asymptote lines at $$x = \pm\pi/2$$ in a dotted style (lines 10 & 11).

Script files
It is useful to be able to save Octave commands and return them later on. You might want to save your work or create code that can be reused (by yourself or somebody else). Such files are known as Octave script files. They should be saved with a  extension so that Octave can recognise them. (The  extension is used because MATLAB calls its script files M-files and Octave is based on MATLAB.)

To run an existing script in Octave, you have to be in the same directory as the script file and type in the name of the file without the   in Octave. For example, if I have a script called   in an   directory, the following two commands will execute the script.

chdir('~/octave'); % This changes to the octave directory myscript;

Note that the  command is necessary only if you are not already inside that directory when running Octave.

In the following section you will be shown a number of new statements that you can use to make your Octave code much more powerful. A number of example script files are provided and you should save these into a directory for later use. A good idea is to create a directory called  in your home directory and store all your Octave files in there.

Return to the Octave Programming tutorial index


text:
Octave Programming Tutorial/Vectors and matrices

= Creating vectors and matrices = Here is how we specify a row vector in Octave: octave:1> x = [1, 3, 2] x = 1 3  2

Note that
 * the vector is enclosed in square brackets;
 * each entry is separated by an optional comma.    results in the same row vector.

To specify a column vector, we simply replace the commas with semicolons: octave:2> x = [1; 3; 2] x = 1  3   2

From this you can see that we use a comma to go to the next column of a vector (or matrix) and a semicolon to go to the next row. So, to specify a matrix, type in the rows (separating each entry with a comma) and use a semicolon to go to the next row. octave:3> A = [1, 1, 2; 3, 5, 8; 13, 21, 34] A = 1  1   2    3   5   8   13  21  34

= Operators = You can use the standard operators to matrices, vectors and scalars with one another. Note that the matrices need to have matching dimensions (inner dimensions in the case of multiplication) for these operators to work.
 * add ,
 * subtract, and
 * multiply

octave:4> A' ans = 1  3  13    1   5  21    2   8  34 (Note: this is actually the complex conjugate transpose operator, but for real matrices this is the same as the transpose. To compute the transpose of a complex matrix, use the dot transpose  operator.)
 * The transpose operator is the single quote: . To continue from the example in the previous section,

 * The power operator can also be used to compute real powers of square matrices.

Element operations
When you have two matrices of the same size, you can perform element by element operations on them. For example, the following divides each element of A by the corresponding element in B: octave:1> A = [1, 6, 3; 2, 7, 4] A = 1 6  3   2  7  4 octave:2> B = [2, 7, 2; 7, 3, 9] B = 2 7  2   7  3  9 octave:3> A ./ B ans = 0.50000 0.85714  1.50000   0.28571  2.33333  0.44444 Note that you use the dot divide  operator to perform element by element division. There are similar operators for multiplication and exponentiation.

Let's introduce a scalar for future use.

a = 5;

The dot divide operators can also be used together with scalars in the following manner. C = a ./ B returns a matrix, C where each entry is defined by

$$C_{ij} = \frac{a}{B_{ij}}$$

i.e. a is divided by each entry in B. Similarly C = a .^ B return a matrix with

$$C_{ij} = a^{B_{ij}}$$

= Indexing = You can work with parts of matrices and vectors by indexing into them. You use a vector of integers to tell Octave which elements of a vector or matrix to use. For example, we create a vector octave:1> x = [1.2, 5, 7.6, 3, 8] x = 1.2000 5.0000  7.6000  3.0000  8.0000 Now, to see the second element of x, type octave:2> x(2) ans = 5 You can also view a list of elements as follows. octave:3> x([1, 3, 4]) ans = 1.2000 7.6000  3.0000 This last command displays the 1st, 3rd and 4th elements of the vector x.

To select rows and columns from a matrix, we use the same principle. Let's define a matrix octave:4> A = [1, 2, 3; 4, 5, 6; 7, 8, 9] A = 1 2  3   4  5  6   7  8  9 and select the 1st and 3rd rows and 2nd and 3rd columns: octave:5> A([1, 3], [2, 3]) ans = 2 3   8  9

The colon operator can be used to select all rows or columns from a matrix. So, to select all the elements from the 2nd row, type octave:6> A(2, :) ans = 4 5  6

You can also use  like this to select all Matrix elements:

octave:7> A ans = 1  2   3   4   5   6   7   8   9

Ranges
We can also select a range of rows or columns from a matrix. We specify a range with start:step:stop

You can actually type ranges at the Octave prompt to see what the results are. For example, octave:3> 1:3:10 ans = 1  4   7  10

The first number displayed was, the second was  , the third,. And the last number was less than or equal to.

Often, you simply want the step size to be 1. In this case, you can leave out the step parameter and type octave:4> 1:10 ans = 1  2   3   4   5   6   7   8   9  10

As you can see, the result of a range command is simply a vector of integers. We can now use this to index into a vector or matrix. To select the $$2\times 2$$ submatrix at the top left of A, use octave:4> A(1:2, 1:2) ans = 1 2   4  5

Finally, there is a keyword called  that can be used when indexing into a matrix or vector. It refers to the last element in the row or column. For example, to see the last column in a Matrix, you can use octave:5> A(:,end) ans = 3  6   9

= Functions = The following functions can be used to create and manipulate matrices.

Creating matrices

 * returns the lower triangular part of A.

 * returns the upper triangular part of A.

 * returns the $$n\times n$$ identity matrix. You can also use  to return $$m\times n$$ rectangular identity matrices.

 * returns an $$m\times n$$ matrix filled with 1s. Similarly,   returns $$n\times n$$ square matrix.

 * returns an $$m\times n$$ matrix filled with 0s. Similarly,   returns $$n\times n$$ square matrix.

 * returns an $$m\times n$$ matrix filled with random elements drawn uniformly from $$[0, 1]$$. Similarly,   returns $$n\times n$$ square matrix.

 * returns an $$m\times n$$ matrix filled with normally distributed random elements.

 * returns a row vector containing a random permutation of the numbers $$1, 2, \ldots, n$$.

octave:16> A = [1, 2, 3; 4, 5, 6; 7, 8, 9] A = 1 2  3   4  5  6   7  8  9 octave:17> x = diag(A) ans = 1  5   9 octave:18> diag(x) ans = 1 0  0   0  5  0   0  0  9
 * or . For a vector, x, this returns a square matrix with the elements of x on the diagonal and 0s everywhere else. For a matrix, A, this returns a vector containing the diagonal elements of A. For example,

 * returns a vector with n values, such that the first element equals a, the last element equals b and the difference between consecutive elements is constant. The last argument, n, is optional with default value 100.

octave:186> linspace(2, 4, 2) ans = 2  4 octave:187> linspace(2, 4, 4) ans = 2.0000  2.6667   3.3333   4.0000 octave:188> linspace(2, 4, 6) ans = 2.0000  2.4000   2.8000   3.2000   3.6000   4.0000

 * returns a vector with n values, such that the first element equals $$10^a$$, the last element equals $$10^b$$ and the ratio between consecutive elements is constant. The last argument, n is optional with default value 50.

octave:189> logspace(2, 4, 2) ans = 100  10000 octave:190> logspace(2, 4, 4) ans = 1.0000e+02  4.6416e+02   2.1544e+03   1.0000e+04 octave:191> logspace(2, 4, 5) ans = 1.0000e+02  3.1623e+02   1.0000e+03   3.1623e+03   1.0000e+04

Other matrices
There are some more functions for creating special matrices. These are Use  to find out more about how to use these functions.
 * (Hankel matrix),
 * (Hilbert matrix),
 * (Inverse of a Hilbert matrix),
 * (Sylvester matrix) - In v3.8.1 there is a warning: sylvester_matrix is obsolete and will be removed from a future version of Octave; please use hadamard(2^k) instead,
 * (Toeplitz matrix),
 * (Vandermonde matrix).

Changing matrices
octave:49> A = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12] A = 1  2   3   4    5   6   7   8    9  10  11  12 octave:50> fliplr(A) ans = 4  3   2   1    8   7   6   5   12  11  10   9
 * returns a copy of matrix A with the order of the columns reversed, for example,

octave:51> flipud(A) ans = 9 10  11  12    5   6   7   8    1   2   3   4
 * returns a copy of matrix A with the order of the rows reversed, for example,

octave:52> rot90(A) ans = 4  8  12    3   7  11    2   6  10    1   5   9
 * returns a copy of matrix A that has been rotated by (90n)° counterclockwise. The second argument, $$n$$, is optional with default value 1, and it may be negative.

octave:53> reshape(A, 2, 6) ans = 1  9   6   3  11   8    5   2  10   7   4  12
 * creates an $$m\times n$$ matrix with elements taken from A. The number of elements in A has to be equal to $$mn$$. The elements are taken from A in column major order, meaning that values in the first column ($$A_{11}, \ldots, A_{m1}$$) are read first, then the second column ($$A_{12}, \ldots, A_{m2}$$), etc.

octave:54> x = rand(1, 6) x = 0.25500 0.33525  0.26586  0.92658  0.68799  0.69682 octave:55> sort(x) ans = 0.25500 0.26586  0.33525  0.68799  0.69682  0.92658
 * returns a copy of the vector x with the elements sorted in increasing order.

= Linear algebra = For a description of more operators and functions that can be used to manipulate vectors and matrices, find eigenvalues, etc., see the Linear algebra section.

Return to the Octave Programming Tutorial index

Программирование_на_Octave/Векторы_и_матрицы


text:
User:Apfelmus/Sandbox

Which to choose?
 * a p f e l m u s
 * apfeλmus

Test signatures:
 * -- a p f e l m u s
 * -- apfeλmus

title: User:Apfelmus/Sandbox


text:
Octave Programming Tutorial/Text and file output

= The  function = The  function displays the value of a variable (scalar, vector, matrix, string, etc.) in the same way as simply typing the name of the variable does. For example, octave:1> x = [1, 2, 3] x = 1 2  3 octave:2> disp(x) 1 2  3 The name of the variable is, however, not displayed. You can also display the result of a computation without the  that normally precedes it. octave:3> log(10) ans = 2.3026 octave:4> disp(log(10)) 2.3026

The output of  depends on the   command. octave:5> format long octave:6> disp(log(10)) 2.30258509299405

The displayed value can be printed to the screen, saved in a string or saved to a file using. octave:7> s = disp(log(10)) s = 2.30258509299405 Note that  is a string containing the characters shown above.

File output
The  function can be used to save values to a file. Before we can do this, we have to open a file. This is done using the  command. When a file is opened for writing, its contents are erased and replaced with new data. To keep the existing data in a file and add to the end thereof, use the append mode. octave:10> file_id = fopen('mydata.txt', 'w'); Here,  is simply the name of a variable that we use to tell Octave which file to write. The output written to the file will appear exactly the same as the output from the  command.
 * opens a file and returns an identifier for it. The  argument is a string and can be the name of any new or existing file in the current directory. The   argument is a string that specifies whether the file is opened for
 * reading ,
 * writing, or
 * appending.
 * writes  to the file identified by.

It is important to close a file after all data has been written to it. Closing the file tells Octave to finalise any output that might still be pending and frees up the file so that it can be opened by other users or programmes.
 * closes the file identified by.

= The  function = The  function is considerably more powerful than   and, consequently, a bit more complicated to use. With, you can define exactly what the output of a value should look like. This includes specifying
 * the number of significant digits to display;
 * the format of the number (integer, real, scientific, etc.);
 * other output to display before or after the value.

Since there are so many different ways to format output using, we will discuss only the basics here using examples. For more complete information, type doc printf in Octave and page through the help using the spacebar key.

Outputting to screen, string or file
The  function displays its output on the screen. Use the  to return the result in a string and   to write to a file. Note that the  requires one additional parameter to specify the file identifier.

Note that these functions can output more than one value at the same time--more on this in the next section.

The format string
Let's look at an example. octave:18> x = 10.1; octave:19> y = 5.5; octave:20> z = 'test'; octave:21> printf('An integer: %i. A real: %f. This is a %s.\n', x, y, z); An integer: 10. A real: 5.500000. This is a test. The important part is the first argument to the  function on line 21. It specifies what the output of  should look like. Essentially, the percentage sign indicates that a value should be placed at its position in the format string. In the format string 'An integer: %i. A real: %f. This is a %s.\n' the  is replaced with an integer, the   with a real (  is for floating point) value, and the   with a string. The values of the integer, real and string are given as arguments to  after the format string. Note that  in the example above equals 10.1, but the value displayed is 10 since we specified that   should display an integer. Finally, the  at the end of the string tells Octave to move to a new line.

The next example demonstrates the following types: For more types, see the Octave documentation.
 * integer ,
 * real ,
 * scientific notation ,
 * percentage symbol.

octave:22> x = 10.34; octave:23> printf("x is a real number: %f (%e in scientific notation).\n", x, x); x is a real number: 10.340000 (1.034000e+01 in scientific notation). octave:24> printf("Write percentages as %i%%.\n", x); Write percentages as 10%.

Note that
 * the  format outputs a value in the form $$a\times10^b$$, where $$1\le a<10$$ and b is an integer;
 * the variable  is passed to   twice on line 23 since we want to output it twice (in different formats);
 * the double percentage on line 24 outputs a single percentage symbol.

We can customize the output of values even further by specifying
 * the width of the output, and
 * the precision of the output.

The width allows you to right align numbers and is specified between the percentage and the format specifier. For example, octave:36> x = 10; octave:37> y = pi; octave:38> z = 'test'; octave:39> printf("%9i\n%9f\n%9s\n", x, y, z); 10 3.141593      test Note that in the, each format specifier contains an integer (9). This tells  to use 9 columns to output the integer, real and string.

The effect of the precision parameter depends on the type of output. It's most obvious use is to specify the number of digits to display after the decimal point of a real number. The precision is specified after the width and is preceded by a dot. octave:40> printf("%9.3f\n", pi); 3.142 This displays π using 9 columns and to 3 digits after the decimal point. Note that the number is rounded. For other uses of the precision parameter (e.g. for integers and strings), see the Octave help.

Outputting matrices
When the value passed to the  function is a matrix or vector, all of the values in it are printed. If there is only one format specifier in the format string, it is used for each value in the matrix. octave:51> A = [1, 2, 3; 4, 5, 6; 7, 8, 9]; octave:52> printf("%i\n", A) 1 4 7 2 5 8 3 6 9 Note that the values are read from the matrix in column-major order, i.e. all the values from the first column are displayed first, then the second column, etc..

If there is more than one format specifier in the format string,  cycles through them. octave:57> printf("[%i, %.1f, %.2e]\n", A) [1, 4.0, 7.00e+00] [2, 5.0, 8.00e+00] [3, 6.0, 9.00e+00] The values are still read in column-major order.

Return to the Octave Programming Tutorial index


text:
Octave Programming Tutorial/Linear algebra

= Functions = $$I + A + \frac{A^2}{2!} + \frac{A^3}{3!} + \cdots$$
 * computes the determinant of the matrix A.
 * returns the eigenvalues of  in the vector , and
 * also returns the eigenvectors in  but   is now a matrix whose diagonals contain the eigenvalues.  This relationship holds true (within round off errors).
 * computes the inverse of non-singular matrix A. Note that calculating the inverse is often 'not' necessary. See the next two operators as examples. Note that in theory   should return the identity matrix, but in practice, there may be some round off errors so the result may not be exact.
 * computes X such that $$XB = A$$. This is called right division and is done without forming the inverse of B.
 * computes X such that $$AX = B$$. This is called left division and is done without forming the inverse of A.
 * computes the p-norm of the matrix (or vector) A. The second argument is optional with default value $$p = 2$$.
 * computes the (numerical) rank of a matrix.
 * computes the trace (sum of the diagonal elements) of A.
 * computes the matrix exponential of a square matrix. This is defined as
 * computes the matrix logarithm of a square matrix.
 * computes the matrix square root of a square matrix.

Below are some more linear algebra functions. Use  to find out more about them.
 * (eigenvalue balancing),
 * (condition number),
 * (computes diag(x) * A efficiently),
 * (dot product),
 * (Givens rotation),
 * (Kronecker product),
 * (orthonormal basis of the null space),
 * (orthonormal basis of the range space),
 * (pseudoinverse),
 * (solves the Sylvester equation).

= Factorizations =
 * computes the Cholesky factorization of the symmetric positive definite matrix A, i.e. the upper triangular matrix R such that $$R^TR = A$$.
 * computes the LU decomposition of A, i.e. L is lower triangular, U upper triangular and $$A = LU$$.
 * computes the QR decomposition of A, i.e. Q is orthogonal, R is upper triangular and $$A = QR$$.

Below are some more available factorizations. Use  to find out more about them.
 * (generalized eigenvalue problem: QZ decomposition),
 * (Hessenberg-triangular decomposition),
 * (Schur decomposition),
 * (singular value decomposition),
 * (Householder reflections),
 * (Orthogonal basis of block Krylov subspace).

Return to the Octave Programming Tutorial index


text:
Octave Programming Tutorial/Polynomials

In Octave, a polynomial is represented by its coefficients (arranged in descending order). For example, the vector octave:1> p = [-2, -1, 0, 1, 2]; represents the polynomial $$-2x^4 - x^3 + x + 2.$$ You can check this by displaying the polynomial with the function. octave:2> polyout(p, 'x') -2*x^4 - 1*x^3 + 0*x^2 + 1*x^1 + 2 The function displays the polynomial in the variable specified ( in this case). Note that the  means raised to the power of much like the Octave operator.

Functions
y = polyval(p, x) This returns $$p(x)$$. If x is a vector or matrix, the polynomial is evaluated at each of the elements of x.
 * Evaluating a polynomial:

r = conv(p, q) Here,  and   are vectors containing the coefficients of two polynomials and the result, , will contain the coefficients of their product.
 * Multiplication:

(As an aside, the reason this function is called  is that we use vector convolution to do polynomial multiplication.)

[b, r] = deconv(y, a) This returns the coefficients of the polynomials b and r such that $$y = ab + r.$$
 * Division:

So,  contains the coefficients of the quotient and   the coefficients of the remainder of y and a.

roots(p) This returns a vector containing all the roots of the polynomial with coefficients in.
 * Root finding:

q = polyder(p) This returns the coefficients of the derivative of the polynomial whose coefficients are given by vector.
 * Derivative:

q = polyint(p) This returns the coefficients of the integral of the polynomial whose coefficients are represented by the vector. The constant of integration is set to 0.
 * Integration:

p = polyfit(x, y, n) This returns the coefficients of a polynomial $$p(x)$$ of degree $$n$$ that best fits the data $$(x_i, y_i)$$ in the least squares sense.
 * Data fitting:

Warning: Adding polynomials
Since polynomials are represented by vectors of their coefficients, adding polynomials is not straightforward in Octave. For example, we define the polynomials $$p(x) = x^2 - 1$$ and $$q(x) = x + 1$$. octave:1> p = [1, 0, -1]; octave:2> q = [1, 1]; If we try to add them, we get octave:3> p + q error: operator +: nonconformant arguments (op1 is 1x3, op2 is 1x2) error: evaluating binary operator `+' near line 22, column 3 This happens because Octave is trying to add two vectors ( and  ) of different lengths. This operation is not defined. To work around this, you have to add some leading zeroes to. octave:4> q = [0, 1, 1]; Note that adding leading zeroes does not change the polynomial. Next, we add octave:5> p + q ans = 1 1  0 octave:6> polyout(ans, 'x') 1*x^2 + 1*x^1 + 0

Return to the Octave Programming tutorial index

title: Octave Programming Tutorial/Polynomials


text:
Octave Programming Tutorial/Plotting

Octave can work with gnuplot, Grace, PLplot. Some people deem PLplot is a replacement of the traditional gnuplot in Octave.

2D plots
plot(y) If a single data argument is supplied, it is taken as the set of Y coordinates and the X coordinates are taken to be the indices of the elements, starting with 1.

plot(x, y)
 * If the first argument is a vector and the second is a matrix, the vector is plotted versus the columns (or rows) of the matrix. (using whichever combination matches, with columns tried first.)
 * If the first argument is a matrix and the second is a vector, the columns (or rows) of the matrix are plotted versus the vector. (using whichever combination matches, with columns tried first.)
 * If both arguments are vectors, the elements of Y are plotted versus the elements of X.
 * If both arguments are matrices, the columns of Y are plotted versus the columns of X. In this case, both matrices must have the same number of rows and columns and no attempt is made to transpose the arguments to make the number of rows match.

linspace(b, l, n) results in a vector with n linearly spaced numbers between b and l. It is often used to produce the vector X in the two-argument form of plot.

Non-linear plots
semilogx, semiology, loglog, polar

Formatting
The plot may be formatted using an additional FMT argument: In the argument any number of the following options may appear:

`-'          Set lines plot style (default). `.'          Set dots plot style. `@'          Set points plot style. `-@'          Set linespoints plot style. `^'          Set impulses plot style. `L' Set steps plot style. `N' Interpreted as the plot color if N is an integer in the range 1 to 6. `NM' If NM is a two digit integer and M is an integer in the range 1 to 6, M is interpreted as the point style. This is only valid in combination with the `@' or `-@' specifiers. `C' If C is one of `"r"', `"g"', `"b"', `"m"', `"c"', or `"w"', it is interpreted as the plot color (red, green, blue,          magenta, cyan, or white). `";title;"' Here `"title"' is the label for the key. `+'    `*'     `o' `x' Used in combination with the points or linespoints styles, set the point style. The color line styles have the following meanings on terminals that support color. Number Gnuplot colors  (lines)points style 1      red                   * 2      green                 + 3      blue                  o             4       magenta               x             5       cyan                house 6      white           there exists The FMT argument can also be used to assign key titles. To do so, include the desired title between semi-colons after the formatting sequence described above, e.g. "+3;Key Title;" Note that the last semi-colon is required and will generate an error if it is left out.

Furthermore, a set of property-value pairs may also be applied, simultaneously, to each "line" drawn by plot.

Example
Here instead of line plot we place a '+' marker on the graph for each datapoint, choose the first color (red), and add a legend.

The second example adds another line and some property-value pairs as well.

Commands related to plot
xlabel, ylabel, title and refresh

3D plots
mesh, meshgrid, surf

Contour plots
contour

contour (Z)

contour (Z, VN)

contour (X, Y, Z)

contour (X, Y, Z, VN)

contour (..., STYLE)

contour (H, ...)

[C, H] = contour (...)

Plot level curves (contour lines) of the matrix Z, using the contour matrix C computed by `contourc' from the same arguments; see the latter for their interpretation. The set of contour levels, C, is only returned if requested. For example: x = 0:2; y = x;         z = x' * y;          contour (x, y, z, 2:3) The style to use for the plot can be defined with a line style STYLE in a similar manner to the line styles used with the `plot' command. Any markers defined by STYLE are ignored. The optional input and output argument H allows an axis handle to    be passed to `contour' and the handles to the contour objects to  be returned.

contourc

[C, LEV] = contourc (X, Y, Z, VN) Compute isolines (contour lines) of the matrix Z. Parameters X, Y     and VN are optional. The return value LEV is a vector of the contour levels. The return value C is a 2 by N matrix containing the contour lines in    the following format C = [lev1, x1, x2, ..., levn, x1, x2, ... len1, y1, y2, ..., lenn, y1, y2, ...] in which contour line N has a level (height) of LEVN and length of    LENN. If X and Y are omitted they are taken as the row/column index of    Z.  VN is either a scalar denoting the number of lines to compute or a vector containing the values of the lines. If only one value is wanted, set `VN = [val, val]'; If VN is omitted it defaults to    10.

For example, x = 0:2; y = x;         z = x' * y;          contourc (x, y, z, 2:3) =>  2.0000   2.0000   1.0000   3.0000   1.5000   2.0000               2.0000   1.0000   2.0000   2.0000   2.0000   1.5000

Images
colormap, image, imshow, hsv2rgb

>> help colormap 'colormap' is a function from the file C:\Octave\Octave-4.0.1\share\octave\4.0.1\ m\image\colormap.m

-- Function File: CMAP = colormap -- Function File: CMAP = colormap (MAP) -- Function File: CMAP = colormap ("default") -- Function File: CMAP = colormap ("MAP_NAME") -- Function File: CMAP = colormap (HAX, ...) -- Command: colormap MAP_NAME -- Function File: CMAPS = colormap ("list") -- Function File: colormap ("register", "NAME") -- Function File: colormap ("unregister", "NAME") Query or set the current colormap.

With no input arguments, `colormap' returns the current color map.

`colormap (MAP)' sets the current colormap to MAP. The colormap should be an N row by 3 column matrix. The columns contain red, green, and blue intensities respectively. All entries must be    between 0 and 1 inclusive. The new colormap is returned.

`colormap ("default")' restores the default colormap (the `jet'    map with 64 entries). The default colormap is returned.

The map may also be specified by a string, "MAP_NAME", where MAP_NAME is the name of a function that returns a colormap.

If the first argument HAX is an axes handle, then the colormap for the parent figure of HAX is queried or set.

For convenience, it is also possible to use this function with the command form, `colormap MAP_NAME'.

`colormap ("list")' returns a cell array with all of the available colormaps. The options "register" and "unregister" add or remove the colormap NAME from this list.

See also: jet.

Saving and printing graphs
Print a graph to a printer or save it to a file

print("-Pprinter") print("filename", "-ddevice")

Devices: `ps' `ps2' `psc' `psc2' Postscript (level 1 and 2, mono and color) `eps' `eps2' `epsc' `epsc2' Encapsulated postscript (level 1 and 2, mono and color) `ill' `aifm' Adobe Illustrator `cdr' `corel' CorelDraw `hpgl' HP plotter language `fig' XFig `dxf' AutoCAD `mf' Metafont `png' Portable network graphics `pbm' PBMplus `svg` Scalar Vector Graphics

If the device is omitted, it is inferred from the file extension, or if there is no filename it is sent to the printer as postscript.

=See also=
 * Creating graphic file in Octave
 * commons:Category:Images with Octave source code

Return to the Octave Programming tutorial index

GNU Octave/Tworzenie rysunków

title: Octave Programming Tutorial/Plotting


text:
Octave Programming Tutorial/Loops and conditions

Loops are used to repeat a block of code for a known or unknown number of times, depending on the type of loop. Using loops, you will draw some nice pictures of fractals and shapes drawn with random dots.

The loop
We use  loops to repeat a block of code for a list of known values. As an example, we'll calculate the mean of a list of values. The mean is calculated from $$\overline{x} = \frac{1}{n}\sum_{i=1}^n x_i.$$

We set up a vector with some values octave:1> x = [1.2, 6.3, 7.8, 3.6]; and calculate the mean with octave:2> sum = 0; octave:3> for entry = x, octave:4>  sum = sum + entry; octave:5> end; octave:6> x_mean = sum / length(x)

Line 2: Set sum equal to 0.

Line 3: For each value in x, assign it to entry.

Line 4: Increment sum by entry.

Line 5: Ends the for loop when there are no more members of x.

Line 6: Assign the final value of sum divided by the length of x to x_mean.

TO DO: get a better example and explain the code.

In general, we write a  loop as for variable = vector ... end

The  represents the block of code that is executed exactly once for each value inside the.

Example: The Sierpinski triangle
The Sierpinski triangle is a fractal that can be generated with a very simple algorithm.
 * 1) Start on a vertex of an equilateral triangle.
 * 2) Select a vertex of the triangle at random.
 * 3) Move to the point halfway between where you are now and the selected vertex.
 * 4) Repeat from step 2.

Plotting the points that you visit by following this procedure, generates the following picture.

The code that generates this fractal is shown bellow. Note that this code uses one very simple for loop to generate the fractal (for i = 1:N ; ... ; end)

axis ([-1, 1, -0.75, 1.25], "square"); figure(1, "visible", "off");                         % no plotting window hold on; % defining the vertices of an equilateral triangle (symmetric to y-axis) V = [ 0, 1;                                          % top vertex cos( (pi/2)+(2*pi/3) ), sin( (pi/2)+(2*pi/3) ); % left vertex cos( (pi/2)-(2*pi/3) ), sin( (pi/2)-(2*pi/3) )  % right vertex ]; r = floor(3*rand(1)+0.9999999999);                   % integer random number in [1:3] x = [ V(r,1), V(r,2) ];                              % initializing x on random vertex for i = 1:1000 % !!! 100000 => time=130m57.343s r = floor(3*rand(1)+0.9999999999);                 % integer random number in [1:3] x = ( x+V(r,[1:2]) )./2;                           % halfway, current to random vertex plot(x(1),x(2), "."); endfor print -dpng "sierpinski_m.png";

A Word of Caution
For performance reasons, it's best to perform as few tasks as possible inside 'for' loops, and graphical operations like plot should be moved outside of loops whenever possible. By simply storing all x values in a matrix and then plotting as shown below, the run time for the code to produce this figure drops to a few seconds, even when iterating over 100,000 elements (which the code above warns not to do). By initializing x as a matrix of the full final size ahead of time, this processing time can be reduced still further to only 1 or 2 seconds on modern hardware. In general, if a loop can be replaced with vectorization, it should be.

Exercises

 * 1) Write a script that sums the first N integers. You can check your result with the formula $$\frac{1}{2}N(N+1)$$.
 * 2) Write a script that does the same thing as the  function. It should start at some value, , stop at   and create a vector that contains N values evenly spaced from   to  . You can use the   function to create a zero-filled vector of the right size. Use   to find out how the function works.

The loop
The while loop also executes a block of code more than once but stops based on a logical condition. For example x = 1.0; while x < 1000 disp(x); x = x*2; endwhile will multiply  by 2 until its value exceeds 1000. Here,  is the condition of the loop. As long as the condition holds (is true), the loop will continue executing. As soon as it is false, the loop terminates and the first instruction after the loop is executed.

The general form of a while loop is

while condition ... endwhile

Exercise

 * 1) Write a script that calculates the smallest positive integer, n, such that $$a^n \ge b$$ for some real numbers a and b. (Meaning, find the smallest power of a that is at least b.) Using the  function is considered cheating.

Example: The Mandelbrot fractal
The Mandelbrot set is another fractal and is generated by checking how long it takes a complex number to become large. For each complex number, c,

 * 1) Start with $$z_0 = 0$$.
 * 2) Let $$z_i = z_{i-1}^2 + c \quad\forall i = 1, 2, \ldots$$
 * 3) Find the first i such that $$|z_i| > 2$$.

We record all of these i values and assign a colour to each of them. This is used to generate an image like this one.

You can download the code that generates this fractal from Mandelbrot.m. Note that there is a while loop (inside some for loops) that tests whether the complex number z has modulus less than 2:

while (count < maxcount) & (abs(z) < 2) ... endwhile

The first condition in the while loop checks that we do not perform too many iterations. For some values of c the iteration will go on forever if we let it.

See also another version by Christopher Wellons

The statement
These loops are very similar to while loops in that they keep executing based on whether a given condition is true or false. There are however some important difference between  and   loops.
 * 1)   loops have their conditions at the beginning of the loop;  loops have theirs at the end.
 * 2)   loops repeat as long as the condition is true;  loops continue as long as theirs is false.
 * 3)   will execute 0 or more times (because the condition is at the beginning);  loops will execute 1 or more times (since the condition is at the end).

The general form of a  loop is do    ... until condition

Exercise
Write a script that calculates the greatest common divisor (GCD) of two positive integers. You can do this using Euclid's algorithm.

Challenge
Write a script that generates random number pairs (a, b) that are distributed uniformly
 * 1) over the disc $$\left\{(x, y) | x^2 + y^2 \le 1\right\}$$ (the first image below);
 * 2) as in the second image below

The and   statements
Sometimes it is necessary to stop a loop somewhere in the middle of its execution or to move on to the next value in a for loop without executing the rest of the loop code for the current value. This is where the  and   statements are useful.

The following code demonstrates how the break statement works.

total = 0; while true x = input('Value to add (enter 0 to stop): '); if x == 0 break; endif total = total+x; disp(['Total: ', num2str(total)]); endwhile

Without the  statement, the loop would keep executing forever since the condition of the   loop is always true. The  allows you to jump past the end of the loop (to the statement after the endwhile).

The  statement can be used in any loop: ,   or.

The continue statement also jumps from the inside of a loop but returns to the beginning of the loop rather than going to the end. In a
 * 1)   loop, the next value inside the vector will be assigned to the for variable (if there are any left) and the loop restarted with that value;
 * 2)   loop, the condition at the beginning of the loop will be retested and the loop continued if it is still true;
 * 3)   loop, the condition at the end of the loop will be tested and the loop continued from the beginning if it is still false.

As an example, the following code will fill the lower triangular part of a square matrix with 1s and the rest with 0s.

N = 5; A = zeros(N); % Create an N x N matrix filled with 0s for row = 1:N for column = 1:N if column > row continue; endif A(row, column) = 1; endfor endfor disp(A);

Note that the inner  skips (continues) over the code that assigns a 1 to an entry of   whenever the column index is greater than the row index.

The statement
The general form of the  statement is

if condition1 ... elseif condition2 ... else ... endif

If  evaluates to true, the statements in the block immediately following the   are executed. If  is false, the next condition (  in the  ) is checked and its statements executed if it is true. You can have as many  statements as you like. The final set of statements, after the, is executed if all of the conditions evaluate to false. Note that the  and   parts of the   statement are optional.

The following are all valid  statements:

% Take the log of the absolute value of x if x > 0 y = log(x); elseif x < 0 y = log(-x); else disp("Cannot take the log of zero."); endif x = input("Enter a value: "); if x > 0 disp("The number is positive"); endif if x < 0 disp("The number is negative"); endif if x == 0 disp("The number is zero"); endif

Example: The fractal fern
This algorithm is not quite complete. Have a look at the .m file available from http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4372&objectType=file.

The image to the right can be generated with the following algorithm:

1. Let x1 and y1 be random values between 0 and 1. 2. Choose one of the linear transformations below to calculate (xi+1, yi+1) from (xi, yi): 1. xi+1 = 0 yi+1 = 0.16yi 2. xi+1 = 0.20xi − 0.26yi yi+1 = 0.23xi + 0.22yi + 1.6 3. xi+1 = −0.15xi + 0.28yi yi+1 = 0.26xi + 0.24yi + 0.44 4. xi+1 = 0.85xi + 0.04yi yi+1 = −0.04xi + 0.85yi + 1.6 The first transformation is chosen if probability 0.01, the second and third with probability 0.07 each and the fourth with probability 0.85. 3. Calculate these values for i up to at least 10,000.

You can download the code that generates this fractal as fracfern.m (this is disabled for now).

Return to the Octave Programming tutorial index


text:
Octave Programming Tutorial/Writing functions

Syntax
In Octave, function definitions use the following syntax:

Factorial Function
The factorial function, which takes exactly one argument and returns one integer, is as follows.

Save m-File
You can save the definition of the function in your working directory. Use the name of the function also for the filename - e.g. use the filename  for the definition of the function .

Maximum and Minimum of two integer Values
The following function, maxmin, returns the maximum and minimum value of two integers:

To call a function with multiple arguments, you specify multiple variables to hold the results. For example, one could write:

After executing, the variable 'big' would store the value '10' and the variable 'small' would store '7'. If fewer than two variables are used to hold the result then fewer outputs are returned. Writing

a = maxmin(13,5)

would store 13 in the variable 'a', and would discard the value of 5.

Return to the Octave Programming tutorial index