MATLAB(R) by Example -  Munther Gdeisat,  Francis Lilley

MATLAB(R) by Example (eBook)

Programming Basics
eBook Download: PDF | EPUB
2012 | 1. Auflage
366 Seiten
Elsevier Science (Verlag)
978-0-12-405853-8 (ISBN)
Systemvoraussetzungen
Systemvoraussetzungen
60,95 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

MATLAB By Example guides the reader through each step of writing MATLAB programs. The book assumes no previous programming experience on the part of the reader, and uses multiple examples in clear language to introduce concepts and practical tools. Straightforward and detailed instructions allow beginners to learn and develop their MATLAB skills quickly.

The book consists of ten chapters, discussing in detail the integrated development environment (IDE), scalars, vectors, arrays, adopting structured programming style using functions and recursive functions, control flow, debugging, profiling, and structures. A chapter also describes Symbolic Math Toolbox, teaching readers how to solve algebraic equations, differentiation, integration, differential equations, and Laplace and Fourier transforms. Containing hundreds of examples illustrated using screen shots, hundreds of exercises, and three projects, this book can be used to complement coursework or as a self-study book, and can be used as a textbook in universities, colleges and high schools.


  • No programming experience necessary to learn MATLAB
  • Examples with screenshots and plentiful exercises throughout help make MATLAB easy to understand
  • Projects enable readers to write long MATLAB programs, and take the first step toward being a professional MATLAB programmer

MATLAB By Example guides the reader through each step of writing MATLAB programs. The book assumes no previous programming experience on the part of the reader, and uses multiple examples in clear language to introduce concepts and practical tools. Straightforward and detailed instructions allow beginners to learn and develop their MATLAB skills quickly. The book consists of ten chapters, discussing in detail the integrated development environment (IDE), scalars, vectors, arrays, adopting structured programming style using functions and recursive functions, control flow, debugging, profiling, and structures. A chapter also describes Symbolic Math Toolbox, teaching readers how to solve algebraic equations, differentiation, integration, differential equations, and Laplace and Fourier transforms. Containing hundreds of examples illustrated using screen shots, hundreds of exercises, and three projects, this book can be used to complement coursework or as a self-study book, and can be used as a textbook in universities, colleges and high schools. No programming experience necessary to learn MATLAB Examples with screenshots and plentiful exercises throughout help make MATLAB easy to understand Projects enable readers to write long MATLAB programs, and take the first step toward being a professional MATLAB programmer

2

Scalars in Matlab

Chapter Outline

Lesson 2.1 Creating and Naming Matlab Scalar Variables 

Lesson 2.2 Approximation of Numbers and Discrete Mathematical Operations 

Lesson 2.3 Mathematical Expressions for Scalar Variables

Lesson 2.4 Relational and Logical Operations for Scalar Variables

Lesson 2.5 Complex Scalar Variables

Answers to Selected Exercises

Lesson 2.1 Creating and Naming Matlab Scalar Variables


Objectives

• To learn how to create scalar variables using Matlab.

• To differentiate between Matlab special variables and user-defined variables.

Topics

2.1.1 Matlab Special Variables

2.1.1.1 Using Matlab Special Variables

2.1.1.2 Changing the Values of Matlab Special Variables

2.1.2 User-Defined Variables

2.1.2.1 Naming a User-Defined Variable

2.1.2.2 Matlab is Case Sensitive

2.1.2.3 Clearing a User-Defined Variable

2.1.1 Matlab Special Variables


2.1.1.1 Using Matlab Special Variables

In Matlab, every variable created should have a value. Variables are created either by Matlab or by the user. Variables created by Matlab are considered to be special variables, whose values are assigned by Matlab. For example, the special variable pi (π), whose value is approximated here to 3.1416. To find the value of the special variable pi, type at the Command Prompt

Then press Enter. Matlab responds with

This command generates another special variable ans and assigns the value 3.1416 to it. The special variable ans saves the result of any Matlab operation if the value of the result is not specifically assigned to a variable. For example, type at the Command Prompt

Then press Enter. Matlab responds with

Other examples of special variables are i and j. The value for both variables is defined as Normally, mathematicians use the term i to represent whereas engineers use the term j to represent the same thing.

To find the value of the special variable i, type at the Command Prompt

Then press Enter. Matlab responds with

To get some help about the variable i, type at the Command Prompt

Then press Enter. Matlab responds and gives you some information about the special variable i as follows.

To find the value of the special variable j, type at the Command Prompt

Then press Enter. Matlab responds with

2.1.1.2 Changing the Values of Matlab Special Variables

The user can change the value of the special variables. For example, type at the Command Prompt

Then press Enter. Matlab responds with

Now the value for the special variable pi has been changed to 1.

To restore the value of the special variable pi, type at the Command Prompt

Then press Enter.

To display the value of the variable pi, type at the Command Prompt

Then press Enter. Matlab responds with

2.1.2 User-Defined Variables


2.1.2.1 Naming a User-Defined Variable

The user can also create Matlab variables and assign values to the created variables. The variable name should satisfy the following requirements:

• A variable name must not contain spaces or hyphens (-).

• A variable name can contain up to 63 characters.

• A variable name must start with a letter (a–z or A–Z), followed by any number of letters, digits (0–9), or underscores ( _ ).

• Punctuation characters such commas ( , ) or apostrophes ( ) are not allowed, because many of them have special meanings in Matlab.

• A variable name must not be a Script M-file name or an existing Matlab function name.

• The use of a Matlab reserved word as a variable name is not allowed. A list of Matlab reserved words is given below.

• The use of a Matlab keyword as a variable name is not allowed. A list of Matlab keywords is given below.

The following variable names are acceptable

The following names are not suitable to be used as variable names:

3x: This variable name starts with a number, not an alphabetical character.

_y: This variable name starts with an underscore.

r$: This variable name contains the dollar sign.

sum: This variable name is a Matlab function. To check this, type at the Command Prompt

Matlab responds by displaying some information about the sum function.

2.1.2.2 Matlab is Case Sensitive

Matlab is a case-sensitive programming language as it distinguishes lowercase from uppercase. The variable name x is considered to be different from the variable name X, which can lead to confusion, so be careful! For example, type at the Command Prompt

Then Press Enter. Matlab responds by creating the variable x and assigning the value “1” to it.

To display the content of the x variable, type at the Command Prompt

Then Press Enter. Matlab responds by displaying the value of the variable x as

To find the value of X, type at the Command Prompt

Then Press Enter. Matlab gives the results

In Matlab, the variable x is different from the variable X. Matlab is case sensitive. For example, cost, Cost and COST are viewed as being three different variables in Matlab.

2.1.2.3 Clearing a User-Defined Variable

Create a variable y

To display the content of y, type at the Command Prompt

Then Press Enter. Matlab responds by displaying the value of y as

To clear the variable y, type at the Command Prompt

Then Press Enter. To be sure that the variable y is cleared, type at the Command Prompt

Then Press Enter. Matlab responds with

Exercise 11

Explain why the following Matlab code is incorrect.

Lesson 2.2 Approximation of Numbers and Discrete Mathematical Operations


Objectives

• To learn how to approximate numbers in Matlab.

• To learn a few of Matlab’s discrete mathematical operations.

Topics

2.2.1 Approximating Numbers

2.2.1.1 round Function

2.2.1.2 fix Function

2.2.1.3 ceil Function

2.2.1.4 floor Function

2.2.2 Discrete Mathematical Operations

2.2.2.1 Factorizing a Number

2.2.2.2 Greatest Common Divisor

2.2.2.3 Least Common Multiple

2.2.1 Approximating Numbers


A real number consists of integer and decimal parts, and it can be approximated by an integer number. For example, the real number 2.5 can be approximated by the integer number 2. This approximation process requires the elimination of the decimal part of the number, and it may also affect the integer part. Matlab supports four functions to approximate real numbers: round, fix, ceil, and floor.

2.2.1.1 round Function

This function rounds a real number upward, or downward, toward the nearest integer. The operation of this function is best explained by way of examples. Type at the Command Prompt

Then press Enter. Matlab responds with

A second example, type at the Command Prompt

Then press Enter. Matlab responds with

2.2.1.2 fix Function

This function truncates (eliminates) the decimal part of a real number, leaving the integer part unchanged. The operation of this function is best explained by way of examples. Type at the Command Prompt

Then press Enter. Matlab responds with

A second example, type at the Command Prompt

Then press Enter. Matlab responds with

2.2.1.3...

Erscheint lt. Verlag 31.12.2012
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
Mathematik / Informatik Mathematik Computerprogramme / Computeralgebra
Technik
ISBN-10 0-12-405853-1 / 0124058531
ISBN-13 978-0-12-405853-8 / 9780124058538
Haben Sie eine Frage zum Produkt?
PDFPDF (Adobe DRM)
Größe: 17,8 MB

Kopierschutz: Adobe-DRM
Adobe-DRM ist ein Kopierschutz, der das eBook vor Mißbrauch schützen soll. Dabei wird das eBook bereits beim Download auf Ihre persönliche Adobe-ID autorisiert. Lesen können Sie das eBook dann nur auf den Geräten, welche ebenfalls auf Ihre Adobe-ID registriert sind.
Details zum Adobe-DRM

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen eine Adobe-ID und die Software Adobe Digital Editions (kostenlos). Von der Benutzung der OverDrive Media Console raten wir Ihnen ab. Erfahrungsgemäß treten hier gehäuft Probleme mit dem Adobe DRM auf.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen eine Adobe-ID sowie eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

EPUBEPUB (Adobe DRM)
Größe: 5,6 MB

Kopierschutz: Adobe-DRM
Adobe-DRM ist ein Kopierschutz, der das eBook vor Mißbrauch schützen soll. Dabei wird das eBook bereits beim Download auf Ihre persönliche Adobe-ID autorisiert. Lesen können Sie das eBook dann nur auf den Geräten, welche ebenfalls auf Ihre Adobe-ID registriert sind.
Details zum Adobe-DRM

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen eine Adobe-ID und die Software Adobe Digital Editions (kostenlos). Von der Benutzung der OverDrive Media Console raten wir Ihnen ab. Erfahrungsgemäß treten hier gehäuft Probleme mit dem Adobe DRM auf.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen eine Adobe-ID sowie eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Das umfassende Handbuch

von Johannes Ernesti; Peter Kaiser

eBook Download (2023)
Rheinwerk Computing (Verlag)
44,90
Das Handbuch für Webentwickler

von Philip Ackermann

eBook Download (2023)
Rheinwerk Computing (Verlag)
49,90