norm.c

来自「ngspice又一个电子CAD仿真软件代码.功能更全」· C语言 代码 · 共 79 行

C
79
字号
/**********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 + =
减小字号Ctrl + -
显示快捷键?