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

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

1

1

Introducing matlab

matlab is short for Matrix Laboratory, and was designed in the ﬁrst instance for the purposes of numerical linear algebra. Since its conception it has developed many advanced features for the manipulation of vectors and matrices. It can solve large systems of equations eﬃciently and is therefore useful for solving diﬀerential equations and optimization problems. It also provides excellent means for data visualization and has symbolic capabilities. Whilst simple problems can be solved interactively with matlab, its real power shows when given calculations that are cumbersome or extremely repetitive to do by hand.

1.1

Calling Matlab

The easiest way to start Matlab is by clicking the Start menu and then selecting Programs core followed by scientific software, Matlab and ﬁnally Matlab R12, i.e. the sequence Start--Programs core--Scientific software--Matlab--Matlab R12}, After a short initiation sequence Matlab will appear. Using the default settings Matlab appears with 3 active sub-windows, other tools can be started from the view menu. You can have up to six active windows with the following features Command Window Command History Current Directory Workspace This is where you type commands in at the >> prompt. gives a list of recent commands. allows you to access ﬁles in a diﬀerent directory Allows you to access all information about the the variables you have deﬁned. NB: you can view them by double-clicking the yellow symbols to activate the array editor. allows you to launch demos and the help utility Allows you to navigate the online help facility

Launch Pad Help

To save space you can overlap windows by dragging the titlebar of one window over to the title bar of another, and tabs allow you switch between the windows.

1.2

+ * / ^

matlab as a calculator

addition subtraction multiplication division exponentiation (to the power of)

The basic mathematical operators are deﬁned as follows:

Although employing matlab as a calculator is under-using its computational capabilities, it can serve as an introduction to the wide range of functions available. For example, matlab stores the value of π directly:

MT1242: Introduction to Matlab >> pi ans = 3.1416

2

This might not have been the answer, that you were expecting. However, matlab has two formats for displaying the value of a variable, short and long. The default is short, but you can toggle between them, using the format command: >> format long >> pi ans = 3.14159265358979 >> format short matlab always stores variables in long form. Unlike π, matlab doesn’t store the value of e in the same way. Instead, it has a function exp to compute exponentials and you can assign variables as follows: >> e=exp(1) e = 2.7183 It is possible to suppress the output of a function from the command bar. For example, if wished to assign the value π to a variable a, we would use a semi-colon after the instruction in order to suppress the output: >> a=pi; matlab also has the standard range of trigonometric functions, such as sin, cos, tan >> cos(a) ans = -1 The command lookfor instructs matlab to scan through its standard functions, looking for references to the word speciﬁed. For example, >> lookfor sine ACOS Inverse cosine. ACOSH Inverse hyperbolic cosine. ASIN Inverse sine. ASINH Inverse hyperbolic sine. COS Cosine. COSH Hyperbolic cosine. SIN Sine. SINH Hyperbolic sine. TFFUNC time and frequency domain versions of a cosine modulated Gaussian pulse. Sometimes, computer arithmetic does not always produce the right answer, for example ∞. We know that tan π = ∞, however will matlab get the right answer? 2 >> tan(pi/2) ans = 1.6331e+16

MT1242: Introduction to Matlab

3

Unfortunately not! This is due to the ﬂoating point capabilities of the machine being used. matlab is however aware of the existence of the value ∞, for example >> 1/0 Warning: Divide by zero. ans = Inf matlab is also familiar with logarithms! You may recall that the logarithm of a number x, with base n, is deﬁned to be the value a such that na = x. There are many types of logarithm available in matlab, for example base 2, natural and base 10: >> log2(e) ans = 1.4427 >> log(e) ans = 1 >> log10(e) ans = 0.4343 matlab also has a range of commands for evaluating complex numbers. matlab uses i to represent √ −1. For example: >> c=a+i*e c = 3.1416 + 2.7183i >> abs(c) ans = 4.1544 >> angle(c) ans = 0.7133 matlab often provides additional information about in-built functions. You can access this by using the help command. For example >> help abs ABS Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex modulus (magnitude) of the elements of X. See also SIGN, ANGLE, UNWRAP. You are often pointed towards other in-built functions that are similar to the function of interest. There is also an on-line version of the help facility, called helpdesk. To access this simply type

MT1242: Introduction to Matlab

4

helpdesk in the command bar. helpdesk contains all the information that can be bought up via help in addition to useful features such as hyper-links to related commands and helpful illustrations of how various commands can be used. helpdesk can prove a powerful ally when using matlab and you should familiarise yourself with it! When you have been using matlab for a while, it can often become quite tricky to remember all the diﬀerent variables that you have introduced. Fortunately matlab can remind you of them: >> who Your variables are: a ans c al b

e

Note that pi and i are not listed, as they are built in to matlab. The command whos, gives a more descriptive version of the above, including the size of each variable.

1.3

Visualization using matlab

One of the many nice features of matlab, is it’s ability to produce information graphically. 1.3.1 Argand diagrams

Consider a complex number a + bi, where a and b are both real numbers. This can be represented by the vector (a, b) on an Argand diagram, which represents the real numbers on the x-axis and imaginary numbers on the y-axis. A visual representation of a + bi can be made by drawing a line between the origin (0, 0) and the point (a, b). We may use matlab to produce such a diagram, using the plot command. Recall that we created a complex number c in the previous section. matlab can think of the number c as simply a point in two dimensional space and in order to tell it to join this point to the origin, we use the following command: >> plot([0,c]) This produces the following graph:

3

2.5

2

1.5

1

0.5

0

0

0.5

1

1.5

2

2.5

3

3.5

In order to produce the graph we had to vectorize the two points. We did this by creating an array using the square brackets [ ]. We will learn more about arrays and in particular vectors and matrices soon.

MT1242: Introduction to Matlab

5

After a time you may wish to remove some or all the variables that you have stored in the computer’s memorybank. The command clear is used for this purpose: >> clear e clears the individual variable e (watch it disappear from the workspace window), whereas >> clear removes all variables from the memorybank.

1.4

matlab as an equation solver

matlab is particularly good at solving systems of equations. There are a number of ways in which we can ask matlab to do this. 1.4.1 The quadratic formula

All of you should be familiar with the formula for ﬁnding the roots of a quadratic equation. We shall ﬁrst brieﬂy discuss this formula, before seeing how matlab handles such equations. A quadratic equation is one of the form ax2 + bx + c = 0 and often a question of interest is given values of a, b and c what are the values of x which satisfy this equation? These values are often called roots and there are the same number of roots as the highest power of the equation. Consequently for a quadratic equation, we seek two roots. By re-arranging the equation in the correct manner we discover that the roots of the problem are given by the formula √ −b ± b2 − 4ac x= . 2a It is important to note that even if all the coeﬃcients (i.e. a, b and c) are real, the roots of the equation may not be! matlab has symbolic capabilities which can manipulate equations such as those above. We shall brieﬂy discuss how: We must ﬁrst inform matlab that we wish to make use of its symbolic capabilities. It is essential to inform matlab of the variables that we want it to consider as symbols – the command syms exists for this purpose. Note that it is not a standard feature of matlab and therefore not all versions have symbolic capabilities. >> syms a b c x >> whos Name Size a b c x 1x1 1x1 1x1 1x1

Bytes 126 126 126 126

Class sym sym sym sym object object object object

Grand total is 8 elements using 504 bytes

MT1242: Introduction to Matlab >> y = solve(a*x^2 + b*x + c) y = [ 1/2/a*(-b+(b^2-4*a*c)^(1/2))] [ 1/2/a*(-b-(b^2-4*a*c)^(1/2))] >> pretty(y) [ [ [1/2 [ [ [ [ [1/2 [ 2 1/2] -b + (b - 4 a c) ] --------------------] a ] ] 2 1/2] -b - (b - 4 a c) ] --------------------] a ]

6

matlab has some basic “artiﬁcial intelligence” built in. An example of this is the fact that unless we specify otherwise, it solves the equation with respect to the symbolic variable x, or alternatively the symbolic variable with the letter which lies closest alphabetically to x. We may however, speciﬁcally instruct matlab to solve the equation with respect to a diﬀerent symbolic variable, for example b: >> y = solve(a*x^2 + b*x + c, b) y = -(a*x^2+c)/x You can evaluate symbolic expressions when the parameters take speciﬁc numerical values using the subs command: >> subs([y],{a,b,c},{1,1,1}) ans = -(x^2 + 1)/x You can also get Matlab to symbolically solve integrals and evaluate answers >> syms I x >> I=int(1/(1+cos(x)),0,pi/8) I = cot(7/16*pi) >> eval(I) ans = 0.1989 When you’ve decided enough is enough use either quit or exit: >> exit Remember the best way to learn matlab is by trying it yourself, so make sure you make use of the support classes and other facilities available to you!

- Tutorial Etabsv8 Exelente 62pag
- Títulos HIJK
- Título G crk
- Título F crk
- Título E (casas) crk
- Título D crk
- Titulo C Crk
- Título B crk
- Título A crk
- Prefacio Crk
- Ley 400-97crk
- Curso Matlab
- Matlab 7
- Guide
- cap02-v2
- Sl Using Simulink
- xpctarget_basictutorial
- Rna
- 016 Tutor Lab View
- transparencias-leccion20
- Tutorial Resumen Matlab
- Taller 2
- Matlab Tutorial
- Matlab Tut
- transparencias-leccion23

Introducing matlab: Tutorial sobre funciones básicas en ingles:\
Muy básico pero sirve para comenzarse en este lenguaje de programación.\
Idioma: Ingles Paginas:6 Valoración: Bueno Formato: pdf...

Introducing matlab: Tutorial sobre funciones básicas en ingles:\

Muy básico pero sirve para comenzarse en este lenguaje de programación.\

Idioma: Ingles Paginas:6 Valoración: Bueno Formato: pdf (Adobe Acrobat)

Muy básico pero sirve para comenzarse en este lenguaje de programación.\

Idioma: Ingles Paginas:6 Valoración: Bueno Formato: pdf (Adobe Acrobat)

- manualv2
- Book
- Matlab Workshop Lecture
- EXPERIMENT Basic Matlab
- DataProcessing_MATLAB_Lecture1
- Exercise 1 2013
- Curs 0 Introducere in Matlab
- Par Ti
- Legendre Functions
- Chapter3rev1.ppt
- Revisiting Lambert’s Problem - Dario Izzo
- Matlab Tutorial 3
- S Function
- math model qs by NRB
- Ellipsoidal, Cylindrical, Bipolar and Toroidal Wormholes in 5D Gravity
- f5 Sbp Addmaths p1 Mid Year
- ALL MAths Formulas From Maths.org
- Teknik Menjawab Matematik Tambahan 1
- Additional Math OCR 04 JUN With Ms
- 9709_s04_qp_3
- kepler
- MHT CET 2016 version 11
- Lab Experiment 02
- Novus 4510 Mathematician
- Cheat
- The Geometry of Special Relativity (Tevian Dray)_slides
- Complex Functions and Application
- CH07 - Inverse Functions
- Method of Variation of Parameters
- Differentiability on R 2

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 reading from where you left off, or restart the preview.

scribd