Maple Software Tutorial for Modelling

22
Maple Software Tutorial

description

Maple Software Tutorial for the IO2081 Modelling Course of the faculty of Industrial Design of the TU Delft

Transcript of Maple Software Tutorial for Modelling

Page 1: Maple Software Tutorial for Modelling

Maple Software Tutorial

Page 2: Maple Software Tutorial for Modelling

MapleDoc, IO, TU DelftMathematical Symbols

Page 3: Maple Software Tutorial for Modelling

Product en

beweging

ConstruerenProduct

in werking

Modeling

MapleDocY. Song (Wolf) B.Eng, M.Sc., Ph.D.

Erik W. Thomassen M.Sc.

Faculty of Industrial Design Engineering

Delft University of Technology

The Arts of Computing

Page 4: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 2

Whenever facing a more complex (or “wicked”) design problem which is mathematically solvable, we can benefit from the force of a systematic application such as Maple as a designer’s tool. Maple’s strength lies in that is not merely providing a number as the output to a question, but in adding insight into that question by showing its parametrical relations. A simplified formula itself can be seen as the result, lifting this time to a more fundamental level. It allows system thinking, along with producing valuable output. Understanding the system helps tremendously in rationally improving a design, as well as in communicating about it.

What your system is all about is finally up to you. Within this course we use Maple models for mechanics, thermo- and fluid dynamics. But if you’re interested in other aspects of design or research you can use it too: there is no limit to your imagination.

We know that Maple may seem rather inaccessible in the beginning: that’s why we wrote this manual. But don’t let that put you off: we are convinced that a vast majority of you will appreciate its opportunities in the end.

Erik W. Thomassen, industrial design engineer.

Preface: Why should industrial design engineers use Maple?

Page 5: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 3

Maple – A general purpose computer algebra system

In April 2008, Maplesoft™ celebrated twenty years of being a corporation. Its core intellectual property, Maple™, was developed as an advanced research project at the University of Waterloo, Canada, in the early 1980s. It is currently a private company, with headquarters in Waterloo, Ontario, Canada.

Maple is one of the leading general-purpose commercial computer algebra system and widely used in engineering, science, and mathematics. Maplesoft’s customers include Ford, BMW, Bosch, Boeing, NASA, Canadian Space Agency, Canon, Motorola, Microsoft Research, Bloomberg, and DreamWorks, covering sectors such as automotive, aerospace, electronics, defense, energy, financial services, consumer products and entertainment. Over 90% of advanced research institutions and universities worldwide, including MIT, Stanford, Oxford, the NASA Jet Propulsion Laboratory and the U.S. Department of Energy, have adopted Maplesoft solutions to enhance their education and research activities.

The architecture of Maple is based around a small kernel, written in C, which provides the Maple language. Besides this kernel, many numerical libraries, such as NAG, etc. are used. The standard interface and calculator interface are written in Java. The classic interface is written in C. Maple is cross-platform software. The current version is Maple 17, which was released in March 2013.

Maple 16: The starting window

Maple ≈ Canada?

Page 6: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 5

Install Maple on your computer

Preparation Download Installation Activation

Check OS of your computer

Check memory & free space on hard disk: Memory >=2G, HD>=2G

Windows:XP, Vista, 7; 32 or 64 bit

Mac:OS version > OS 10.5

Blackboard->Software-> Maple

http://www.maplesoft.com/products/system_requirements.aspx

http://www.maplesoft.com/support/install/maple15_install.html

Single user license installation

Purchase code:QR3N8D79YHUUEE92

Connected to TU Delft network (use VPN at home)

Page 7: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 6

The Maple interface & Important shortcuts

New file

Open

Save

Print

Print Preview

Insert plain text after

Insert Maple commands after

Execute the whole Maple sheet

Enclose current work in a sub section

Remove current section

Execute the selected work groups

The working

areaDynamic helpMaple tools

System status Memory usage

Time used to execute

the commands

Mode at the cursor

position: Math mode or

Text mode

Fonts & Mode

Page 8: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 7

Hallo, Maple

ProblemsTom drives a lorry from Delft to Rotterdam (15KM distance) at a speed of 80 km/hour. How long it will take him to reach Rotterdam.

RotterdamDelft

15KM

80 KM/Hour

Lorry

Find a blank paper

The distance between Delft and Rotterdam is:

15 ( )

The speed of the lorry is:

80 ( / )

The time needed is:

15 0.1875 ( )

80

Convert hours to minutes

minutes = t × 60 = 0.1875 × 60 = 11.

dis km

v km h

dist h

v

25 (minutes)

Hand writingHand writing

vs Maple

Page 9: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 8

General guidelines in creating a Maple file

Page 10: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 9

In Maple, you can work with either Document mode or

Worksheet mode. Both provide different ways how to

get required results. You can use any of them at your

convenience, and of course, switch between them during

your work.

Document mode can create interactive documents, and it

focuses on What You See Is What You Get

(WYSIWYG).

Worksheet mode is Maple´s traditional environment and

all commands start with a red [>. For the sake of a clear

syntax structure, worksheet mode is used here.

In the following two figures, an Ordinary Differential

Equation (ODE) is solved in the two modes,

respectively.

We strongly recommend worksheet mode

Tips & tricks in Maple

Clear the memory: Using restart when each section starts

Document mode & Worksheet mode

Document mode

Worksheet mode

Page 11: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 10

All Maple commands should end with a semi-colon “;” or a colon“:”. If ended with a “:”, the system will hide the response.

To define a variable, use” := ”; the “ = ” sets up an equation.

The evalf command is used to evaluate a symbolic expression numerically to n digits accuracy.[>evalf(Pi,8);

3.1415926The expand command may be used to expand an algebraic expression. [>expand((x+2)^3);

x3+6x2+12x+8The simplify command may be used to simplify complicated expressions.[>simplify( (x+3)^3 - (x-3)^3 )

12x2+16The subs commands may be used to make a substitution, [>f:=x^3+2*x + 7; subs( x=x^2, f);

x6 + 2x2 + 7

The plot command may be used to plot simple graphs,[>plot( x^3, x=-3..3);

Commands frequently used in Maple

The diff command is used to compute the (partial) derivative of a function.[>diff(sin(Pi*x), x);

cos(πx)πThe int command can be used to calculate the indefinite or definite integral.[>f:=2x; int(f, x) ;

x2

To compute the definite integral, use[>f:=2x; int(f, x = a..b) ;

b2-a2

Commands solve, fsolve can be used to solve an equation or set of equations for a variable or set of variables. The fsolve command solves the equations numerically for real solutions, whereas solve may give complex numbers as solutions.[>solve( {x-y=3, 3*x-2*y=-1}, {x,y})

Page 12: Maple Software Tutorial for Modelling

> >

> >

> >

> >

(1.2)(1.2)

> >

(1.3)(1.3)

> >

(1.1)(1.1)

> >

> >

(1.4)(1.4)

> >

> >

Time from Delft to Rotterdamclean the memory

distances

speed

time

change time from hours to minutes

conclusion: it will take Tom 11.25 minutes

Page 13: Maple Software Tutorial for Modelling

> >

(1.3)(1.3)

> >

(1.4)(1.4)

> >

(1.6)(1.6)

> >

> >

(1.2)(1.2)

(1.1)(1.1)

(1.5)(1.5)

Do NOT use document mode

DO NOT

15

80

316

Write eqautions always behind a red arrow by click "[>" button

Reason: A hybrid text and equations is a confusion

Do use restart in the begining

DO NOT

Question x:

Do use restart in the begining

Question x:

Page 14: Maple Software Tutorial for Modelling

> >

(4.4)(4.4)

> >

> >

> >

(3.1)(3.1)

> >

> >

> >

> >

(4.1)(4.1)

> >

> >

(3.2)(3.2)

(4.2)(4.2)

(4.3)(4.3)

Reason: The restart clear the memory of the Maple, it looks like you use a white paper in the begining of the calculation

Do NOT use super & sub-script unless you are sure

DONOT

Use it in this way

Reason: a small blank in the super and sub-script is hard to find

Do NOT use graphical input unless you are sure

DO NOT

73

Use

73

Page 15: Maple Software Tutorial for Modelling

> > (5.2)(5.2)

> >

> >

> >

> >

(5.2.1)(5.2.1)

(5.1.1)(5.1.1)

> >

> >

> >

(5.1)(5.1)> >

Reason: Graphical input may contain unknown blanks, which will ruin the command

Do use sections to make the content clear

DO NOT

Question 1

explanations.....

explanations.....

Question 2

explanations.....

explanations.....

Use sections as here by click the "Enclose the selctions in a section button"

Question 1

explanations.....

explanations.....

Question 2

explanations.....

explanations.....

Reason: Here it is much clear

Page 16: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 12

mg

F

θ

s

Case Study 1: Analytical Solution of an ODE

Question: Given an object with mass m (1kg) on a slope with angle (30). What is the speed of the object after travelling a distance s (1.5m)? Suppose the friction coefficient f is 0.2 and the initial speed is 0.

Page 17: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 13

Many differential equations cannot be solved analytically, in which case we have to satisfy ourselves with an approximation of the solution. In Maple, a numerical solution of an ODE can be done by the dsolve function. In this section, we solve the same question as in Case Study 1, but now in a numerical way. The initial steps “Identify the problem” and “Modeling” are identical, so we move to the next step:

mg

F

θ

s

Case Study 2: Numerical Solution of an ODE

Question: Given an object with mass m (1kg) on a slope with angle (30). What is the speed of the object after travelling a distance s (1.5m)? Suppose the friction coefficient f is 0.2 and the initial speed is 0.

Same as previous question

Case Study 2: Numerical Solution of an ODE

Page 18: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 16

Read & Write Data

In many cases, it is needed to exchange data between Maple and other software. In this section, we demonstrate (a) how to export Maple data to a text file and analyze it via Excel; and (b) how to load external data to Maple. (Case study 2)

in Excel, read the text file and use Space as delimiter, the series of data are plotted as:

Load external text file to maple is quite similar, an example can be found in the following.

Attention:For some computers, a file name is “D:\data.txt”. In many other cases,

please use “D:\\data.txt”, where and extra “\” is needed.

Page 19: Maple Software Tutorial for Modelling

MapleDoc, IO, TU Delft

Page 17

Procedure

A procedure is a set of actions to be performed on a set of variables. Just like “brush your teeth” is a procedure, implying a sequence of actions. According to Maple Help, a procedure definition is a valid expression that can be assigned to a name. That name may then be used to refer to the procedure in order to invoke it in a function call.)

The parenthesized parameter sequence (which may be empty), specifies the names and optionally the types and default values of the procedure's parameters. In its simplest form, the parameter sequence is just a comma-separated list of symbols (‘arguments’) which may be referred to within the procedure.

More complex parameter declarations are possible in the parameter sequence, including the ability to declare the type that each argument must have, default values for each parameter, evaluation rules for arguments, dependencies between parameters, and a limit on the number of arguments that may be passed.

Also good to know: variables which are only defined within a procedure are called local variables. The arguments are considered input: the output is seen as returned value (“return”).

Not too difficult. The power of a proc however is shown in automating a tedious, repetitive task:

This may be off topic, but do you know the elegant solution without Maple or even paper?

Page 20: Maple Software Tutorial for Modelling

> >

> >

(3.1)(3.1)

> >

> >

MapleDoc: Case Study 3: Using procedure - Same question as Case Study 1

Define the proc

Test the proc

Feed proc with its respective input values: m = 1.5, theta = 30 degrees, f =0.2

0.9678542184

Page 21: Maple Software Tutorial for Modelling

> >

> >

> >

> >

> >

> >

> >

MapleDoc: Case Study 4 - 1-Dimensional Senstivity analysis

Define the proc

Relation between angle and travel timem = 1.5, f =0.2, Angle ranges from 25 to 90 degrees

Page 22: Maple Software Tutorial for Modelling

> >

> >

> >

> >

Define the proc for a 3D plot (2 variables)

Relation between angle and travel time - 3D Plot

m = 1.5, f =0.2, Angle Range of angle 1 to 60