求二范数C++代码
来源:互联网 发布:python股票量化分析 编辑:程序博客网 时间:2024/06/03 19:38
#include <iostream>#include <cmath>using namespace std;#define NUM 3float num[NUM][NUM] = { 1,2,3,4,5,6,7,8,9 };void Loop(float a[NUM][NUM], float u[NUM], int n){float S, U[NUM];int i, j;for (int i = 0; i <= n - 1; i++){U[i] = u[i];}for (i = 0; i <= n - 1; i++){S = 0.0;for (j = 0; j <= n - 1; j++){S = S + a[i][j] * U[j];}u[i] = S;}}float Max(float u[NUM], int n){float max;int i;max = u[0];for (i = 0; i <= n - 1; i++){if (u[i] > max){max = u[i];}}return max;}//对矩阵进行转置操作void MatrixTransport(float a[NUM][NUM],float b[NUM][NUM]){for (int i = 0; i < NUM; i++)for (int j = 0; j < NUM; j++){b[i][j] = a[j][i];}}void OutputMatrix(float a[NUM][NUM]){for (int i = 0; i < NUM; i++){for (int j = 0; j < NUM; j++){cout << a[i][j] << " ";}cout << endl;}}void MulMatrix(float a[NUM][NUM],float b[NUM][NUM],float c[NUM][NUM]){float temp = 0;for (int i = 0; i < NUM; i++){for (int j = 0; j < NUM; j++){temp = 0;for (int k = 0; k < NUM; k++)temp += a[i][k] * b[k][j];c[i][j] = temp;}}}//求二范数float GetNorm(float a[NUM][NUM]){float x[NUM], y, z;float u[NUM] = { 1, 1, 1 };int i, j, n = NUM;y = Max(u, n);do{z = y;Loop(a, u, n);y = Max(u, n);for (i = 0; i <= n - 1; i++){x[i] = u[i] / y;u[i] = x[i];}} while (fabs(z - y) >= 0.0000005);return sqrt(y);}int main(){float zhuanZhi[NUM][NUM];float mul[NUM][NUM];MatrixTransport(num, zhuanZhi);//OutputMatrix(zhuanZhi);MulMatrix(num, zhuanZhi, mul);OutputMatrix(mul);float norm = GetNorm(mul);cout << norm << endl;return 0;}
0 0
- 求二范数C++代码
- python求范数
- 矢量二范数
- 二范数-特征值的意义-矩阵范数-向量范数-
- 对范数求偏导数
- L0、L1、L2范数与核范数(二)
- norm--求矩阵和向量的范数
- 求矩阵的1,和2范数
- 范数
- 范数
- 范数
- 范数
- 范数
- 范数
- 范数
- 范数
- 范数
- 范数
- mount
- typeof
- Ajax提交表单报400 bad request错误
- 闭包
- I2C总线协议和控制器解析
- 求二范数C++代码
- ccf2014031
- react学习笔记 item9 ---双向绑定(mixin)
- servlet
- 操作系统库-atoi()函数
- 工厂设计模式
- android-lite-http处理http异常返回时的content数据读取
- js学习笔记:Ajax
- 老毛桃U盘快速安装ghost win7系统图文教程