kstars
ksutils.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <kstandarddirs.h>
00019 #include <qfile.h>
00020 #include "ksutils.h"
00021
00022 bool KSUtils::openDataFile( QFile &file, const QString &s ) {
00023 bool result;
00024 QString FileName = locate( "appdata", s );
00025
00026 if ( !FileName.isNull() ) {
00027 file.setName( FileName );
00028 if ( !file.open( IO_ReadOnly ) ) {
00029 result = false;
00030 } else {
00031 result = true;
00032 }
00033 } else {
00034 result = false;
00035 }
00036
00037 return result;
00038 }
00039
00040 long double KSUtils::lagrangeInterpolation( const long double x[], const long double v[], int n, long double xval) {
00041 long double value = 0;
00042 for (int i=1; i<n; ++i) {
00043 long double c = 1.0;
00044 for (int j = 1; j<n;++j)
00045 if (i != j)
00046 c *= (xval - x[j]) / (x[i] - x[j]);
00047 value += c *v[i];
00048 }
00049
00050 return value;
00051 }