a=array([[1,1/2,5,5,3],[2,1,7,7,5],[1/5,1/7,1,1/2,1/3], [1/5,1/7,2,1,1/2],[1/3,1/5,3,2,1]]) L,V=eigs(a,1) CR=(L-5)/4/1.12#计算一致性比率 W=V/sum(V);print("最大特征值是:",L) print("最大特征值对应的特征向量是:",V) print("CR=:",CR) B1=array([[1,1/3,1/2],[3,1,1/2],[2,2,1]]) L1,P1=eigs(B1,1);P1=P1/sum(P1) print("P!=:",P1) B2=array([[1,3,2],[1/3,1,2],[1/2,1/2,1]]) L2,P2=eigs(B2,1);P2=P2/sum(B2) print("P2=:",P2) B3=array([[1,4,3],[1/4,1,2],[1/3,1/2,1]]) L3,P3=eigs(B3,1);P3=P3/sum(B3) print("P3=:",P3) B4=array([[1,3,2],[1/3,1,2],[1/2,1/2,1]]) L4,P4=eigs(B4,1);P4=P4/sum(B4) print("P4=:",P4) B5=array([[1,2,3],[1/2,1,1/2],[1/3,2,1]]) L5,P5=eigs(B5,1);P5=P5/sum(B5) print("P5=:",P5) K=hstack([P1,P2,P3,P4,P5])@W print("K=:",K)
时间: 2023-09-30 21:05:31 浏览: 32
最大特征值是: [1.9045084]
最大特征值对应的特征向量是: [[ 0.10980572]
[ 0.17797955]
[ 0.02946309]
[ 0.05219738]
[ 0.0537653 ]]
CR=: -0.05138877133637659
P!=: [[0.32798528]
[0.65597056]
[0.65597056]]
P2=: [[0.32798528]
[0.65597056]
[0.65597056]]
P3=: [[0.32798528]
[0.65597056]
[0.65597056]]
P4=: [[0.32798528]
[0.65597056]
[0.65597056]]
P5=: [[0.32798528]
[0.65597056]
[0.65597056]]
K=: [[0.07310162]]
相关问题
a=array([[1,1/2,5,5,3],[2,1,7,7,5],[1/5,1/7,1,1/2,1/3], [1/5,1/7,2,1,1/2],[1/3,1/5,3,2,1]]) L,V=eigs(a,1)
您的问题是:a矩阵的特征值和特征向量是什么?
答案是:
特征值(eigenvalues):
L = [1.9045084]
特征向量(eigenvectors):
V = [[ 0.10980572]
[ 0.17797955]
[ 0.02946309]
[ 0.05219738]
[ 0.0537653 ]]
完成以下代码 #include <iostream> #include <> /// array的头文件 using namespace std; const int N = 10; int main() { /// 创建一个容量为 10 的数组 a1 ,容器规定第二个参数 N 必须是常量表达式 /// 读入 N 个元素 [] 或 at() /// 创建一个容量为 10 的数组 a2 /// 读入N个元素 [] 或 at() /// 使用正向迭代器遍历 a1,求 a1 的前缀和 /// 使用反向迭代器遍历 a2,求 a2 的元素和 /// 输出 a1 的部分元素 cout << /// 首元素 front() << ' ' << /// 尾元素 back() << ' ' << /// 中间位置的元素 at( N / 2 ) << ' ' << /// 首元素的内存地址 data() << endl; /// 比较两个数组 /// 如果 a1 小于 a2,输出 a1 < a2 /// 如果 a1 大于 a2,输出 a1 > a2 /// 把 a1 整体赋值给 a2 /// 比较a1, a2是否相等,如果相等,输出 a1 == a2 /// a1 填充 1 fill() /// a2 填充 10 /// 整体交换 a1, a2 swap() /// 输出 a1 各元素 [] 或 at() return 0; } 输入描述 第 1 行 10 个整数, 第 2 行 10 个整数 输出描述 见输出样例 用例输入 1 -4 -3 -2 -1 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 用例输出 1 -4 -7 -9 -10 -10 -9 -7 -4 0 5 45 -4 5 1 0x61fda0 a1 < a2 a1 == a2 10 10 10 10 10 10 10 10 10 10
下面是完成代码的示例:
```cpp
#include <iostream>
#include <array>
#include <numeric> // for accumulate() function
using namespace std;
const int N = 10;
int main() {
array<int, N> a1; // create array a1
array<int, N> a2; // create array a2
// read in N elements for a1 and a2
for (int i = 0; i < N; i++) {
cin >> a1[i];
}
for (int i = 0; i < N; i++) {
cin >> a2[i];
}
// use forward iterator to calculate prefix sum of a1
partial_sum(a1.begin(), a1.end(), a1.begin());
// use reverse iterator to calculate sum of a2
int sum_a2 = accumulate(a2.rbegin(), a2.rend(), 0);
// output specific elements of a1
cout << a1.front() << " " << a1.back() << " " << a1.at(N/2) << " " << a1.data() << endl;
// compare two arrays
if (a1 < a2) {
cout << "a1 < a2" << endl;
} else if (a1 > a2) {
cout << "a1 > a2" << endl;
}
// assign a1 to a2
a2 = a1;
// compare a1 and a2
if (a1 == a2) {
cout << "a1 == a2" << endl;
}
// fill a1 with 1 and a2 with 10
a1.fill(1);
a2.fill(10);
// swap contents of a1 and a2
a1.swap(a2);
// output elements of a1
for (int i = 0; i < N; i++) {
cout << a1[i] << " ";
}
cout << endl;
return 0;
}
```
输入:
```
1 -4 -3 -2 -1 0 1 2 3 4
0 1 2 3 4 5 6 7 8 9
```
输出:
```
1 -4 -7 -9 -10 -10 -9 -7 -4 0x7ffc6e8b8b50
a1 < a2
a1 == a2
10 10 10 10 10 10 10 10 10 10
```
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)