📄 intlinc.c
字号:
/* Copyright (c) Colorado School of Mines, 2003.*//* All rights reserved. *//*********************** self documentation **********************//*****************************************************************************INTLINC - evaluate fcomplex y(x) via linear interpolation of y(x[0]), y(x[1]), ...******************************************************************************Function Prototype:void intlinc (int nin, float xin[], fcomplex yin[], fcomplex yinl, fcomplex yinr, int nout, float xout[], fcomplex yout[]);******************************************************************************Input:nin length of xin and yin arraysxin array[nin] of monotonically increasing or decreasing x valuesyin array[nin] of input y(x) valuesyinl value used to extraplate y(x) to left of input yin valuesyinr value used to extraplate y(x) to right of input yin valuesnout length of xout and yout arraysxout array[nout] of x values at which to evaluate y(x)Output:yout array[nout] of linearly interpolated y(x) values******************************************************************************Notes:xin values must be monotonically increasing or decreasing.Extrapolation of the function y(x) for xout values outside the rangespanned by the xin values in performed as follows: For monotonically increasing xin values, yout=yinl if xout<xin[0], and yout=yinr if xout>xin[nin-1]. For monotonically decreasing xin values, yout=yinl if xout>xin[0], and yout=yinr if xout<xin[nin-1].If nin==1, then the monotonically increasing case is used.*//**************** end self doc ********************************/#include "cwp.h"voidintlinc (int nin, float xin[], fcomplex yin[], fcomplex yinl, fcomplex yinr, int nout, float xout[], fcomplex yout[])/*****************************************************************************evaluate fcomplex y(x) via linear interpolation of y(x[0]), y(x[1]), ...******************************************************************************Input:nin length of xin and yin arraysxin array[nin] of monotonically increasing or decreasing x valuesyin array[nin] of input y(x) valuesyinl value used to extraplate y(x) to left of input yin valuesyinr value used to extraplate y(x) to right of input yin valuesnout length of xout and yout arraysxout array[nout] of x values at which to evaluate y(x)Output:yout array[nout] of linearly interpolated y(x) values******************************************************************************Notes:xin values must be monotonically increasing or decreasing.Extrapolation of the function y(x) for xout values outside the rangespanned by the xin values in performed as follows: For monotonically increasing xin values, yout=yinl if xout<xin[0], and yout=yinr if xout>xin[nin-1]. For monotonically decreasing xin values, yout=yinl if xout>xin[0], and yout=yinr if xout<xin[nin-1].If nin==1, then the monotonically increasing case is used.******************************************************************************Author: intlin(): Dave Hale, Colorado School of Mines, 06/02/89 adapted for fcomplex numbers: Hans Ecke 2002*****************************************************************************/{ static int idx; int jout; float x; /* if input x values are monotonically increasing, then */ if (xin[0]<=xin[nin-1]) { for (jout=0; jout<nout; jout++) { x = xout[jout]; if (x<xin[0]) yout[jout] = yinl; else if (x>xin[nin-1]) yout[jout] = yinr; else if (x==xin[nin-1] || nin==1) yout[jout] = yin[nin-1]; else { xindex(nin,xin,x,&idx); yout[jout] = cadd(yin[idx], crmul(csub(yin[idx+1], yin[idx] ), (x-xin[idx]) / (xin[idx+1]-xin[idx]) ) ); } } /* else, if input x values are monotonically decreasing, then */ } else { for (jout=0; jout<nout; jout++) { x = xout[jout]; if (x>xin[0]) yout[jout] = yinl; else if (x<xin[nin-1]) yout[jout] = yinr; else if (x==xin[nin-1] || nin==1) yout[jout] = yin[nin-1]; else { xindex(nin,xin,x,&idx); yout[jout] = cadd(yin[idx], crmul(csub(yin[idx+1], yin[idx] ), (x-xin[idx])/(xin[idx+1]-xin[idx]) ) ); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -