1 #define _CRT_SECURE_NO_WARNINGS
16 for (
unsigned int i=0; i<x.size(); i++)
22 std::string
format(
const char* fmt, ...)
26 buffer =
new char[size];
29 int nsize = vsnprintf(buffer,size,fmt,vl);
31 delete buffer; buffer = 0;
32 buffer =
new char[nsize+1];
33 nsize = vsnprintf(buffer,size,fmt,vl);
35 std::string ret(buffer);
41 std::vector<std::string>
strsplit(std::string s,
char del)
43 int iL = 0, iR = 0, N;
45 std::vector<std::string> v;
47 iR = s.find_first_of(del);
55 v.push_back(s.substr(iL,iR-iL));
57 iR = s.find_first_of(del,iR+1);
60 if (iR == (
int)std::string::npos)
62 v.push_back(s.substr(iL,N-iL));
69 double interp1d(std::vector<double> *
x, std::vector<double> *y,
double x0)
79 { L=M; M=(L+R)/2;
continue;}
81 { R=M; M=(L+R)/2;
continue;}
87 return QuadInterp((*x)[i],(*x)[i+1],(*x)[i+2],(*y)[i],(*y)[i+1],(*y)[i+2],x0);
92 return QuadInterp((*x)[i],(*x)[i-1],(*x)[i-2],(*y)[i],(*y)[i-1],(*y)[i-2],x0);
128 product=product*x_in;
133 double QuadInterp(
double x0,
double x1,
double x2,
double f0,
double f1,
double f2,
double x)
140 L0=((x-x1)*(x-x2))/((x0-x1)*(x0-x2));
141 L1=((x-x0)*(x-x2))/((x1-x0)*(x1-x2));
142 L2=((x-x0)*(x-x1))/((x2-x0)*(x2-x1));
143 return L0*f0+L1*f1+L2*f2;
145 double CubicInterp(
double x0,
double x1,
double x2,
double x3,
double f0,
double f1,
double f2,
double f3,
double x)
152 L0=((x-x1)*(x-x2)*(x-x3))/((x0-x1)*(x0-x2)*(x0-x3));
153 L1=((x-x0)*(x-x2)*(x-x3))/((x1-x0)*(x1-x2)*(x1-x3));
154 L2=((x-x0)*(x-x1)*(x-x3))/((x2-x0)*(x2-x1)*(x2-x3));
155 L3=((x-x0)*(x-x1)*(x-x2))/((x3-x0)*(x3-x1)*(x3-x2));
156 return L0*f0+L1*f1+L2*f2+L3*f3;
164 Det=A[0][0]*A[1][1]-A[1][0]*A[0][1];
165 B[0][0]=1.0/Det*A[1][1];
166 B[1][1]=1.0/Det*A[0][0];
167 B[1][0]=-1.0/Det*A[1][0];
168 B[0][1]=-1.0/Det*A[0][1];
174 std::ifstream in(filename, std::ios::in | std::ios::binary);
177 std::string contents;
178 in.seekg(0, std::ios::end);
179 contents.resize((
unsigned int) in.tellg());
180 in.seekg(0, std::ios::beg);
181 in.read(&contents[0], contents.size());
188 void solve_cubic(
double a,
double b,
double c,
double d,
double *x0,
double *x1,
double *x2)
193 double DELTA = 18*a*b*c*d-4*b*b*b*d+b*b*c*c-4*a*c*c*c-27*a*a*d*d;
196 double p = (3*a*c-b*b)/(3*a*a);
197 double q = (2*b*b*b-9*a*b*c+27*a*a*d)/(27*a*a*a);
203 if (4*p*p*p+27*q*q>0 && p<0)
205 t0 = -2.0*fabs(q)/q*sqrt(-p/3.0)*cosh(1.0/3.0*acosh(-3.0*fabs(q)/(2.0*p)*sqrt(-3.0/p)));
209 t0 = -2.0*sqrt(p/3.0)*sinh(1.0/3.0*asinh(3.0*q/(2.0*p)*sqrt(3.0/p)));
218 double t0 = 2.0*sqrt(-p/3.0)*cos(1.0/3.0*acos(3.0*q/(2.0*p)*sqrt(-3.0/p))-0*2.0*
M_PI/3.0);
219 double t1 = 2.0*sqrt(-p/3.0)*cos(1.0/3.0*acos(3.0*q/(2.0*p)*sqrt(-3.0/p))-1*2.0*
M_PI/3.0);
220 double t2 = 2.0*sqrt(-p/3.0)*cos(1.0/3.0*acos(3.0*q/(2.0*p)*sqrt(-3.0/p))-2*2.0*
M_PI/3.0);
228 std::string
strjoin(std::vector<std::string> strings, std::string delim)
231 if (strings.empty()){
return "";}
233 std::string output = strings[0];
234 for (
unsigned int i = 1; i < strings.size(); i++)
236 output +=
format(
"%s%s",delim.c_str(),strings[i].c_str());
std::vector< double > x(ncmax, 0)