Как задать матрицу в wolfram mathematica

Корпорация "Центр"

Иллюстрированный самоучитель по Mathematica 5

В системе Mathematica матрицы представляются в виде списков строк, т.е. в виде списков списков. Вот пример задания матрицы. Матрица задается как список списков.

Конечно, привычнее ее видеть как матрицу.

Действия с матрицами и векторами задаются естественным образом. Умножим, например, матрицу на вектор.

А вот как можно умножить матрицу m1 на скаляр t.

Для квадратной матрицы Mathematica позволяет найти определитель, а также обратную матрицу (если, конечно, матрица обратима, т.е. имеет ненулевой определитель), собственные значения и векторы.

Поскольку он ненулевой, можем найти обратную матрицу.

Произведение матрицы на ее обратную должно быть единичной матрицей. Давайте проверим.

How to | Create a Matrix

Matrices are represented in the Wolfram Language with lists. They can be entered directly with the < >notation, constructed from a formula, or imported from a data file. The Wolfram Language also has commands for creating diagonal matrices, constant matrices, and other special matrix types.

A matrix can be entered directly with < >notation:

You can show the result in matrix notation with MatrixForm :

expr//fun is another way of entering fun [ expr ] . It can be convenient to use it when fun is a formatting function.

This uses Table to create a grid of values in and :

Note that matrices in the Wolfram Language are not restricted to contain numbers; they can contain symbolic entries such as formulas:

When you create a matrix and save it with an assignment, take care not to combine this with formatting using MatrixForm . Use parentheses:

You can use mat in further calculations:

Suppose you do not use parentheses:

Then mat will print like a matrix but will not work in calculations like a matrix. For example, the following does not carry out matrix multiplication:

You can check the value of mat by using FullForm :

This shows that mat also includes the formatting wrapper MatrixForm , which stops it from working as a matrix.

There are functions to create a variety of special types of matrices.

This creates a 4 &#215; 5 matrix of real values that fall between and :

This creates a matrix that only has nonzero entries on the diagonal:

This creates a matrix whose entries are all the same:

Корпорация "Центр"

This creates a 4 &#215; 4 Hilbert matrix; each entry is of the form :

Many linear algebra and other functions return matrices.

Here, the QR decomposition of a random 3 &#215; 3 matrix is calculated:

This prints the Q matrix:

When Wolfram Language functions return matrices they often use an optimized storage format called packed arrays.

You can apply many common operations in the Wolfram Language to a list, and get back another list with the function mapped onto each element. This also works for matrices, which are lists of lists.

Here is a 2 &#215; 2 matrix of squares:

This applies Sqrt to each element of the matrix:

This behavior of Sqrt is called listability, and it makes very readable and efficient code.

If a function that is not listable is used, it does not map onto each element:

You can make the function listable; now it will map onto each element:

Another important way to create a matrix is to import a data file. This can be done with tabular formats such as Table (.dat), CSV (.csv), and TSV (.tsv). A matrix can also be read from an Excel spreadsheet (.xls).

Here, ImportString is used to import a CSV formatted string into a matrix. Importing from a file is done with Import :

The Wolfram Language also supports a number of other formats including scientific and medical data formats such as HarwellBoeing, MAT, HDF, NASACDF, and FITS.

The way that you create a matrix can have an important impact on the efficiency of your programs. For the best efficiency, avoid appending to a matrix, avoid unnecessary creation operations, and use listable operations when you can.

This example repeatedly adds a new row to a matrix:

It is much faster to create the matrix in one computation. Whenever you see a For loop, try to replace it with some other construct, like Table :

The following example creates a matrix of zeros and then fills it in with a loop. The creation of a zero matrix here is completely unnecessary:

It is much faster to create data for each row of the matrix once, and then use a listable operation:

If your matrices are large and have many elements that are the same (for example, zero), then you should consider working with sparse matrices formed with SparseArray .

Научный форум dxdy

Проблема следующая.
В Mathematica 6.0 пытаюсь перемножить матрицы (для примера):
$A= \left ( \begin<array> <cc>1 & 2\\ 3 & 5\\ \end <array>\right)$

и
$B= \left ( \begin<array> <cc>2&2\\ 1&4\\ \end <array>\right)$

т.е. выдает он мне матрицу
$C= \left ( \begin<array> <cc>2&4\\ 3&20\\ \end <array>\right)$

А у меня, если посчитать на бумаге, получается совсем другой результат. Что я делаю не так?

Корпорация "Центр"

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *