📄 vector_double.c
字号:
/* * ============================================================================= * ALADDIN Version 1.0 : * vector_double.c : Vector operations for data type double * * Copyright (C) 1995 by Mark Austin, Xiaoguang Chen, and Wane-Jang Lin * Institute for Systems Research, * University of Maryland, College Park, MD 20742 * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software for any on any computer system * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written by: M.A. Austin July 1993 * ============================================================================= *//* #define DEBUG */#include <stdio.h>#include "units.h"#include "matrix.h"#include "vector.h"#include "defs.h"/* * ================================================================= * Print Vector [length], where length = no items in Vector * ================================================================= */#ifdef __STDC__void PrintVectorDouble(VECTOR *v)#elsevoid PrintVectorDouble(v)VECTOR *v;#endif{int i; if(v->cpVectorName != NULL) printf ("\nVECTOR \"%s\" \n\n", v->cpVectorName); else printf("\nVECTOR : \"UNTITLED\" \n\n"); for(i = 1; i <= v->iLength; i++) { printf(" %3d ",i); printf(" %16.9e\n", v->uVector.da[i-1]); } printf("\n");}/* * ================================================= * Allocate and Free Vector data structure * ================================================= */#ifdef __STDC__double *dVectorAlloc(int length)#elsedouble *dVectorAlloc( length)int length;#endif{double *array; array = (double *) MyCalloc( length, sizeof(double)); return (array);}#ifdef __STDC__void VectorFreeDouble(VECTOR *v)#elsevoid VectorFreeDouble(v)VECTOR *v;#endif{ free ((char *) v->uVector.da); free ((char *) v->cpVectorName); free ((char *) v); v = (VECTOR *)NULL;}/* * ================= * Vector Operations * ================= */#ifdef __STDC__VECTOR *VectorAddDouble(VECTOR *v1, VECTOR *v2)#elseVECTOR *VectorAddDouble(v1, v2)VECTOR *v1;VECTOR *v2;#endif{VECTOR *v3;int i; /* [a] : Check Dimensions of Vector */ if(v1->iLength != v2->iLength) { printf("FATAL ERROR >> Execution halted in VectorAdd()\n"); printf("FATAL ERROR >> Problem : v1->iLength = %4d\n", v1->iLength); printf("FATAL ERROR >> Problem : v2->iLength = %4d\n", v2->iLength); FatalError("Inconsistent Dimensions",(char *)NULL); } /* [b] : Add Matrices */ v3 = VectorAlloc((char *) NULL, DOUBLE_ARRAY, v2->iLength); for(i = 1; i <= v2->iLength; i++) v3->uVector.da[i] = v1->uVector.da[i] + v2->uVector.da[i]; return(v3);}#ifdef __STDC__VECTOR *VectorSubDouble(VECTOR *v1, VECTOR *v2)#elseVECTOR *VectorSubDouble(v1, v2)VECTOR *v1;VECTOR *v2;#endif{VECTOR *v3;int i; /* [a] : Check Dimensions of Vector */ if(v1->iLength != v2->iLength) { printf("FATAL ERROR >> Execution halted in VectorAdd()\n"); printf("FATAL ERROR >> Problem : v1->iLength = %4d\n", v1->iLength); printf("FATAL ERROR >> Problem : v2->iLength = %4d\n", v2->iLength); FatalError("Inconsistent Dimensions",(char *)NULL); } /* [b] : Add Matrices */ v3 = VectorAlloc((char *) NULL, DOUBLE_ARRAY, v2->iLength); for(i = 1; i <= v2->iLength; i++) v3->uVector.da[i] = v1->uVector.da[i] - v2->uVector.da[i]; return(v3);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -