📄 norm.c
字号:
/**********Copyright 1991 Regents of the University of California. All rights reserved.Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group**********/#include "ngspice.h"/* functions to compute max and one norms of a given vector of doubles */double maxNorm(double *vector, int size){ double norm = 0.0; double candidate; int index, nIndex; nIndex = 1; for( index = 1; index <= size; index++ ) { candidate = fabs(vector[ index ]); if( candidate > norm ) { norm = candidate; nIndex = index; } } /* printf("\n maxNorm: index = %d", nIndex); */ return( norm );}double oneNorm(double *vector, int size){ double norm = 0.0; double value; int index; for( index = 1; index <= size; index++ ) { value = vector[ index ]; if( value < 0.0 ) norm -= value; else norm += value; } return( norm );}double l2Norm(double *vector, int size){ double norm = 0.0; double value; int index; for( index = 1; index <= size; index++ ) { value = vector[ index ]; norm += value * value; } norm = sqrt( norm ); return( norm );}/* * dot(): * computes dot product of two vectors */double dot(double *vector1, double *vector2, int size){ register double dot = 0.0; register int index; for( index = 1; index <= size; index++ ) { dot += vector1[ index ] * vector2[ index ]; } return( dot );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -