如何使用ILMath.invert功能? [英] How to use ILMath.invert function?

查看:235
本文介绍了如何使用ILMath.invert功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ILNumerics,我要反转矩阵A的结果是矩阵B.这是我的code:

In ILNumerics, I want to inverting a matrix A. The result is matrix B. Here is my code:

        ILArray<double> data = ILSpecialData.sinc(50, 50);
        ILArray<double> data2 = ILMath.zeros(50, 50);
        ILMath.invert(data, data2);

方法是:

ILMath.invert Method (ILInArray<Double>, ILOutArray<Double>)

public static void invert(
       ILInArray<double> A,
       ILOutArray<double> outArray
)

但我得到的矩阵B(数据2)零矩阵,而不是矩阵A(数据)的反转。我应该怎么做才能解决这个问题?

but I get the zero matrix in matrix B (data2) instead of an inversion of matrix A (data). What should I do to fix this?

如果不是因为我有利用ILArray代替ILInArray和ILOutArray,如何使用这个矩阵?

If it because I had use ILArray instead of ILInArray and ILOutArray, how to use this matrices?

推荐答案

ILMath.invert 不反转矩阵而是一个数组的元素!看看你是否需要反转矩阵,下面的解决方案。这里是字面回答你的问题。假设,我们有一个矩阵 A

How to use ILMath.invert

ILMath.invert does not invert matrices but the elements of an array! See the solution below if you need to invert a matrix. Here is the literal answer to your question. Suppose, we have a matrix A:

ILArray<double> A = ILMath.counter(2,3); 
> A
>  <Double> [2,3]
> [0]:          1          3          5 
> [1]:          2          4          6 

颠倒函数内部使用,以实现前pressions像 -A ,即反转A的元素:

The invert function is used internally to realize expressions like -A, i.e. the inversion of the elements of A:

> -A     
> <Double> [2,3]
> [0]:         -1         -3         -5 
> [1]:         -2         -4         -6 

如果你想叫它directy(不推荐),你可以去这样的:

If you would want to call it directy (not recommended), you could go like that:

ILArray<double> data = ILSpecialData.sinc(3, 3);
ILArray<double> data2 = 0; // just some initialization
ILMath.invert(data,data2); // invert elements of data, return in data2

> data
> <Double> [3,3]
> [0]: (:,:) 1e-002 * 
> [1]:     5,7765     5,0334     5,0334 
> [2]:     5,0334     6,0334     6,0334 
> [3]:     5,0334     6,0334     6,0334
>
> data2
> <Double> [3,3]
> [0]: (:,:) 1e-002 * 
> [1]:    -5,7765    -5,0334    -5,0334 
> [2]:    -5,0334    -6,0334    -6,0334 
> [3]:    -5,0334    -6,0334    -6,0334 

解决方案:如何反转矩阵

有关

我要反转矩阵A

您需要使用 ILMath.linsolve()来代替。 Linsolve是用来解决线性方程系统。矩阵的逆是解决这样一个等式系统的最昂贵的方法。通常,人们可以美元,如此昂贵的运行时的P $ pvent。 Linsolve这是否适合你。它首先尝试使用更便宜的选择回落至矩阵求逆前求解方程系统。

you need to use ILMath.linsolve() instead. Linsolve is used to solve linear equation systems. The inversion of a matrix is the most expensive way of solving such an equation system. Often one can prevent from such an expensive operation. Linsolve does that for you. It first tries to use cheaper options to solve the equation system before falling back to the matrix inversion.

如果你是肯定的,那是需要完整的反转,只是提供 ILMath.eye()为第2参数 ILMath.linsolve

If you are certain, that the full inversion is needed, just provide ILMath.eye() as 2nd argument to ILMath.linsolve:

ILArray<double> A = ILMath.rand(5,5);
ILArray<double> B = ILMath.linsolve(A, ILMath.eye(5, 5));

为了坡口使得b真的是A的逆,你可以乘 A B 和应得到一个单位矩阵:

In order to proove that B really is the inverse of A, you could multiply A and B and should get an identity matrix:

> ILMath.multiply(A, B)
> <Double> [5,5]
> [0]:          1     0,0000     0,0000     0,0000          0 
> [1]:     0,0000     1,0000     0,0000     0,0000     0,0000 
> [2]:     0,0000     0,0000     1,0000     0,0000     0,0000 
> [3]:     0,0000     0,0000     0,0000          1          0 
> [4]:     0,0000     0,0000     0,0000          0     1,0000 

请注意,某些元素由于舍入误差略有不同为零。误差小,但:

Note, some elements differ slightly from zero due to rounding errors. The error is small though:

> ILMath.norm(C - ILMath.eye(5,5))
> <Double> (:,:) 1e-016 * 
> 5,3541 

这篇关于如何使用ILMath.invert功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆