#include <iostream>
#include "mtl/utils.h"
#include "mtl/mtl.h"
#include "mtl/linalg_vec.h"
/*
Sample output;
X: [1,2,3,4,]
The L-1 norm of X is 10
*/
using namespace mtl;
int
main()
{
double x_[5] = { 1, 2, 3, 4,5 };
double s = one_norm(array_to_vec(x_));
std::cout << "X: ";
print_vector(array_to_vec(x_));
std::cout << "The L-1 norm of X is " << s << std::endl;
}
输出:
X: [1,2,3,4]
The L-1 norm of X is 10
博客给出一段代码,通过包含多个头文件,定义数组并转换为向量,计算向量的L-1范数并输出结果。代码中使用了iostream等头文件,展示了向量范数计算的实现过程。
1062





