MATLAB基本語法

MATLAB 環境下的行為就像一個超級複雜的計算器。您可以使用 >> 命令提示符下輸入命令。

MATLAB 是一種解釋型的環境。換句話說，你給一個命令 MATLAB 就馬上執行。

實踐

`5 + 5`

```ans = 10
```

`3 ^ 2	       % 3 raised to the power of 2`

```ans = 9
```

```sin(pi /2)	  % sine of angle 90o
```

```ans = 1
```

`7/0		      % Divide by zero`

```ans = Inf
warning: division by zero
```

`732 * 20.3	`

```ans =  1.4860e+04
```

MATLAB提供了一些特殊的一些數學符號的表達，像圓周率π, Inf for ∞, i (and j) for √-1 etc. Nan 代表“不是一個數字”。

使用分號（;)

```x = 3;
y = x + 5```

```y =  8
```

添加注釋

`x = 9	     % assign the value 9 to x`

MATLAB編輯器包括工具和上下文菜單項，來幫助添加，刪除或更改注釋的格式。

常用的運算符和特殊字符

MATLAB支持以下常用的運算符和特殊字符：

- Minus; subtraction operator.
* Scalar and matrix multiplication operator.
.* Array multiplication operator.
^ Scalar and matrix exponentiation operator.
.^ Array exponentiation operator.
Left-division operator.
/ Right-division operator.
. Array left-division operator.
./ Array right-division operator.
: Colon; generates regularly spaced elements and represents an entire row or column.
( ) Parentheses; encloses function arguments and array indices; overrides precedence.
[ ] Brackets; enclosures array elements.
. Decimal yiibai.
Ellipsis; line-continuation operator
, Comma; separates statements and elements in a row
; Semicolon; separates columns and suppresses display.
% Percent sign; designates a comment and specifies formatting.
_ Quote sign and transpose operator.
._ Nonconjugated transpose operator.
= Assignment operator.

特殊變量和常量

MATLAB支持以下特殊變量和常量：

Name Meaning
eps Accuracy of floating-yiibai precision.
i,j The imaginary unit √-1.
Inf Infinity.
NaN Undefined numerical result (not a number).
pi The number π

MATLAB是區分大小寫的。

保存你的工作

`save myfile`

`load myfile`