13,826
社区成员
发帖
与我相关
我的任务
分享
#include "math.h"
#include "Math.hpp"
bool MFIInterpolation(double* DataIn, int Dim, double H, double Var, int Level, double* DataOut)
{
if(Dim > 1)
{
// 1. 初始化数据
int Max = pow(2, Level)*(Dim-1);
int L = pow(2, Level); // 初始插值步间隔
for(int i=0; i<Dim; i++) // 埴充插值点
{
DataOut[i*L] = DataIn[i];
}
// 2. 插值
for(int p=0; p<Level; p++)
{
int count = pow(2, p)*(Dim-1); // 每行插值点数量
double Scale = pow(1-pow(2, 2*H-2), 0.5);
for(int i=0; i<=p; i++)
{
Scale *= 1/pow(2, H);
}
for(int i=0; i<count; i++)
{
double D = Scale * RandG(0, Var);
int temp1 = (i+0.5)*L;
DataOut[temp1] = (DataOut[i*L] + DataOut[(i+1)*L])/2 + D;
}
L /= 2;
}
return true;
}
else
{
return false;
}
}
double In[3];
In[0] = 0;
In[1] = 80;
In[2] = 150;
Level = 8;
double Out[513]; // 8级插值后总的点数为(2^(Level-1))*(3-1)+1=513
MFIInterpolation(In, 3, 0.6, 100, Level, Out);