📄 vectors.cpp
字号:
// ENERGY211/CME211// // matrix.cpp - Implementation file for Project 1//#include "vectors.h" // Must include corresponding header file#include <cmath>using namespace std;////////////////////////////////////////////////////////////// Implementation of ColVector class////////////////////////////////////////////////////////////ColVector::ColVector( int rows, double *data ) : Matrix( rows, 1, data ){}ColVector::ColVector( const Matrix& A ){ m_rows = A.get_rows(); Reshape( A, A.get_rows() * A.get_cols(), 1 );}ColVector::ColVector( const ColVector& v ) : Matrix( v ){}ColVector::~ColVector(){}ColVector& ColVector::operator=( const Matrix& A ){ // Take your code from Matrix::operator= and put it here, // except that you should throw an exception if A has more // than one column, and otherwise, your code here may assume // that A only has one column Set(A); return *this;}double& ColVector::operator[]( int i ) const{ return m_rowdata[i][0];}double ColVector::norm( const ColVector& v, int p ) { double sum = 0.0; for ( int i = 0; i < v.length(); i++ ) sum += pow( abs( v[i] ), p ); return pow( sum, 1.0 / p );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -