chapter 6: mupad objects ii sequence, list, set, function matlab for scientist and engineers using...

28
Chapter 6: MuPAD Objects II Sequence, List, Set, Function MATLAB for Scientist and Engineers Using Symbolic Toolbox

Upload: ronnie-bloodsworth

Post on 15-Dec-2015

244 views

Category:

Documents


0 download

TRANSCRIPT

Chapter 6:

MuPAD Objects IISequence, List, Set, Function

MATLAB for Scientist and Engineers

Using Symbolic Toolbox

2

You are going to See that MuPAD handles objects Get to know MuPAD sequences, lists, sets,

and function types Use these objects for various purposes

3

Sequences

A series of MuPAD objects separated by com-mas.

Concatenation

Just Numbers and Repeats

4

Sequences (cont.)

Range using in

Application: Repeated differentiation

Manipulation

Apply to all operands

Modify 1st Object

Delete 2nd Object

5

Exercise

Assign the values x1=1, x2=2, . . . , x100=100 to the identifiers x1, x2, . . . , x100.

6

Exercise

Generate the sequence

7

Exercise

Use a simple command to generate the dou-ble sum

Hint: the function _plus accepts arbitrarily many argu-ments. Generate a suitable argument sequence.

8

Lists – DOM_LIST

An ordered sequence of arbitrary MuPAD ob-jects enclosed in square brackets

Parallel Assignment

Swap

Two. assignments happen atthe same time

9

Lists – Substitute, Concatenate

Substitution may make the list longer.

List Concatenation

10

Lists - Sort

Numerical Values or Strings

Min and Max

11

Lists – Other Operations

Returns TRUE if the elementhas it as an operand.

TRUE FALSE UNKNOWN L1 L2

12

Lists – Function Summary

13

Exercise

Generate two lists with the elements a, b, c, d and 1, 2, 3, 4, respectively. Concatenate the lists. Multiply the lists pairwise.

14

Exercise

Multiply all entries of the list [1, x, 2] by 2. Suppose you are given a list, whose ele-ments are lists of numbers or expressions, such as [[1, x, 2], [PI], [2/3, 1]], how can you multiply all entries by 2?

15

Exercise

Let X = [x1, . . . , xn] and Y = [y1, . . . , yn] be two lists of the same length.

Find a simple method to compute their

“inner product”

x1 y1 + · · · + xn yn,

You can achieve this by using zip, _plus, map and appropriate functions

16

Sets – DOM_SET

An unordered sequence of arbitrary objects enclosed in curly braces

Basic Operations

17

Sets – Other Operations

map / contains / select / split

18

Sets – Function Summary

19

Exercise

How can you convert a list to a set and vice versa?

20

Exercise Instead of the binary operators intersect and union, you

can also use the corresponding MuPAD functions _in-tersect and _union to compute unions and intersec-tions of sets. These functions accept arbitrarily many ar-guments. Use simple commands to compute the union and the intersection of all sets belonging to M:

M := {{2, 3}, {3, 4}, {3, 7}, {5, 3}, {1, 2, 3, 4}}:

21

Functions

How to define functions

-> represent mapping

22

Function – Composition

@ - Composition Operator

23

Functions - Operations

Expression and Functions

Operations

Evaluate and assign

Differentiation

24

Exercise

Define the functions f(x) = x2 and g(x) = .

Compute f (f (g(2)) and f(f(. . . f (x) . . .)).x

100 times

25

Exercise

Define a function that reverses the order of the elements in a list.

26

Key Takeaways

Now, you are able to generate sequences using a range operators, manipulate lists, apply basic operations on sets, and to define/derive functions using @ operators.

27

Summary

Explain the following expressions

$ 10..20 x $ 3 [a,b] := [b,a] list1.list2

sort(list) min(list) max(list)

select(list,has,x) split(list,has,x)

zip(list1,list2,_plus,x)

map(set1,sin)

set1 union set2

f @ g

f @@ 3

28

Notes