2. Basics

Society for Industrial and Applied Mathematics eBooks · 2005

2.1. Interaction and Script Files MATLAB is an interactive system. You type commands at the prompt (≫) in the Command Window and computations are performed when you press the enter or return key. At its simplest level, MATLAB can be used like a pocket calculator: ≫ (1+sqrt(5))/2 ans = 1.6180 ≫ 2^(−53) ans = 1.1102e-016 The first example computes and the second 2−53. Note that the second result is displayed in exponential notation: it represents 1.1102 × 10−16. The variable ans is created (or overwritten, if it already exists) when an expression is not assigned to a variable. It can be referenced later, just like any other variable. Unlike in most programming languages, variables are not declared prior to use but are created by MATLAB when they are assigned: ≫ x = sin (22) x = −0.0089 Here we have assigned to x the sine of 22 radians. The printing of output can be suppressed by appending a semicolon.

Read the paper · More papers on PaperTik