This action might not be possible to undo. Are you sure you want to continue?

BooksAudiobooksComicsSheet Music### Categories

### Categories

### Categories

Editors' Picks Books

Hand-picked favorites from

our editors

our editors

Editors' Picks Audiobooks

Hand-picked favorites from

our editors

our editors

Editors' Picks Comics

Hand-picked favorites from

our editors

our editors

Editors' Picks Sheet Music

Hand-picked favorites from

our editors

our editors

Top Books

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Audiobooks

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Comics

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Sheet Music

What's trending, bestsellers,

award-winners & more

award-winners & more

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

Functional Programming & Data Structures Click to edit Master subtitle style

5/18/12

Required Tools

§ Next few weeks, we will use Mathematica as an example of a functional programming language. § Along the way, we shall be introduced to exact computations and Symbolic Algebra. We will also be able to use the numerical and graphical capabilities to do engineering computations. Its rich compendium of mathematical functions and algorithms will be demonstrated. 5/18/12

The following will be needed § A fully licensed copy of Mathematica 7 or 8. § A pdf copy of the Mathematica Book, version 5. § A copy of the Mathematica Cookbook With these, it should be a straightforward matter to practice the required examples before coming to class. That way, you will be able to ask more useful questions and gain more for the time we spend together in class. § Acquaint yourself with the Mathematica Documentation system installed with your 5/18/12 copy of the software. In most cases, you can

Notational Conventions

5/18/12

List Processing

Lists are created using braces and nested braces. They can be indexed into via double brackets. For example: We create a double list here and call it M. We then ask Mathematica to display it in MatrixForm. We can pick the second element – in this case also a list. We look at the first element of this sub-list and we obtain 3. Finally, we ask for the determinant of the 5/18/12 matrix.

Assignments & Equations

You can use the equals sign for arithmetic assignment as you have been doing in your C Sharp programming. It works exactly the same way and it will assign the result of the computation on the right to the identifier on the left.

§ A new twist is that there can be undefined identifiers on the RHS. Mathematica will process that symbolically. § A colon with an assignment requests a delay in the processing. Recall the previous matrix above.

5/18/12

§ A double equals (==) is used for an equation.

Simultaneous Equations

∗ As you can see in the above equations, they may be linear or nonlinear, Mathematica will solve them if their solutions can be found. 5/18/12 Note the (==)

Built-In functions

§ The list of built-in functions is quite impressive. They contain ALL elementary functions and most special functions. It is difficult to imagine an important mathematical function that is left out. Even if this happens, it is possible to connect Mathematica to your C-Sharp code and define new functions. § More about that later.

5/18/12

Numerical Types

§ The following numerical types are supported in Mathematica: Integers, Real, Rational and Complex. § The Mathematica function Head[] can tell you the underlying structure of the result of any expression as you can see here. § Exact results are displayed in their entirety when possible or symbolically when full display would be impossible due to the infinity of the exact representation. 5/18/12

**Full Forms of Expressions
**

∗ In the example shown here, we can ask Mathematica to add two numbers using our usual addition syntax. We could even add undefined elements, in this case Mathematica assumes a symbolic manipulation and provides whatever answers are reasonable. The full form of these actions are actually functions as the last example shows. Try and interprete: ∗ Times[9,5,3], Divide[Sin[x],x]. 5/18/12

Limits Example

You always knew this didn’t you? That both sine as well as the tangent of x tend to x as x approaches zero. You can use a simple Mathematica plot to settle this matter for any doubter as shown!

5/18/12

Precision & Accuracy

§ You may do exact computations with Mathematica. At other times you may want to perform numerical approximations for several reasons. Accuracy and precision will become important issues when you do this. § For most purposes, treat precision as the total number of digits in the decimal representation of a number and accuracy as the total number of digits after the decimal

5/18/12

Notational Variety

There can be a variety in the ways you can supply a computation request to Mathematica. Some of these are shown with simple examples. The infix is the way of most operators but not limited to them. o Functional notation: Divide [Sin[x],x], N[Sqrt[2]] o Infix notation: Sin[x]/x o Postfix notation: Sqrt[2]//N 5/18/12

Interval Arithmetic

We introduce Interval Arithmetic here by way of a simple example:

5/18/12

§

Infix Apply

§ The equivalency of the two types of interval calculation above can be further explained as follows: § Apply replaces the head of a list with a new head – in this case, the Subtract. In the above form, the Apply command was used in its prefix format.

5/18/12

Asking for help

§ I can seek assistance by using the double question mark: ??Integrate prompts the system to give assistance on the Integrate[] function. § I can also ask Mathematica to show me how to use the Sin[] function in the Prefix format by

5/18/12

Graphics Project

§ Conclude this introductory class with a simple graphical project by a student three years ago. § Let this stimulate your mind to what you can do in your course project. § Mathematica can be used to create useful products by students who are smart enough to go beyond the requirements of the simple examples and class practice.

5/18/12

First Lecture on Algorithms and Data Structures SSG 314 University of Lagos. Continue from OOP treatment of SSG 313

First Lecture on Algorithms and Data Structures SSG 314 University of Lagos. Continue from OOP treatment of SSG 313

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue listening from where you left off, or restart the preview.

scribd