有人可以检查我的代码吗? [英] Can someone check my code please?

查看:50
本文介绍了有人可以检查我的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是这些论坛的新手,实际上是C ++的新手。我正在研究一个项目,如果我能够比那些对C ++有更好理解的人检查我的代码,我将非常感激。


我想要的是什么要做的代码就是要求一个数字,在2到9之间,然后根据给定的数字显示一个矩阵并显示其行列式。我不知道如何编程找到决定因素,所以我通过简单地在别处找到决定因素来解决这个问题。我打算上一个9x9矩阵,虽然我仍然坚持找到6x6矩阵向上的行列式。


这是我的代码:

Hello everyone, i am new to these forums and in fact new to C++. I am working on a project, and i would be most grateful if i could have my code checked by people who have a better understanding of C++ than i curently do.

What i intend this code to do is ask for a number off you, between 2 and 9, it then displays a matrix according to the number given and displays its determinant. I do not know how to program finding the determinant though, so i have got round this by simply finding the determinant elsewhere. I intend to go up a 9x9 matrix, although i am stuck on finding the determinant for 6x6 matrices upwards.

Here is my code:

展开 | 选择 | Wrap | >行号

推荐答案

对于任何非奇异方阵A,它可以分解为L * U == P * A
其中L是一个下三角矩阵,其对角线上的所有一个,U是一个上部

三角矩阵,P是一个行置换矩阵。


因为det(L * U)== det(P * A)和det(P)是+ - 1;如果已经执行了一个奇数的行数交换,则为负数,否则为正数。

三角矩阵的行列式是对角线上元素的乘积。 det(L)== 1

(对角线上只有一个,所以det(A)== det(U)* s,其中s == + -1。


分解被称为低层分解具有部分旋转''。

如果分解失败(部分对角线上全部为零),则b / b矩阵A的行列式为零。
< br $>
亲切的问候,


Jos
For any non-singular square matrix A it can be decomposed as L*U == P * A
where L is a lower triangular matrix with all ones on its diagonal, U is an upper
triangular matrix and P is a row permutation matrix.

Since det(L*U) == det(P * A) and det(P) is +- 1; it is negative if an odd number
of row swaps have been performed, positive otherwise. The determinant of a
triangular matrix is the product of its elements on the diagonal. det(L) == 1
(there are only ones on its diagonal, so det(A) == det(U)*s where s == +-1.

The decomposition is called a ''lower-upper decomposition with partial pivoting''.
If the decomposition fails (all zeros on the partial diagonal), the determinant of
matrix A is zero.

kind regards,

Jos



对于任何非奇异方阵A它可以被分解为L * U == P * A

其中L是一个下三角矩阵,其对角线上的所有一个,U是一个上层

三角矩阵和P是一个行置换矩阵。
For any non-singular square matrix A it can be decomposed as L*U == P * A
where L is a lower triangular matrix with all ones on its diagonal, U is an upper
triangular matrix and P is a row permutation matrix.



这仍然会让你首先找到LU分解的问题。我不知道这将是多么容易。我只会使用辅助因子扩展(也就是扩展未成年人)将大矩阵的行列式减少为一系列决定因素,连续较小的矩阵(未成年人)乘以其辅助因子。最终,你最终会得到2x2矩阵行列式的总和。

This still leaves you with the problem of finding the LU decomposition in the first place. I don''t know how easy that would be. I would just use a cofactor expansion (a.k.a. expansion by minors) to reduce the determinant of the large matrix into a sum of determinants successively smaller matrices (minors) multiplied by their cofactor. Eventually, you end up with a sum of 2x2 matrix determinants.



这仍然会让你在找到LU分解的问题第一名。我不知道会有多容易。
This still leaves you with the problem of finding the LU decomposition in the first place. I don''t know how easy that would be.



这非常简单:只需高斯消除下三角矩阵即可。
足够。交换两行只会改变行列式的符号。


亲切的问候,


Jos

It''s extremely easy: just Gaussian elimination of the lower triangular matrix is
enough. Swapping two rows only changes the sign of the determinant.

kind regards,

Jos


这篇关于有人可以检查我的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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