text:
Subject:Library and information science

Wanted books

 * Social Justice Librarianship
 * Feminism in Library and Information Science

Administration

 * The Financial Planning and Management of Libraries
 * Management of an Information Organization
 * Library Human Resource Management
 * Information Leadership
 * Knowledge Management in a Global Context
 * Library architecture

Collection Development

 * Collection Development
 * Core Collection for Academic Libraries
 * Core Collection for Public Libraries
 * Core Collection for School Libraries
 * Weeding

Information organization

 * Introduction to Information Organization
 * Indexing and Abstracting
 * Information Retrieval
 * Data Management
 * Digital Libraries
 * Text Encoding and Markup

Information Services

 * Introduction to Reference and Information Services
 * Readers' Advisory
 * Information Literacy
 * Information Needs of Children
 * Information Needs of Young Adults
 * Information Needs of Adults
 * Legal Resources
 * Government Resources
 * Genealogy and Local History Reference Services

Policy

 * Introduction to Information Policy
 * Copyright Policies

Special collections

 * Archival Description
 * Preservation and Conservation

title: Subject:Library and information science


text: User:CyberAran/temp

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

title: User:CyberAran/temp


text:
Talk:Mac OS X Tiger/Using your Mac as a Web Server

Shortcomings
ok, first of all, routers should be considered. ruben --81.246.198.139 13:47, 3 August 2006 (UTC)
 * as far as i know you can still run a webserver if port 80 is blocked, for example by using a an adress like 127.0.0.1:31337
 * i changed the whatismyip.com to whatismyip.org, because the latter is ad-free and just contains the IP adress
 * if you're connected directly you can also see your own IP in the network prefs.
 * there is advertising language in use "as you'd expect, apple makes it easy". yeah neutral...


text:
User:Steve Renard

Steve Renard is a composer, arranger, and performer living in the Washington, DC area. He is also a video editor and motion graphics designer. His primary instruments are guitar and voice, and he holds a B.A. Music with a focus in Theory and Composition from Earlham College in Richmond, IN.

title: User:Steve Renard


text:
Greek Mythology/Minor Gods/Graces

The Graces are the daughters of Zeus and Eurynome, a nymph and a child of the Titan Oceanus. Together with the Muses, they sang and danced with the gods of Mount Olympus to the beautiful music of the lyre of Apollo. They are three in numbers:

 * Aglaia - 'splendour' or 'brightness
 * Euphrosyne - 'joy and mirth'
 * Thalia - 'good cheer' or 'bringer of flowers'.

They were venerated as deities or spirits of vegetation in ancient Greece and later adopted in Roman mythology. Aglaia, the youngest of the three, was said to be the most beautiful.

title: Greek Mythology/Minor Gods/Graces


text:
User:Webiddle

=Open Source and Open Access - a New Revolution in Publishing=

Open Source
Open source software is software that includes source code and is usually available at no charge. There are additional requirements besides the availability of source code that a program must meet before it is considered open source including: the software must be free to redistribute; derivative works must be allowed; the license can not discriminate against any persons; and the license cannot discriminate against any fields of endeavor. Software that is licensed under an open source license allows for a community of developers from around the world to improve the software by providing enhancements and bug fixes. The recent success of free software projects such as GNU/Linux, Mozilla Firefox, and the Apache web server has demonstrated that quality works can be created even in the absence of a copyright-enforced monopoly rent [2.1]. Instead, these products use copyright to enforce their license terms, which are designed to ensure the free nature of the work, rather than securing exclusive rights for the holder for monetary gain; such a license is called a copyleft, free software license, or open source license. Mozilla is an example of an open source license.

Libraries can realize many advantages by using open source software. One of the most obvious advantages is cost. Open source software is generally available for free (or at a minimal cost) and it is not necessary to purchase additional licenses for every computer that the program is to be installed on or for every person who is going to use the software. Open source software not only has a lower acquisition cost than proprietary software, it often has lower implementation and support costs as well.

Another advantage is evaluating usability. It is easier to evaluate open source software then proprietary software. Since open source software is typically freely available to download, librarians and systems administrators can install complete production-ready versions of software and evaluate competing packages. This can be done not only without any license fees, but also without having to stick to a vendor's trial period, evaluate a limited version of the software, or deal with the vendor's sales personnel. If the library likes an overall open source package but would like a few added features they can add these features themselves. This is possible because the source code is available. Even if a library does not have in-house expertise they can benefit from source code availability because another library may be able to provide them the fix or they can hire a consultant to make the changes that they desire. Fuchs (2004) points out that if a proprietary program "is deficient in some way [the user] must wait until the vendor decides it is financially viable to develop the enhancement -- an event that may never occur." With open source software the user can develop the enhancement themselves.

Open source software allows for more support options. Proprietary software vendors often package service with the product. This is particularly true of proprietary library-specific software. When support from a vendor is inadequate it is an additional expense to purchase another tier of support, assuming that it is even available. Open source software allows for different vendors to compete for support contracts based on quality of service and on price. Access to the source code also allows for self-support when practical and desired. There are also usually several support forums for developers and users to troubleshoot and brainstorm off each other.

Open Access
Open access to scholarly information has been a hot topic for debate among librarians, scholars, and publishers over the last few years. Recent proposals by the National Institutes of Health (NIH) in the United States (requiring for scholarly works that come out of NIH funded research to be made available via NIH's PubMedCentral open access database), by the government in the United Kingdom (requiring that all UK government-funded research to be available via open access), and by others has expanded this debate. Various definitions of open access exist with the Budapest Open Access Initiative definition being the most widely used (Goodman 2004). Other definitions include the Berlin Declaration on Open Access to Knowledge in the Sciences and Humanities, the Bethesda Statement on Open Access Publishing, and the Washington DC Principles for Free Access to Science. While there are multiple definitions of open access, open access basically calls for scholarly publications to be made freely available to libraries and end users.

There are eight versions of open access that are most popular. They are: 1) e-print archive (authors self-archive prints), 2) unqualified (immediate and full open access publication of a journal, 3) dual mode (both print subscription and open access versions of a journal are offered), 4) delayed open access (open access is available after a certain period of time), 5) author fee (authors pay a fee to support open access), 6) partial open access (some articles from a journal are available via open access), 7) abstract (open access available to table of contents/abstracts, and 8) co-op (institutional members support open access journals).

The growth of the open access movement is partially in response to the enormous costs of many scholarly journals. With traditional journal publication methods it is not uncommon for an institution to have to pay for an article twice. First they pay scholars to produce the work and then the institution's library pays to purchase the work back from the journal publisher. Anderson (2004) is correct that there is no such thing as free information and that there are costs involved in producing scholarly information. However, with the advent of new technologies and software programs, it is becoming increasingly less expensive to compile and distribute scholarly information. By using different funding methods and electronic delivery of journals, the costs can be absorbed by alternative means to subscription fees. One of the great benefits to open access is that libraries in smaller institutions or in economically disadvantaged areas around the world can have greater access to these scholarly resources.

Open access helps to ensure long-term access to scholarly articles. Unlike articles that are licensed in traditional article databases, libraries and others can create local copies and repositories of these resources. Libraries, by working together to make repositories of open access literature, can ensure continued access to these scholarly publications into the distant future.

The Budapest Initiative
The Budapest Intiativeis an organization striving for open access publishing of scholarlly materials using the Internet as the primary form of dissemenation.

Manner of Access
The typical manner of access is electronic access over the Web to HTML or PDF versions, with publication in other formats considered as optional and subsidiary. The entire OA concept depends upon the very low incremental cost for additional users of electronic material delivered over the Internet, whereas printed material must have an incremental cost for each copy printed. (This can be a small cost if we are talking about millions of copies, but we are not.) The financing of OA is always computed on the basis of electronic-only publication. To this calculation can be added the cost of the production of a small number of printed copies, either from specialized PDF or as short-run printing of the electronic version. These versions can be sold conventionally by subscription to those who wish the print for intensive reading of key journals, those requiring print for taxation or regulatory purposes, and those maintaining print archival backup as a supplement to electronic archiving. Before the development of electronic distribution, there were proposals for the distribution of materials in other manners. These generally involved the distribution of individual articles in paper or microform, or the distribution of a totally comprehensive periodical in large numbers. (4) A decreasing number of locations remain without suitable access to the Internet, but these areas almost always have even worse access to printed publications. Facilities for electronic access are likely to improve long before those for print.

Type of Material
"Scholarly publications" cover a very wide range and can be taken to mean all scientific material, or only journal articles, or only those journal articles that are primary research reports. The concept is often extended to include material that is technically "unpublished," such as preprints or working drafts or primary data. It excludes material from which authors expect direct monetary profit, such as textbooks or popularizations. It recognizes that authors eventually expect some form of psychological or monetary compensation, such as the increased prestige among their colleagues, the satisfaction at the diffusion of their ideas, and the possibility of hiring, promotion, or tenure. The basic material covered is primary journal articles, defined as those in which original experiments, discoveries, or calculations are presented. Their publication is described in detail elsewhere, (5) but what follows is an outline of steps at which some of the controversies of OA occur. Typically, such articles are peer-reviewed before publication by two or three other scholars in the field. The reviewers generally recommend either rejection, or acceptance with alterations; the process of making the alterations is brokered by the editor. There are variations, and for some journals, the editor or editorial board alone decides. The end result of peer review is the author's accepted final draft.

The journal editor is generally compensated, at least for expenses. The peer reviewers are generally not directly compensated. (6) The peer-reviewed author's accepted final draft is checked before printing by copyeditors, who are usually paid staff or outside service providers. The author does not usually see the revisions at this stage. The costs associated with these inherently human and non-automated processes are always present, even if not paid in money. However, these costs are dependent only on the size of the journal, the production quality, and the number of articles reviewed (both those accepted and the usually greater number not accepted)--not upon the number of users. A difference exists between the facilities needed for large and small systems, but the effect is small compared to the production for print.

When only electronic versions are produced, the material is usually converted into the publisher's PDF, and added to the journal's Article Database. The cost of operating such a database depends primarily upon the size of the journal, and only to a slight extent upon the number of readers. When both print and electronic versions are produced, usually a common XML version is prepared. From this version comes the HTML and PDF versions for online distribution, and PDF for printing. Producing print adds the cost both of the preparation of the final version for printing, (which is independent of the size of the edition) and the cost for printing and distribution of each copy (which does depend on the size of the edition).

Secondary material, such as editorials and review articles in academic journals, are sometimes OA and sometimes not. News items, explanations or summaries of current work, and announcements are usually written by paid writers, at least for major publications. Paid writers expect to be actually paid in money, and most earn their primary income from this source. Major review articles are usually arranged in advance, and some relatively small monetary compensation is often provided--probably nobody makes a living writing review articles alone. Book reviewers are generally compensated by getting to keep the book they review. Although they could sell these books, probably nobody makes a full living in this way either. Some of the ethical arguments that call for the public to have access to publicly supported research do not necessarily apply to review articles, and neither do some of the economic reasons. A research article (and thus the single journal in which it is published) is inherently a monopoly--no other article can be substituted. That is not usually the case with reviews, where there may be a number of equivalents covering the same material. The users, however, often do not make this distinction and expect them all to be OA.

Some journals contain advertisements, and their treatment under OA varies. Some textbooks and similar items are available as OA, with or without a paid equivalent. Also common is OA availability for older editions, often developed and maintained on a voluntary basis. Some electronic publications carry material that is not in the printed versions. The continuing Nature Web Focus on OA is one example, and supplementary data is another. It is customary to have OA to this material even when the base journal is non-OA. The spread of OA has reached beyond the sciences. Scholarly book publishing in the humanities has similar problems, and the distribution of primary data in the humanities is now often organized at least partially as OA. (7)

What All This Openness Means
Open access and open source software each offer a number of significant benefits to libraries. When they are combined the results can be even greater. Open source can help libraries provide patrons with easier access to open access materials and other resources. There are literally thousands of open access titles available and without open source or standards it would be very difficult to find what one is looking for or to view various articles. Imagine the difficulty, and costs involved, in maintaining a library's information technology infrastructure if each electronic journal required a separate, proprietary piece of software to read or search the journal. Open standards together with open source make it possible to create interoperable systems to access the literature in various open access journals seamlessly.

Open source can help preserve long-term access to open access and other types of electronic journals. Without the assistance of the software manufacturer (who may or may not even still be in business, let alone willing to help) proprietary software and file formats may make migration practically impossible. By utilizing open source software and open standards from the beginning, libraries can assure that this type of systems migration will be possible years down the road.

Not only has the growing cost of serials caused libraries to drop journal subscriptions, it has also factored into a 26% decrease of monograph acquisitions by the typical research library between 1986 and 1999 (Create Change 2002). Library budgets can be reallocated to monographs and other areas because of the lower costs typically involved with open access, open source, and open standards.

Implications of Open Access
Both of the facts that information is inherently costly, and that information is not usually a public good, pose challenges for the idea of open access. For information to be made freely and permanently available to the public, the costs of creation, publication, and distribution must be absorbed by someone other than those who wish to use it. The Internet eliminates most distribution costs, but not all of them, and does not affect creative costs or publication costs to any appreciable degree.

Do these inconvenient facts mean that open access is not desirable or that it cannot work? No. But they do define some limits to the options, and a recognition of those limits should lead to patience with publishers that are moving more slowly towards that model than most might like. Any proposal that is built on the premise that information is inherently free, or that online publication can be undertaken without significant cost, will not work in the real world because both of those premises are demonstrably incorrect. If the intrinsic costliness of information is not taken into account, it will be hard to discuss intelligently the intractable economic realities that govern its creation and distribution, let alone formulating pricing and distribution strategies that will provide maximum public benefit.

Nevertheless, the problems that have led to the current controversy over journal pricing and open access are real and need to be solved in some way. Clearly the status quo is insupportable; if the price of scholarly journals continues to rise at the present rate, research libraries will quickly lose the ability to meet the needs of their patrons. At the same time, it is not reasonable to expect all journal publishers to move immediately into an open-access model simply because the Internet has lowered the cost of distribution.

= Copyright Concerns in Open-Source =

What is Copyright?
Copyright is a set of exclusive rights regulating the use of a particular expression of an idea or information. At its most general, it is literally "the right to copy" an original creation. In most cases, these rights are of limited duration. The symbol for copyright is ©, and in some jurisdictions may alternately be written (c).

An author's exclusive right to his creation is mandated in the US Constitution in Article I, Section 8, Clause 8, which also gives Congress the power to enact statutes: To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries.(See Copyright, Wikipedia, for a more detailed explanation of copyright basics).

Copyright, a historical perspective
Historically, U.S. copyright law has sought to balance private incentives to engage in creative activity with the social benefits that arise from the widespread use of creative works. In the past, the emergence of new technologies has threatened to tilt the scales of the copyright control by loosening the control that copyright owners enjoy over subsequent uses of their works. Such a development could reduce the revenues that creators of copyrighted material obtain from their efforts and thereby restrict the future supply of creative works. Over the years, however, three important factors have helped to preserve some balance in the U.S. copyright regime: the judicial interpretation of existing copyright law; the enactment of new legislation; and the ability of copyright holders and the industries that market and distribute creative products to find ways of applying those new technologies to generate sufficient returns to maintain the flow of new creative works.

An economically efficient outcome in markets for creative works is elusive. Efficiency in markets for goods and services generally requires that the cost of producing the last (or marginal) unit must equal society's valuation of it. However, once a copyrighted work has been created, relatively few costs are incurred in its reproduction and distribution--especially if the work is in digital form. Offering a creative work at the relatively low marginal cost of reproduction and distribution, therefore, would not generate the returns needed to recoup the overall expense of supplying it. To encourage creative works, copyright law has traditionally allowed for licensing rights that enable pricing above marginal cost, while placing a limit on the scope and duration of copyright protection to ensure that creative works eventually become widely available. Copyright law therefore accepts some static inefficiency (copyrighted works are typically not distributed as widely as is economically feasible) in the interests of beneficial dynamic effects (getting those works created in the first place).

It is difficult to determine how close the current copyright regime is to being efficient--that is, whether the optimal balance between private incentives and social benefits has been reached. Given society's desire for creative works, as well as its endowments of talent, technology, and other resources needed to generate and distribute those works, the question is whether current law and practice provide incentives for the greatest quantity and highest quality of original works to be created and consumed over time. Although the answer to that question is not straightforward, the magnitude of illicit consumption of copyrighted works in digital form today--music files shared over the Internet, for example, or movies and software illegally reproduced and distributed on CD-ROM--suggests that potential efficiency gains can be realized by applying advances in digital technology to legal markets for creative works.

The Digital Challenge to Copyright Law
The digitization of creative content poses a more serious challenge to copyright law than did earlier episodes of technological advance. A particularly significant aspect of that challenge is that digital technologies continue to increase the ways in which individuals can consume and enjoy creative works--for example, by "ripping" music files from a CD to store on a computer or portable music device--despite the fact that copyright law does not explicitly permit those uses without the authorization of the copyright owner. At the same time, advances in digital technologies provide copyright owners with growing capacity to either restrict or charge for subsequent uses of their creative works.

Furthermore, copyrighted works in digital form can be flawlessly and inexpensively reproduced and instantaneously distributed worldwide. Copyright holders consequently fear that unauthorized copying and redistribution of their works will cause their economic returns to decline. At the same time, copyright law today applies to a growing number of products. Although the most prominent disputes over digital copyright concern music and movies, copyright law also applies directly to other products, such as computer software. Some manufacturers of software and other products have responded to technological advances by proposing new types of product licenses to protect and extend their commercial interests. Those new licensing practices could, however, potentially run counter to consumers' interests.

Changes to copyright law, moreover, can have ramifications that extend beyond the concerns of producers and consumers of copyrighted material to the well-being of related sectors of the economy. The availability of creative content in digital form contributes to the growth of industries such as computer hardware and peripherals, as well as telecommunications goods and services. Measures to protect copyrighted works--for example, a government mandate that a particular access- or copy-control technology be used to prevent infringement of copyrighted materials in digital form--therefore require careful deliberation. When and how the digital copyright debate is resolved could influence the nature and pace of future technological progress--and hence the growth of the economy.

Economics and Copyright
Because of the growing number and diversity of interests with a stake in the digital copyright debate, many observers believe that the Congress may need to legislate a balance in copyright law between private incentives and societal gains. Economic analysis can illuminate the Congress's search for that balance, but it cannot provide unambiguous conclusions about the best weighting of the interests of copyright holders and consumers. The "best" policy implies a distribution of returns based as much on what is fair as on what is efficient. Economics does not provide answers to questions of fairness.

Although economic analysis may not be able to determine the best copyright regime in terms of fairness or other norms of society--it cannot, for example, identify which group(s) should gain and which should lose as a result of any revision in copyright law--it can provide insights into how private incentives and social benefits in markets for creative works might be structured. To make outcomes in markets for copyrighted goods as efficient as possible--that is, to enable society to obtain the most from the creative efforts of its members--economic reasoning can offer several general principles for legislative deliberations about revisions to copyright law in response to technological change:

Property rights and other elements of a regulatory regime for creative works should be regarded as instruments for allocating creative resources. Hence, existing copyright law should not be viewed as an absolute, inviolable set of rights to which either creators or consumers are entitled.

Revisions to copyright law should be made without regard to the vested interests of particular business and consumer groups. Instead, they should be assessed with regard to their consequences for efficiency in markets for creative works and other products.

Property rights are not free. For a system of property rights to be accepted and upheld, the costs of establishing and enforcing that regime must not exceed the eventual benefits from it. The usefulness of those general principles is not diminished by several additional factors that may constrain the specific contributions that economic analysis eventually makes to the digital copyright debate. The economically efficient level of copyright protection is difficult to determine, for example, because copyright applies to diverse creative works that incorporate varying degrees of creative and artistic expression--from journalism to literature, music, and movies--and to works of a more technical nature, such as software. A single property rights regime, therefore, may not produce efficiency in markets for all of those products.

Furthermore, not all aspects of markets for creative works lend themselves to economic analysis. In particular, while economists may confidently expect that abolishing copyright protection altogether will reduce the level and quality of creative output, they cannot easily predict how a less dramatic change in compensating copyright owners will affect the number or quality of creative works being produced.

Because the advances in digital technology that currently challenge copyright law are part of a broader trend in the development of information technologies, moreover, actions motivated by other concerns may have an effect on the feasibility and desirability of revisions to copyright law. For example, regulation of the peer-to-peer networks that enable file-sharing among personal computer users--the primary source of copyright infringement worries today--may eventually be justified not to protect intellectual property but rather to address concerns about other activities carried out on those networks, such as the dissemination of computer viruses and software packages that surreptitiously monitor an individual's computer use.

Creative Commons
See Creative Commons

The Creative Commons License refers to the name of several copyright licenses released on December 16, 2002 by Creative Commons, a U.S. non-profit corporation founded in 2001.

These licenses all grant certain baseline rights, such as the right to distribute the copyrighted work on file sharing networks. The rest of the license depends on the version, and is comprised of a selection of four conditions:

Attribution (by): Permit others to copy, distribute, display, and perform the work and derivative works based upon it only if they give you credit.

Noncommercial or NonCommercial (nc): Permit others to copy, distribute, display, and perform the work and derivative works based upon it only for noncommercial purposes.

No Derivative Works or NoDerivs (nd): Permit others to copy, distribute, display and perform only verbatim copies of the work, not derivative works based upon it.

ShareAlike (sa): Permit others to distribute derivative works only under a license identical to the license that governs your work. (See also copyleft.)

Mixing and matching these conditions produces sixteen possible combinations, of which eleven are valid Creative Commons licenses. Of the five invalid combinations, four include both the "nd" and "sa" clauses, which are mutually exclusive; and one includes none of the clauses, which is equivalent to releasing one's work into the public domain. The five of the eleven valid licenses thats that lack the Attribution element have been phased out because 98% of licensors requested Attribution, but are still available for viewing on the website [1]. There are thus six regularly used licenses:

1. Attribution alone (by) 2. Attribution + Noncommercial (by-nc) 3. Attribution + NoDerivs (by-nd) 4. Attribution + ShareAlike (by-sa) 5. Attribution + Noncommercial + NoDerivs (by-nc-nd) 6. Attribution + Noncommercial + ShareAlike (by-nc-sa)

None of the Creative Commons licenses have been certified by the Open Source Initiative. The Debian GNU/Linux distribution does not believe that any of the licenses adheres to the Debian Free Software Guidelines. The Free Software Foundation recommends the licenses for creative works other than software and software documentation, provided the "nc" and "nd" options are not used. [2]

Creative Commons licenses are currently available under 31 different jurisdictions worldwide, with nine others under development. [3]

title: User:Webiddle


text:
Understanding Darcs/Making changes

record makes new stuff old
The record command takes the changes which only exist in your working directory (or the pending patch) and updates the pristine tree. The result of a record operation is a new patch.

replace for renaming tokens
The replace command is useful for explicitly telling darcs to replace one word with another (for example, a variable name, if you are a programmer).

Note that because of the underlying patch theory, replace only works if the new word doesn't already exist in the file. Darcs will helpfully let you know if you try to replace something you cannot. Also, there is a switch for forcing the replacement, but the resulting patch is not a clean darcs-replace patch, but a combination of that, and what you would have gotten if you had edited the file in a text editor. In short, forcing darcs to replace when it really doesn't want to can lead to counter-intuitive results.

Playing with files
We saw add in the last chapter. What about the other file-related commands?

add tells darcs to pay attention
add, unsuprisingly, adds a file or directory to the list of files that darcs is paying attention to.

mv for moving or renaming
mv lets you rename a file or put it in a different directory. This command updates the pending patch with a move command.

you don't need remove
You might think that remove gets rid of a file, but actually all it does is to remove it from the list of files that darcs is paying attention to. You probably just want to delete the file instead (eg: with rm). Darcs will notice and record the change next time you darcs record that file. So what's the remove command good for? It might be handy if you want to just remove the file from darcs, without actually getting rid of your physical copy. This is most useful when you've accidentally used darcs add on a file you don't want darcs to pay attention to.

title: Understanding Darcs/Making changes


text:
Understanding Darcs/Working with others

get
makes a copy of an entire darcs repository. Note that we only get the recorded patches (and pristine tree), not any of the pending stuff.

pull/push
copies from some other repository patches that you do not have. The patches are applied to your pristine tree and working directory. This may cause changes to be merged. Note that  does the same thing, but in the other direction.

send
Darcs send is sort of like push, only it doesn't actually apply the patches anywhere. Instead it generates a handy email to the person or people who own the repository. If it can't figure out who owns the repository, it will let you send to any email address you want. Note that you can also pass the -o command to "send" into a file, rather than a mail.

apply
Apply is what you do to a patch that somebody darcs sends to you. You can also use it for the files you generated via send -o. Note: <tt>push</tt> is actually just <tt>apply</tt> in disguise, but with all the boring work of copying files over being done for you.

<tt>put</tt>
<tt>Put</tt> enables to copy a local repository to remote location (for instance, via ssh). Think of <tt>put</tt> as the opposite of <tt>get</tt>.

Dealing with conflicts
So you pulled a patch and you got a conflict. What do you do? See the chapter ../Dealing with conflicts/

title: Understanding Darcs/Working with others


text:
Python Programming/Loops

While loops
This is our first control structure.The version used is 2.7. Ordinarily the computer starts with the first line and then goes down from there. Control structures change the order that statements are executed or decide if a certain statement will be run. As a side note, decision statements (e.g., if statements) also influence whether or not a certain statement will run. Here's the source for a program that uses the while control structure: And here is the output: 1 2 3 4 5 So what does the program do? First it sees the line  a = 0 and sets the variable a to zero. Then it sees  while a < 5: and so the computer checks to see if  a < 5. The first time the computer sees this statement, a is zero, and zero is less than 5. In other words, while a is less than five, the computer will run the indented statements.

Here is another example of the use of  while:

Enter Numbers to add to the sum. Enter 0 to quit. Current Sum: 0 Number? 200 Current Sum: 200 Number? -15.25 Current Sum: 184.75 Number? -151.85 Current Sum: 32.9 Number? 10.00 Current Sum: 42.9 Number? 0 Total Sum = 42.9

Notice how  print 'Total Sum =',s is only run at the end. The  while statement only affects the lines that are tabbed in (a.k.a. indented). The  != means does not equal so  while a != 0 : means until a is zero run the tabbed in statements that are afterwards.

Now that we have while loops, it is possible to have programs that run forever. An easy way to do this is to write a program like this:

This program will output <tt> Help, I'm stuck in a loop.</tt> until the heat death of the universe or you stop it. The way to stop it is to hit the Control (or Ctrl) button and `c' (the letter) at the same time. This will kill the program. (Note: sometimes you will have to hit enter after the Control C.)

Examples
Fibonacci.py

Output: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

Password.py

Sample run: Password:auo Password:y22 Password:password Password:open sesame Password:unicorn Welcome in

For Loops
The next type of loop in Python is the <tt>for</tt> loop. Unlike in most languages, <tt>for</tt> requires some <tt>__iterable__</tt> object like a <tt>Set</tt> or <tt>List</tt> to work. The output: 1 2 3 4 5 6 7 8 9 10 The output looks very familiar, but the program code looks different. The first line uses the <tt> range</tt> function. The <tt> range</tt> function uses two arguments like this <tt> range(start,finish)</tt>. <tt> start</tt> is the first number that is produced. <tt> finish</tt> is one larger than the last number. Note that this program could have been done in a shorter way: Here are some examples to show what happens with the <tt> range</tt> function: >>> range(1,10) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(-32, -20) [-32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21] >>> range(5,21) [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> range(21,5) []

Remark: for the current version of Python, we need to pass the range function to  to actually print a list. For instance, we need to use  to get.

Another way to use the <tt>range</tt> function in a <tt>for</tt> loop is to supply only one argument:

The above code acts exactly the same as:

with 0 implied as the starting point. The output is 0 1 2 3 4 5 6 7 8 9

The code would cycle through the <tt>for</tt> loop 10 times as expected, but starting with 0 instead of 1.

The next line <tt>for count in onetoten:</tt> uses the <tt> for</tt> control structure. A <tt> for</tt> control structure looks like <tt> for variable in list:</tt>. <tt> list</tt> is gone through starting with the first element of the list and going to the last. As <tt> for</tt> goes through each element in a list it puts each into <tt> variable</tt>. That allows <tt> variable</tt> to be used in each successive time the for loop is run through. Here is another example to demonstrate: The output is: The Current item is: life The Current item is: 42 The Current item is: the universe The Current item is: 6 The Current item is: and The Current item is: 7 The Current item is: everything Notice how the for loop goes through and sets item to each element in the list. (Notice how if you don't want <tt> print</tt> to go to the next line add a comma at the end of the statement (i.e. if you want to print something else on that line). ) So, what is <tt> for</tt> good for? The first use is to go through all the elements of a list and do something with each of them. Here a quick way to add up all the elements: with the output simply being: The sum is: 20 Or you could write a program to find out if there are any duplicates in a list like this program does: and for good measure: Duplicate of 7  Found How does it work? Here is a special debugging version: with the output being: l = [4, 5, 7, 8, 9, 1,0,7,10]  l: [4, 5, 7, 8, 9, 1, 0, 7, 10] l.sort       l: [0, 1, 4, 5, 7, 7, 8, 9, 10] prev = l[0]    prev: 0 del l[0]       l: [1, 4, 5, 7, 7, 8, 9, 10] if prev == item:       prev: 0         item: 1 prev = item            prev: 1         item: 1 if prev == item:       prev: 1         item: 4 prev = item            prev: 4         item: 4 if prev == item:       prev: 4         item: 5 prev = item            prev: 5         item: 5 if prev == item:       prev: 5         item: 7 prev = item            prev: 7         item: 7 if prev == item:       prev: 7         item: 7 Duplicate of 7  Found prev = item            prev: 7         item: 7 if prev == item:       prev: 7         item: 8 prev = item            prev: 8         item: 8 if prev == item:       prev: 8         item: 9 prev = item            prev: 9         item: 9 if prev == item:       prev: 9         item: 10 prev = item            prev: 10        item: 10 Note: The reason there are so many <tt> print</tt> statements is because print statements can show the value of each variable at different times, and help debug the program. First the program starts with a old list. Next the program sorts the list. This is so that any duplicates get put next to each other. The program then initializes a prev(ious) variable. Next the first element of the list is deleted so that the first item is not incorrectly thought to be a duplicate. Next a for loop is gone into. Each item of the list is checked to see if it is the same as the previous. If it is a duplicate was found. The value of prev is then changed so that the next time the for loop is run through prev is the previous item to the current. Sure enough, the 7 is found to be a duplicate.

The other way to use for loops is to do something a certain number of times. Here is some code to print out the first 9 numbers of the Fibonacci series: with the surprising output: 1 1 2 3 5 8 13 21 34

Everything that can be done with <tt> for</tt> loops can also be done with <tt> while</tt> loops but <tt> for</tt> loops give an easy way to go through all the elements in a list or to do something a certain number of times.

range Versus xrange
Python 3 Note: In Python 3.x'', there is no function named. Instead, the  function has the behaviour described below for. The following applies to the legacy Python 2.''

Above, you were introduced to the  function, which returns a list of all the integers in a specified range. Supposing you were to write an expression like : that would construct a list consisting of a million integers! That can take up a lot of memory.

Often, you do indeed need to process all the numbers over a very wide range. But you might only need to do so one at a time; as each number is processed, it can be discarded from memory before the next one is obtained.

To do this, you can use the  function instead of. For example, the following simple loop

for i in xrange(0, 1000000): print(i)

will print the million integers from 0 to 999999, but it will get them one at a time from the  call, instead of getting them all at once as a single list and going through that.

This is an example of an iterator, which yields values one at a time as they are needed, rather than all at once. As you learn more about Python, you will see a lot more examples of iterators in use, and you will learn how to write your own.

The Statement
A -loop checks its termination condition before each entry into the loop body, and terminates if the condition has gone. Thus, the loop body will normally iterate zero, one or more complete times.

A -loop iterates its body once for each value returned from the iterator expression. Again, each iteration is normally of the complete loop body.

Sometimes you want to conditionally stop the loop in the middle of the loop body. An example situation might look like this:
 * 1) Obtain the next value to check
 * 2) Is there in fact another value to check? If not, exit the loop with failure.
 * 3) Is the value what I’m looking for? If so, exit the loop with success.
 * 4) Otherwise, go back to step 1.

As you can see, there are two possible exits from this loop. You can exit from the middle of a Python - or  -loop with the  -statement. Here is one way to write such a loop:

The trouble with this is the asymmetry between the two ways out of the loop: one through normal -loop termination, the other through the. As a stylistic matter, it would be more consistent to follow this principle:
 * If one exit from a loop is represented by a, then all exits from the loop should be represented by  s.

In particular, this means that the loop construct itself becomes a “loop-forever” loop; the only out of it is via a  statement.

We can do this by explicitly dealing with an iterator yielding the values to be checked. Perhaps the  call above already yields an iterator; if not, it can be converted to one by wrapping it in a call to the   built-in function, and then using the   built-in function to obtain successive values from this iterator. Then the loop becomes:

This uses the special Python value  to indicate that the iterator has reached its end. This is a common Python convention. But if you need to use  as a valid item in your sequence of values, then it is easy enough to define some other unique value (e.g. a custom dummy class) to represent the end of the list.

Exercises

 * 1) Create a program to count by prime numbers.  Ask the user to input a number, then print each prime number up to that number.
 * 2) Instruct the user to pick an arbitrary number from 1 to 100 and proceed to guess it correctly within seven tries.  After each guess, the user must tell whether their number is higher than, lower than, or equal to your guess.

Solutions

title: Python Programming/Loops


text:
Digital Signal Processing/Hilbert Transform

Definition
The Hilbert transform is used to generate a complex signal from a real signal. The Hilbert transform is characterized by the impulse response:

 * $$h(t)= {1 \over (\pi t)}$$

The Hilbert Transform of a function x(t) is the convolution of x(t) with the function h(t), above. The Hilbert Transform is defined as such:

 * $$\widehat x(t) = \mathcal{H}\{x\}(t) = (h*x)(t) = \frac{1}{\pi}\int_{-\infty}^{\infty}\frac{x(\tau)}{t-\tau}\, d\tau.\, $$

We use the notation $$\widehat x(t)$$ to denote the Hilbert transformation of x(t).


text:
Template:Print chapter heading

 = =

title: Template:Print chapter heading


text:
Category:Print Versions

This category contains resources on creating a print version for a book.

fr:Catégorie:Versions imprimables

title: Category:Print Versions


text:
MATLAB Programming/Basic Reading and Writing data from a file

MATLAB file types
There are two file types used by MATLAB namely .m and .mat files
 * .m / .mat files: Standard MATLAB files (Most functions in .mat can be supported by the older version off MATLAB)

 * .mlx files: Live Code File Format. This format were just introduced on MATLAB version R2016a. This type of files storing the live scripts/live functions that uses the Live Code file format.

Import functions
The function that usually are used to import data into MATLAB : importdata(filename) importdata(filename) can loads data into array. % sample script of loading an images >> A = importdata('example1.png'); imread(A)

Loading Data
load(filename) can loads data from filename. The files can be text, images, and even audio files. % sample script of loading an audio >> B = load('example2.mp3'); audioread(B,single,1.0)

The load command is used to load data from a file into the current workspace.
 * Load all variables from the file mySave.mat into the current workspace.

>> load('mySave.mat') >> load(fullfile(pwd, 'mySave.mat'))
 * Load just the variables myData1 and myData2.

>> load('mySave.mat', 'myData1', 'myData2')
 * Load all myData variables.

>> load('mySave.mat', 'myData*')
 * Get a cell array of variables in saved file.

>> whos('-file', 'mySave.mat')

Saving Data
The save command is used to save workspace data to a file.
 * Save all workspace data to the file mySave.mat in the current directory.

>> save('mySave.mat') >> save(fullfile(pwd, 'mySave.mat'))
 * Save just the variables myData1 and myData2 to mySave.mat.

>> save('mySave.mat', 'myData1', 'myData2')
 * Save all myData variables to mySave.mat.

>> save('mySave.mat', 'myData*')
 * Save all myData variables to a mySave.mat file compatible with version 6 of MATLAB.

>> save('mySave.mat', 'myData*', '-v6')
 * Save all myData variables to an ASCII file.

>> save('mySave.mat', 'myData*', '-ASCII')
 * Append new variables to the data file.

>> save('mySave.mat', 'newData*', '-append')

Excel Spreadsheets I/O
Since analyzing data is one of the more common motivations for using input output I will start with reading and writing from a spreadsheet. I cover the command line first since it is often necessary to import the data while an m-function is being evaluated.

Reading Excel Spreadsheets
MATLAB makes it easy to read from an Excel spreadsheet. It has the built-n command readcell

Let say, you have an Excel file (Preferably latest version with file format .xlsx ), In this example, you have a table with data shown as below saved as Class Marks.xlsx in any place of your liking To read the contents, you need to type as follows:

Pro tips: If you are unsure of the file location, right click of the file that you saved and select Properties and look for Locations in General tabs. You can change mydir into your selected locations

It will shows the output as follows A = 7×2 cell array {'Name'  }    {'Marks'} {'Ali'   }    {[   93]} {'Chin'  }    {[   47]} {'Sammy' }    {[   74]} {'Dorothy'}   {[   96]} {'Huat'  }    {[   94]} {'Anna'  }    {[   38]}

This line of code reads Class Marks.xlsx (from the saved directory - mydir) and places it in an identical array inside MATLAB called A. You can then manipulate the array A in any way you want.

Reading from certain range in the text files
From table above just now, we expand to more rows and columns as shown below in Sheet named Class1A. Note that A-> H and 1->11 are for references

In this example, we are interested, we interested in Huat marks and make an array B to extract his marks The comments explained how to select certain range of wanted data. The B array will show following results B = 1×8 cell array {'Huat'}   {[82]}    {[90]}    {[15]}    {[65]}    {[42]}    {[82]}    {[90]}

Writing Excel Spreadsheets
The writecell command allows data to be added into the Excel files.

First, we create data for our student Juan.as followed: Later on, use the writecell command (Make sure the Excel file is closed to prevent error message following)

Error using writecell (line 149) Unable to write to file 'C:\mydir\Class Marks.xlsx'. You may not have write permissions or the file may be open by another application. When you open back the Excel files: you should see Juan with his marks

Reading Text Files
If a file is not an excel spreadsheet, it can still be read using "load" function:

>> load newfile.txt

This works only if the text is entirely numerical, without special formatting. Otherwise you get an 'unrecognized character' error.

The easiest way to write to a non-excel file, or using MATLAB 6.5 or less, is to use the same code as that for writing excel files but change the extension. Usually there are no formatting difficulties with plain text files.

For reading more general text files, MATLAB does not have a function to do it easily (unless you have excel), but you can read very general text files (with different delimiters for both cells and text within cells) using the "textread.m" function in the MATLAB file exchange (do a google search to find it). You can also try to use fscanf if the formatting is consistent enough (i.e. consistent numbers of spaces, no mixing of strings and numbers in columns, and so on).

=MATLAB File I/O: from the Graphical User Interface=

MATLAB contains a nice GUI application that will guide you through importing data from any recognized data file (usually .mat, .txt, or .xls on a Windows system). To use it, go to file > import data, and select the file you want. Then, choose what column separators are present (by selecting the appropriate radio button). Finally, click "next".

MATLAB saves the variable under a name similar to that of the file, but with modifications to make it conform with MATLAB syntax. Spaces are omitted, plusses and minuses are turned into other characters. To see the name MATLAB generated (and probably change it) type "who" in the command prompt.

External Resources
ControlTheoryPro.com

MatlabCodes.Webs.com


text:
MATLAB Programming/Advanced Topics/Advanced IO/Writing and Reading to A Serial Port

Now that we've covered basic file input output (I'll get into more detailed file manipulation later) we can move on to the next step.

In the section Basic Reading and Writing data we already had the data in the form of a spreadsheet. How did it get to that spreadsheet and how do we send it some where else? This question will attempt to be answered in the following section. There are many ways to transmit and receive data. I've even heard of this newfangled thing called the easternet or internet or whatever, but for now we will assume we are in a University lab with no Internet connection (don't laugh I've been in this situation more times than I like to remember). In this case, we will use the computer's serial port, which implements the RS-232 physical layer protocol. Although this protocol is very slow (usually no more than 9600 bits/s), it's very simple to implement and thus it's used widely on embedded devices.

MATLAB provides us with there style of reading and writing to the serial port.
 * 1) You must create a serial port object.

object=serial(port,'Property name',propertyValue); Example: I will now create a serial object called serialOne

serialOne=serial('COM1', 'BaudRate', 9600);

(for those of you more familiar with C this should look very similar to creating a handle: In fact it is the MATLAB way of making handles)

Most computers call the serial ports COM and then some number usually 1-4 (depending on how many there are). This also includes DB-9, DB-25 and other various DB type connectors.

2. Now that the computer knows there is a serial port object you have to tell it to open
 * the object. Use the fopen command

3. Write to the port 4. Close object.

Example:

serialOne=serial('COM1', 'BaudRate', 9600); fopen(serialOne); fprintf(serialOne,'textFile.txt'); fclose(serialOne);


text:
WebObjects/Project WONDER/Frameworks/ERPlot

Anjo Krank:

Simple wrapper around the JFreechart framework, which can be found here: http://www.jfree.org/jfreechart/

JFreechart is a very comprehensive open-source LGPL charting framework. ERPlot is a light wrapper around some of it's features so they can be used inside WOBuilder and webobjects in general.


text:
MATLAB Programming/Arrays

Introduction to Arrays
An array is the most fundamental data type in MATLAB. In MATLAB, as in many traditional languages, arrays are a collection of several values of the same type. The string and number data type formerly presented are particular cases of arrays.

A matrix is an array with two dimensions. Most arrays have the same data type; however, a cell array is an array with varying data types. If no data type is specified for numbers, then the default data type is the equivalent to the double precision floating point in the C programming language on the same architecture. For example on x86 and PowerPC a double has 64 bits.

Row and Column Arrays
A row array is created using comma separated values inside brackets:

>> array = [0, 1, 4, 5] array = 0    1     4     5

Sometimes commas are omitted for simple row arrays. Omitting commas is not recommended because in larger more complex arrays white-spaces can be ambiguous. Commas almost always indicate an array is horizontal.

A column array is created using semicolons to separate values:

>> column = [1; 2; 3] column = 1    2     3

Declaring multi-dimensional arrays
A two dimensional array (or a matrix) is declared with commas separating columns, and semicolons separating rows:

>> matrix = [1, 2, 3; 4, 5, 6] matrix = 1    2     3     4     5     6

Simple matrix manipulation is the basis of many linear algebra computations. To use arrays of more than two dimensions, a matrix has to be extended using indexing.

When declaring arrays in MATLAB all rows and all columns need have same size. If not an error message will be generated:

>> matrix = [1, 2, 3; 4, 5] ??? Error using ==> vertcat All rows in the bracketed expression must have the same number of columns.

Indexing Arrays
Arrays are indexed using integers. To return a single element in a simple array, use a single integer.

>> array = [0, 1, 4, 5]; >> array(3) ans = 4

To return a single element in a two dimensional array one number as a row index and the second as a column index.

>> matrix = [1, 2, 3; 4, 5, 6]; >> matrix(2,2) ans = 5

To return multiple elements in an array an array can be used as an index.

>> array = [0, 1, 4, 5]; >> array([1 3]) ans = 0   4

To return the last element of an array use (end).

>> array = [0, 1, 4, 5]; >> array(end) ans = 5

A range of indexes can be returned using a colon

>> array = [0, 1, 4, 5]; >> array(2:end) ans = 1    4     5

Properties of MATLAB arrays and matrices
Contrary to low level languages such as C, an array in MATLAB is a more high level type of data: it contains various information about its size, its data type, and so on.

>> array = [0,1,4,5]; >> length(array) ans = 4 >> class(array) ans = double

The number of rows and columns of the matrix can be known through the built-in size function. Following the standard mathematical convention, the first number is the number of rows and the second is the number of columns:

>> matrix = [1, 2, 3; 4, 5, 6]; >> size(matrix) ans = 2    3

The goal of MATLAB arrays is to have a type similar to mathematical vectors and matrices. As such, row and column arrays are not equivalent. Mono-dimensional arrays are actually a special case of multi-dimensional arrays, and the 'size' function can be used for them as well.

>> size(array) ans = 1    4

Row and column do not have the same size, so they are not equivalent:

>> size(column) ans = 3    1 >> size(row) ans = 1    3

Why Use Arrays?
A major advantage of using arrays and matrices is that it lets you avoid using loops to perform the same operation on multiple elements of the array. For example, suppose you wanted to add 3 to each element of the array [1,2,3]. If MATLAB didn't use arrays you would have to do this using a FOR loop:

>> array = [1,2,3]; >> for ii = 1:3 array(ii) = array(ii) + 3; >> end >> array array = [4,5,6]

Doing this is not efficient in MATLAB, and it will make your programs run very slowly. Instead, you can create another array of 3s and add the two arrays directly. MATLAB automatically separates the elements: >> array = [1,2,3]; >> arrayofthrees = [3,3,3]; >> array = array + arrayofthrees array = [4,5,6];

If all you are doing is adding a constant, you can also omit the declaration of 'arrayofthrees', as MATLAB will assume that the constant will be added to all elements of the array. This is very useful, for example if you use an array with variable size:

>> array = [1,2,3]; >> array + 3 ans = [4,5,6]

The same rule applies to scalar multiplication.

See Introduction to array operations for more information on the operations MATLAB can perform on arrays.

Arrays are a fundamental principle of MATLAB, and almost everything in MATLAB is done through a massive use of arrays. To have a deeper explanation of arrays and their operations, see Arrays and matrices.

title: MATLAB Programming/Arrays


text:
MATLAB Programming/Saving and loading a MAT-file

<noinconclude MatlabNav}} and metal

The Current Directory and Defined Path
It is necessary to declare a current directory before saving a file, loading a file, or running an M-file. By default, unless you edit the MATLAB shortcut, the current directory will be .../MATLAB/work. After you start MATLAB, change the current directory by either using the toolbar at the left-hand side of the screen, or entering the path in the bar at the top.

The current directory is the directory MATLAB will look in first for a function you try to call. Therefore if you have multiple folders and each of them has an M-file of the same name, there will not be a discrepancy if you set the current directory beforehand. The current directory is also the directory in which MATLAB will first look for a data file.

If you still want to call a function but it is not part of the current directory, you must define it using MATLAB's 'set path' utility. To access this utility, follow the path:

file > set path... > add folder...

You could also go to "add folder with subfolders...", if you're adding an entire group, as you would if you were installing a toolbox. Then look for and select the folder you want. If you forget to do this and attempt to access a file that is not part of your defined path list, you will get an 'undefined function' error.

Saving Files
There are many ways to save to files in MATLAB.

 * save - saves data to files, *.mat by default
 * uisave - includes user interface
 * hgsave - saves figures to files, *.fig by default
 * diary [filename] - saves all the text input in the command window to a text file.

All of them use the syntax:

save filename.ext

or similar for the other functions. The files are saved in your current directory, as seen on the top of the window. By default the current directory is .../MATLAB/work.

Loading Files
Likewise, there are many ways to load files into the workspace. One way is to use the "file" menu. To open a .m file click "open", whereas to import data from a data file select "import data..." and follow the wizard's instructions.

An alternative way to load a saved .mat file (within a function, for example) is to type: >> load filename.ext The file must be in a recognized directory (usually your current directory, but at least one for which the path has been set).

The data in the .mat file is stored with the same name as the variable originally had when it was saved. To get the name of this and all other environment variables, type "who".

To open an .m file, you can use file -> open, or type >>open filename.ext

File Naming Constraints
You can name files whatever you want (usually simpler is better though), with a few exceptions:

 " / : * < > | ?
 * MATLAB for Windows retains the file naming constraints set by DOS. The following characters cannot be used in filenames:

 * You're not allowed to use the name of a reserved word as the name of a file. For example, while.m is not a valid file name because while is one of MATLAB's reserved words.

 * When you declare an m-file function, the m-file must be the same name as the function or MATLAB will not be able to run it. For example, if you declare a function called 'factorial':

function Y = factorial(X)

 * You must save it as "factorial.m" in order to use it. MATLAB will name it for you if you save it after typing the function declaration, but if you change the name of the function you must change the name of the file manually, and vice versa.


text:
MATLAB Programming/Advanced Topics/Advanced IO/Writing to a USB port

The USB port is a type of serial port. It is, after all, the Universal SERIAL Bus. I wrote that twice because all of the books I have read on USB seem to muddle that quite a bit. There are some minor and major differences to how you use the USB ports but the idea is very much the same. I did this a while back and have to reread some stuff. (I also plan to either start a wiki book about USB or join one that is already started- I have to look into this more).


text:
MATLAB Programming/Strings

Declaring Strings
Strings are declared using single quotes (  ' ): Including a single quote in a string is done this way:

Concatenate Strings
In MATLAB, multiple strings can be concatenated (linked together as a chain) using square brackets. Here are the random greeting message that are using this concatenate functions.

Inputting strings
To let user input, we can use input functions

Count the repeating words
Consider the following tounge-twister How much wood would a woodchuck chuck

if a woodchuck could chuck wood?

He would chuck, he would, as much as he could,

and chuck as much wood as a woodchuck would

if a woodchuck could chuck wood. We would like to know how many times of the word wood appeared in that tounge twister. We can use the count function. Note that the function count are counting occurrences of pattern in strings.

Therefore, it will counting the word "wood" inside the word "woodchuck" Now, we have have another examples to count the word " the" of the famous proverbs of-all-time"The quick brown fox jumps over the lazy dog"

Finding lengths of string
At times, you might be needing to find the length of words in a sentence, here is the length(string') functions comes to the rescue. As we can see in next section, it can be seen that there are exactly 43 characters inside the string.

Extracting words from Strings
To extracting certain words in the string, need to stringName(indexnumberfirst:indexnumberlast) .

We using the same example phrase as above.

Note that even empty space is consider as a string. Based on this example, if we wanted to extract the word brown fox and lazy dog,

we can see that each word is represented by index number (11:19) and index number (36:43) respectively. In MATLAB, we can type following commands:

Lowercase and Uppercase of Strings
For the string manipulations such as converting the strings to upper and lower cases, we can use lower and upper functions. This will make the strings all in lowercase and uppercase characthers respectively.

Reverse Strings
To reverse the string, we can use reverse / flip function. This will make the string reverse from the last index number to first index number and vice versa.

Replace Characters in Strings
To replace certain words in the strings, we can use replace functions

The syntax of replace functions are as followed: replace(stringName,oldword,newword) There are at times, you might want to replace multiple words in one go, therefore we need to declare the multiple strings in vector. But before that make sure, the order/sequences for old and new words are in correct order.

Strings as a Character Array
Strings in MATLAB are an array of characters. To see this, executing the following code: Because strings are arrays, many array manipulation functions work including: size, transpose, and so on. Strings may be indexed to access specific elements.

Performing arithmetic operations on character arrays converts them into doubles. These numbers are from the ASCII standard for each character in the array. These values are obtained using the double function to turn the array into an array of doubles. The 'char' function can turn an array of integer-valued doubles back into characters. Attempting to turn a decimal into a character causes MATLAB to round down:

Special String Functions
Since MATLAB strings are character arrays, some special functions are available for comparing entire strings rather than just its components:

deblank
deblank removes white spaces from the string.

findstr
findstr(bigstring, smallstring) looks to see if a small string is contained in a bigger string, and if it is returns the index of where the smaller string starts. Otherwise it returns [].

strrep
strrep(string1, replaced, replacement) replaces all instances of replaced in string1 with replacement

strcmp
Strings, unlike rational arrays, do not compare correctly with the relational operator. To compare strings use the strcmp function as follows: Note that MATLAB strings are case sensitive so that 'a' and 'A' are not the same. In addition the strcmp function does not discard whitespace: The strings must be exactly the same in every respect.

If the inputs are numeric arrays then the strcmp function will return 0 even if the values are the same. Thus it's only useful for strings. Use the == operator for numeric values.

num2str
Convert numbers to character. This functions is useful when you want to use function disp values to limit the display of decimal point.

Displaying values of string variables
If all you want to do is display the value of a string, you can omit the semicolon as is standard in MATLAB.

If you want to display a string in the command window in combination with other text, one way is to use array notation combined with either the 'display' or the 'disp' function:

MATLAB doesn't put the space in between the two strings. If you want one there you must put it in yourself.

This syntax is also used to concatenate two or more strings into one variable, which allows insertion of unusual characters into strings: Any other function that returns a string can also be used in the array.

You can also use the "strcat" function to concatenate strings, which does the same thing as above when you use two strings, but it is especially useful if you are using a cell array of strings because it lets you concatenate the same thing to all of the strings at once. Unfortunately you can't use it to add white space (strcat discards what MATLAB considers extraneous whitespace). Here's the syntax for this use.

Finally, although MATLAB doesn't have a printf function you can do essentially the same thing by using 1 as your file identifier in the fprintf function. The format identifiers are essentially the same as they are in C.

The "9.200" is printed to the screen. fprintf is nice compared to display because you don't have to call num2str on all of the numbers in a string - just use the appropriate format identifer in the place you want it.

Cell arrays of strings
In many applications (particularly those where you are parsing text files, reading excel sheets with text, etc.) you will encounter cell arrays of strings.

You can use the function "iscellstr" to tell if all of the elements in a given cell array are strings or not.

This is useful since functions that work with cell arrays of strings will fail if provided with something that's not a cell array of strings. In particular, they all fail if any elements of the provided cell array are the empty array ( [] ) which is somewhat frustrating if the provided text file contains empty cells. You must catch this exception before calling cellstr manipulation functions.

Searching a cell array of strings can be done with the "strmatch", "strfind", and "regexp" functions. Strmatch looks for a string within a cell array of strings whose first characters exactly match the string you pass to it, and returns the index of all strings in the array for which it found a match. If you give it the 'exact' option, it will only return the indexes of elements that are exactly the same as what you passed. For example:

Strfind looks for a specific string within a cell array of strings, but it tries to find it in any part of each string. For each element x of the given cell array of strings, it will return an empty array if there is no match found in x and the starting index (remember, strings are arrays of characters) of all matches in x if a match to the query is found.

The "cellfun" / "isempty" combination is very useful for identifying cases where the string was or was not found. You can use the find function in combination with these two functions to return the index of all the cells in which the query string was found.

The strfind function also has some other options, such as the option to only return the index of the first or last match. See the documentation for details.

The regexp function works the same way as strfind but instead of looking for strings literally, it tries to find matches within the cell array of strings using regular expressions. Regular expressions are a powerful way to match patterns within strings (not just specific strings within strings). Entire books have been written about regular expressions, so they cannot be covered in as much detail here. However, some good resources online include regular-expresions.info and the MATLAB documentation for the matlab-specific syntax. Note that MATLAB implements some, but not all, of the extended regular expressions available in other languages such as Perl.

Unfortunately, MATLAB does not innately have functions to do common string operations in some other languages such as string splitting. However, it is quite possible to find many of these functions in a google search.

title: MATLAB Programming/Strings


text:
MATLAB Programming/Advanced Topics/Toolboxes and Extensions/Symbolic Toolbox

Introduction to the Symbolic Math Toolbox
The symbolic toolbox is a bit difficult to use but it is of great utility in applications in which symbolic expressions are necessary for reasons of accuracy in calculations. The toolbox simply calls the MAPLE kernel with whatever symbolic expressions you have declared, and then returns a (usually symbolic) expression back to MATLAB. It is important to remember that MAPLE is not a numeric engine, which means that there are certain things it doesn't let you do that MATLAB can do. Rather, it is useful as a supplement to provide functions which MATLAB, as a numerical engine, has difficulty with.

The symbolic math toolbox takes some time to initialize, so if nothing happens for a few seconds after you declare your first symbolic variable of the session, it doesn't mean you did anything wrong.

The MATLAB student version comes with a copy of the symbolic math toolbox.

Symbolic Variables
You can declare a single symbolic variable using the 'sym' function as follows.

>> a = sym('a1') a = a1

You can create arrays of symbolic expressions like everything else:

>> a1 = sym('a1'); >> a2 = sym('a2'); >> a = [a1, a2] a = [ a1, a2]

Symbolic variables can also be declared many at a time using the 'syms' function. By default, the symbolic variables created have the same names as the arguments of the 'syms' function. The following creates three symbolic variables, a b and c.

>> syms a b c >> a a = a

Symbolic Numbers
Symbolic numbers allow exact representations of fractions, intended to help avoid rounding errors and representation errors. This section helps explain how to declare them.

If you try to add a number into a symbolic array it will automatically turn it into a symbolic number.

>> syms a1, a2; >> a = [a1, a2]; >> a(3) = 1; %would normally be class 'double' >> class(a(3)) ans = sym

Symbolic numbers can also be declared using the syntax a(3) = sym('number'). The difference between symbolic numbers and normal MATLAB numbers is that, if possible, MAPLE will keep the symbolic number as a fraction, which is an exact representation of the answer. For example, to represent the number 0.5 as a fraction, you can use:

>> sym(0.5) ans = 1/2

Here, of course, MATLAB would normally return 0.5. To make MATLAB change this back into a 'double', type:

>> double(ans) ans = 0.5000

Other class conversions are possible as well; for instance, to change it into a string use the 'char' function. There is no function to directly change a symbolic variable into a function handle, unfortunately.

A caveat: Making a symbolic variable of negative exponentials can create problems if you don't use the correct syntax. You cannot do this:

>> sym('2^-5') ??? Error using ==> sym.sym>char2sym Not a valid symbolic expression.

Instead, you must do this:

>> sym('2^(-5)') ans = 2^(-5)

MAPLE is thus more picky about what operators you can use than MATLAB.

Symbolic Functions
You can create functions of symbolic variables, not just the variables themselves. This is probably the most intuitive way to do it:

>> syms a b c %declare variables >> f = a + b + c ans = a + b + c

If you do it this way, you can then subsequently perform substitution, differentiation, and so on with respect to any one of these variables.

If you want to create an actual function, it's not much harder:

>> syms a b c >> f(a,b,c) = a + b + c % or f = symfun(a + b + c, [a b c]) if you want to be more explicit f(a, b, c) = a + b + c >> f(1,2,3) ans = 6

Substituting Values into Symbolic Variables
Substitutions can be made into functions of symbolic variables. Suppose you defined the function f = a + b + c and wish to substitute a = 3 into f. You can do this with the following syntax:

>> syms a b c %declare variables >> f = a + b + c; >> subs(f, a, 3) ans = 3+b+c

Notice the form of this function call. The first argument is the name of the function you wish to substitute into. The second can be either the name of the symbolic variable you want to plug in for or its present value, but if you want to avoid confusion they should be the same anyway. The third argument is the value you want to plug in for that variable.

The value you're plugging in need not be a number. You can also plug in other variables (including those already present in the function) by using strings. Using the same f:

>> subs(f, a, 'x') ans = x+b+c >> subs(f, a, 'b') ans = 2*b + c

If x is already a symbolic variable you can omit the quotes (but if it's not you'll get an undefined variable error):

>> syms x >> subs(f,a,x) ans = x+b+c

Multiple substitutions are allowed; to do it, just declare each of them as an array. For example, to plug in 1 for a and 2 for b use:

>> subs(f, [a,b], [1,2]) ans = 3+c

Finally, if you substitute for all of the symbolic values in a function MATLAB automatically changes the value back into a double so that you can manipulate it in the MATLAB workspace.

>> subs(f, [a,b,c], [1,2,3]) ans = 6 >> class(ans) ans = double

Using Functions with Symbolic Matrices as Inputs
Unfortunately, symfun does not seem to allow using a symbolic matrix as a function input. You can manually add each element of the matrix to the list of input variables, or even use subs to iteratively substitute the input values if you're just using a symbolic expression, but both solutions would require typing out all of the indexing. Instead, the simplest path is to declare an anonymous function:

>> A = sym('A',2) % declare a 2x2 symbolic matrix >> sum_elements = @(myMat) myMat(1,1) + myMat(1,2) + myMat(2,1) + myMat(2,2); sum_elements = @(myMat)myMat(1,1)+myMat(1,2)+myMat(2,1)+myMat(2,2) >> sum_elements(A) ans = A1_1 + A1_2 + A2_1 + A2_2

Algebraic Function Manipulations
The symbolic math toolbox allows you several different ways to manipulate functions. First off you can factor a function using 'factor' and multiply it out using 'expand':

>> syms a b >> f = a^2 - 2*a*b + b^2; >> factor(f); ans = (a - b)^2 >> expand(ans) ans = a^2 - 2*a*b + b^2

The 'collect' function does the same thing as the 'expand' function but only affects polynomial terms. 'Expand' can also be used to expand trigonometric and logarithmic/exponential functions with the appropriate identities.

The Horner (nested) representation for a function is given by 'horner':

>> horner(f) ans = b^2+(-2*b+a)*a

This representation has a relatively low number of operations required for its evaluation compared to the expanded version and is therefore helpful in making calculations more efficient.

A common problem with symbolic calculations is that the answer returned is often not in its simplest form. MATLAB's function 'simple' will perform all of the possible function manipulations and then return the one that is the shortest. To do this do something like:

>> Y = simple(f) Y = (a - b)^2

Algebraic Equations
The symbolic math toolbox is able to solve an algebraic expression for any variable, provided that it is mathematically possible to do so. It can also solve both single equations and algebraic systems.

Solving Algebraic Equations With a Single Variable
MATLAB uses the 'solve' function to solve an algebraic equation. The syntax is solve(f, var) where f is the function you wish to solve and var is the variable to solve for. If f is a function of a single variable you will get a number, while if it is multiple variables you will get a symbolic expression.

First, let us say we want to solve the quadratic equation x^2 = 16 for x. The solutions are x = -4 and x = 4. To do this, you can put the function into 'solve' directly, or you can define a function in terms of x to solve and pass that into the 'solve' function. The first method is rather intuitive:

>> solve('x^2 = 16', x) ans = -4 4 >> solve(x^2 - 16, x) ans = -4 4

Either of these two syntax works. The first must be in quotes or you get an 'invalid assignment' error. In the second, x must be defined as a symbolic variable beforehand or you get an 'undefined variable' error.

For the second method you assign a dummy variable to the equation you want to solve like this:

>> syms x >> y = x^2 - 16; >> solve(y, x);

Note that since MATLAB assumes that y = 0 when you're solving the equation, you must subtract 16 from both sides to put the equation into normal form.

Solving Symbolic Functions for Particular Variables
The format for doing this is similar to that for solving for a single variable, but you will get a symbolic function rather than a number as output. There are a couple of things to look out for though.

As an example, suppose that you want to solve the equation y = 2x + 4 for x. The expected solution is x = (y-4)/2. Lets see how we can get MATLAB to do this. First let's look at how NOT to do it:

>> syms x >> y = 2*x + 4; >> solve(y, x) ans = -2

What has happened here? The MATLAB toolbox assumes that the 'y' you declared is 0 for the purposes of solving the equation! So it solved the equation 2x + 4 = 0 for x. In order to do what you intended to do you have to put your original equation, y = 2x + 4, into normal form, which is 2x + 4 - y = 0. Once this is done, you need to assign a 'dummy' variable like this:

>> syms x y >> S = 2*x + 4 - y; %S is the 'dummy' >> solve(S, x) ans = -2 + 1/2*y

This is, of course, the same thing as what we expected. You could also just pass the function into the 'solve' function like this, as done with functions of a single variable:

>> solve('y = 2*x + 4', x);

The first method is preferable, because once it is set up it is much more flexible to changes in the function. In the second method you would have to change every call to 'solve' if you changed the function at all, whereas in the first you only need to change the original definition of S.

Solving Algebraic Systems
The 'solve' command also allows you to solve systems of algebraic equations, and will attempt to return all solutions to these systems. As a first example, let us consider the linear system

a + b = 3 a + 2*b = 6,

which has the solution (a,b) = (0,3). You can tell MATLAB to solve it as follows:

>> syms a b >> f(1) = a + b - 3; >> f(2) = a + 2*b - 6; >> [A,B] = solve(f(1), f(2)) A = 0 B = 3

If only one output variable is specified but there are multiple equations, MATLAB will return the solutions in a struct array:

>> SOLUTION = solve(f(1), f(2)) SOLUTION = a: [1x1 sym] b: [1x1 sym] >> SOLUTION.a a = 0 >> SOLUTION.b b = 3

The good thing about this is that the fields have the same names as the original variables, whereas in the other form it is easy to get confused which variable is going into which spot in the array. In addition, the struct array is more convenient for large systems.

Now let us look at a slightly more complex example:

a^2 + b^2 = 1 a + b = 1

This has solutions (a,b) = (0,1) and (a,b) = (1,0). Now putting this into MATLAB gives:

>> f = [a^2 + b^2 - 1, a + b - 1]; SOLUTION = solve(f(1), f(2)); >> SOLUTION.a ans = 1 0 >> SOLUTION.b ans = 0 1

Here both solutions are given, a(1) corresponds to b(1) and a(2) corresponds to b(2). To get one of the solutions into a single array together you can use normal array indexing, as in:

>> Solution1 = [SOLUTION.a(1), SOLUTION.b(1)] Solution1 = [1, 0]

Analytic Calculus
MATLAB's symbolic toolbox, in addition to its algebraic capabilities, can also perform many common calculus tasks, including analytical integration, differentiation, partial differentiation, integral transforms, and solving ordinary differential equations, provided the given tasks are mathematically possible.

Differentiation and Integration with One Variable
Differentiation of functions with one or more variables is achieved using the 'diff' function. As usual, you can either define the function before the differentiation (recommended for M files) or you can manually write it in as an argument (recommended for command-line work). If there is only one symbolic variable in the expression, MATLAB assumes that is the variable you are differentiating with respect to. The syntax is simply:

>> syms x >> f = x^2 - 3*x + 4; >> diff(f) % or diff('x^2 - 3*x + 4') ans = 2*x - 3

Integration, similarly, is achieved using the 'int' function. Only specifying the function results in an indefinite integral, or the antiderivative of the function.

>> int(f) ans = x^3/3 - (3*x^2)/2 + 4*x

Note that if you only specify one output argument (or none at all), the 'int' function omits the integration constant. You just have to know it's there.

To do a definite integral on a one-variable function, simply specify the beginning and end points.

>> int(f, 0,1) ans = 17/6

Differentiation and Integration of Multivariable Functions
A convenient way of representing the derivatives of multivariate functions (partial derivatives) is with the Jacobian, which is performed by the 'jacobian' function. To use it, you should define an array of symbolic functions and then just pass it to the function (note the difference between the use of this function, which requires all equations to be in the same array, and the use of 'solve', which requires you to separately pass each equation):

>> syms a b >> f = [a^2 + b^2 - 1, a + b - 1]; >> Jac = jacobian(f) Jac = [ 2*a, 2*b] [  1,   1]

Note that the first row is the gradient of f(1) and the second the gradient of f(2).

If you only want a specific partial derivative, not the entire Jacobian, you can call the 'diff' function with the function you want to differentiate and the variable you wish to differentiate with respect to. If none is specified, differentiation occurs with respect to the variable closest to 'x' in the alphabet.

>> diff(f(1), a) ans = 2*a

It is worth noting that to complete an implicit differentiation, one can explicitly state the implicit assumption by multiplying the differentiated function by $$ \frac{d}{dx_i}$$, where $$ x_i$$ is the ith variable in a multivariable equation.

Indefinite integration of multivariate functions works the same as for single functions; pass the function and MATLAB will return the indefinite integral with respect to the variable closest to x:

>> int(f(1)) ans = a^2*b+1/3*b^3-b

This is the integral with respect to b. To avoid confusion, you can specify the variable of integration with a second argument, as with differentiation.

>> int(f(1), a) ans = 1/3*a^3+b^2*a-a

Definite integration (as far as I can tell) can only be done with respect to one variable at a time, and this is done by specifying the variable, then the bounds:

>> int(f(1), a, 1, 2) %integrate a from 1 to 2, holding b constant ans = 4/3 + b^2

Analytic Solutions to ODEs
MATLAB can solve some simple forms of ODEs. Unlike with the integration and algebraic solving techniques, the syntax for the differential equation solver required that you put the function in manually in a specific manner. The derivatives can be specified using the symbol 'DNV', where N is the order of the derivative and V is the variable that is changing. However, newer versions of MATLAB support entering differential equations in the form of symbolic equalities. For example, suppose you seek the solution to the equation $$ \frac{d^2}{dt^2}x = -x$$, the solutions to which are of the form x(t) = A*cos(t) + B*sin(t). You would put this equation into the 'dsolve' function as follows:

>> syms x >> dsolve('D2x = -x') ans = C1*sin(t)+C2*cos(t) >> % or >> syms x(t) >> dsolve(diff(x, t, 2) == -x) ans = C1*sin(t)+C2*cos(t)

Unlike the 'int' function, dsolve includes the integration constants. To specify initial conditions, just pass extra arguments to the 'dsolve' function as strings. If x'(0) = 2 and x(0) = 4 these are inserted as follows:

>> dsolve('D2x = -x', 'Dx(0) = 2', 'x(0) = 4') ans = 2*sin(t)+4*cos(t) >> % or >> Dx = diff(x, t); >> dsolve(diff(x, t, 2) == -x, Dx(0) == 2, x(0) == 4) ans = 2*sin(t)+4*cos(t)

Note that the initial conditions can also be passed as strings.

MATLAB can also solve systems of differential equations. An acceptable syntax is to pass each equation as a separate string, and then pass each initial condition as a separate string:

>> % in older versions you were required to use strings >> % SOLUTION = dsolve('Df=3*f+4*g', 'Dg =-4*f+3*g', 'f(0) = 0', 'g(0) = 1') >> syms f(t) g(t) >> SOLUTION = dsolve(diff(f) == 3*f + 4*g, diff(g) == -4*f + 3*g, f(0) == 0, g(0) == 1) SOLUTION = f: [1x1 sym] g: [1x1 sym] >> SOLUTION.f SOLUTION.f = exp(3*t)*sin(4*t) >> SOLUTION.g SOLUTION.g = exp(3*t)*cos(4*t)

The 'dsolve' function, like 'solve', thus returns the solution as a structure array, with field names the same as the variables you used. Also like 'solve', you can place the variables in separate arrays by specifying more than one output variable.

Integral Transforms
MATLAB's symbolic math toolbox lets you find integral transforms (in particular, the Laplace, Fourier, and Z-transform) and their inverses when they exist. The syntax is similar to the other symbolic math functions: declare a function and pass it to the appropriate functions to obtain the transform (or inverse).


text:
MATLAB Programming/Inserting Newlines into Plot Labels

Cell arrays are the easiest way to generate new lines when using the functions xlabel,  ylabel,  zlabel,  text,  title, and  gtext. However, cell arrays do not always work (see next section).

When displaying text on plots, "\n" is typically interpreted as '\' followed by 'n' instead of the newline character. To generate multiple lines, use cell arrays. This is done by separating each string line of text with a comma and enclosing all comma-separated strings in curly braces as follows. >> title({'First line','Second line'})

Sometimes it is nice to put the value of a variable and a newline into the plot title. You can do this like so:

n = 4; x = -n:1:n; y = x.^2; plot(x,y) title( [ 'plot of x squared', 10, 'from x = ', num2str(-n), ' to x = ', num2str(n) ] )

The 10 outside the single quotes is the ascii value for a newline. You don't have to use the char function, just the number will work.

The output should look like this:

plot of x squared from x = -4 to x = 4