source: trunk/MagicSoft/Simulation/Detector/ReflectorII/lagrange.h@ 725

Last change on this file since 725 was 725, checked in by harald, 24 years ago
Ciro and Denis changed the reflector to read in the changed MMCS output (single file version). They made a big change of all the code. That is the reason why I put here a new reflector directory in the repository. This is the future development point for reflector. Until the next drastic change. WARNING: Reflector here is only proved on OSF!!!
File size: 2.0 KB
Line 
1/*
2/////////////////////////////////////////////////////////////////
3//
4// lagrange
5//_______________________________________________________________
6//
7// Created: Sun Jun 14 14:10:18 MET DST 1998
8// Author: Jose Carlos Gonzales
9// Purpose: Macro for Lagrange interpolation of 3rd. order
10// Notes:
11//
12/////////////////////////////////////////////////////////////////
13
14
15//++
16// Formula for Lagrange interpolation of 3rd. order
17// x: value to be interpolated
18// t: table(2xN), table[0]: abscissas, table[1]: ordinates
19// n: higher value of abscissas, such that t[0][n] <= x
20//--
21*/
22
23#define Lagrange(t,n,x) ((t[1][ (n) ]*((x-t[0][(n)+1])*(x-t[0][(n)+2]))/ \
24 ((t[0][ (n) ]-t[0][(n)+1])*(t[0][ (n) ]-t[0][(n)+2])))+ \
25 (t[1][(n)+1]*((x-t[0][ (n) ])*(x-t[0][(n)+2]))/ \
26 ((t[0][(n)+1]-t[0][ (n) ])*(t[0][(n)+1]-t[0][(n)+2])))+ \
27 (t[1][(n)+2]*((x-t[0][ (n) ])*(x-t[0][(n)+1]))/ \
28 ((t[0][(n)+2]-t[0][ (n) ])*(t[0][(n)+2]-t[0][(n)+1]))) \
29 )
30
31/*
32//++
33// Macro to find, and save in variable "m", the value of
34// "n" to be used in the "Lagrange{t,n,x)" macro
35//--
36*/
37
38#define FindLagrange(t,m,x) {m = 0; while (t[0][++m] < x);} --m
39
40/*
41//////////////////////////////////////////////////////////////////////////////
42// Here follows a sample program using this two macros
43//////////////////////////////////////////////////////////////////////////////
44// #include <iostream.h>
45// #include "lagrange.h"
46//
47// void main(void)
48// {
49// float data[2][20];
50// int i, number;
51// float x, y;
52//
53// for (i=0; i<20; ++i) {
54// data[0][i] = i*10.;
55// data[1][i] = 3.0*data[0][i]*data[0][i];
56// cout << data[0][i] << ' ' << data[1][i] << '\n';
57// }
58//
59// while (1==1) {
60// cout << "Enter x = ";
61// cin >> x;
62// FindLagrange(data,number,x);
63// y = Lagrange(data,number,x);
64// cout << x << ' ' << y << '\n';
65// }
66// }
67////////////////////////////////////////////////////////////////////////////// */
68
Note: See TracBrowser for help on using the repository browser.