# 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`