# 【译】Jep文档(4)——数据类型(Data Type)

## 数据类型

### 向量（Vectors）

a = [2, 3, 10]      // create a variable with a vector value
a[1]                // evaluates as 2
a[3]                // evaluates as 10

a + [1, 2, 3]       // addition, evaluates as [3, 5, 13]
a - [1, 2, 3]       // subtraction, evaluates as [1, 1, 7]
[3, 4, 5]*2         // multiplication by a scalar,
// evaluates as [6, 8, 10]
[1,2] * [1,2]       // interpreted as a column vector times a row
// vector. Evaluates as [[1.0, 2.0], [2.0, 4.0]]
[4, 6, 8]/2         // division by a scalar, evaluates as [2, 3, 4]
[1,2,3].[1,2,3]     // dot product, evaluates as 14
[1,2,3]^^[1,2,3]    // cross product, evaluates as [0, 0, 0]
min([6,4,7,8])      // minimum value, 4
max([6,4,7,8])      // minimum value, 8
avg([6,4,7,8])      // average value, 2.5
vsum([6,4,7,8])     // sum of elements, 25


// Add the variable y with value [1.2,3.4]
// Use the y[2] syntax to get a specific element
Object res = jep.evaluate(jep.parse("y[2]"));
assertEquals(3.4,res);
// calculate the vector expression y*2
Object res2 = jep.evaluate(jep.parse("y*2"));
// The returned type will be Vector<Object>
assertTrue(res2 instanceof Vector<?>);
Vector<Object> vec = (Vector<Object>) res2;
// Convert to an array
Object[] array = vec.toArray();
assertArrayEquals(new Object[]{2.4,6.8},array);


### 复数

Jep在大多数操作和函数中支持复数。虚部 i 是标准变量表中的一部分，在使用StandardComponents时，被加入到解释器中。还包括了一组复函数，re(c)，im(c)，cmond(c)，conj(c)，complex(x, y)和polar(r, hteta)。查看Functions了解更多。需要导入com.singularsys.jep.standard.Complex类才能过操作表达式中的复数值。

(1+2*i)^3
e^(-i)
re((1+2*i)^2 - (3+3*i)^2)


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120