我试图生成具有11个系数的10阶多项式的值.我也试图产生它的衍生物.我写了三个函数如下所示.此代码生成多项式的值.a1到a10是系数.
float polynm( float a0,float a1,float a2,float a3,float a4,float a5,float a6,float a7,float a8,float a9,float a10,float x)
{
float poly = a0 + a1*x + a2*pow(x,2)+a3*pow(x,3)+a4*pow(x,4)+a5*pow(x,5)+a6*pow(x,6)+a7*pow(x,7)+a8*pow(x,8)+a9*pow(x,9)+a10*pow(x,10);
return poly;
}
Run Code Online (Sandbox Code Playgroud)
此代码生成它调用函数deri的多项式的导数值
float polynm_der(float a0,float a1,float a2,float a3,float a4,float a5,float a6,float a7,float a8,float a9,float a10,float x)
{ float der = a1 + a2*deri(x,2)+a3*deri(x,3)+a4*deri(x,4)+a5*deri(x,5)+a6*deri(x,6)+a7*deri(x,7)+a8*deri(x,8)+a9*deri(x,9)+a10*deri(x,10);
return der;
}
deri is below
float deri(float x,int n)
{
float term_der = n*pow(x,n-1);
return term_der;
}
Run Code Online (Sandbox Code Playgroud)
多项式的代码是低效的.如果我想生成一个100阶多项式,它将变得不可能.有没有办法可以递归生成多项式及其导数,以避免笨重的代码.
我有一个C项目,我必须扫描array[10][15]
对角线,如下图所示.
我想帮助我找到如何以这种方式扫描阵列......非常感谢你.
对不起我的英语(我是希腊语)
我struct bbb
在kill程序中释放最后一个变量时遇到程序崩溃.但为什么呢?假设某处出现问题free
.
struct bbb
{
struct bbb * h;
char a [256];
int i;
};
void kill(struct bbb * value)
{
if (value!=NULL)
{
kill(value->h);
printf("killing %s\n", value->a);
free(value);
printf("killed\n");
value=NULL;
}
}
void ins(struct bbb * b, struct bbb * a )
{
b->h= malloc(sizeof(struct bbb ) );
b->h[0]=*a;
}
int main(void) {
struct bbb a;
struct bbb b;
struct bbb c;
//ss=s;
sprintf(a.a,"aaa" );
sprintf(b.a,"bbb" );
sprintf(c.a,"ccc" );
ins(&b,&c);
ins(&a,&b);
kill(&a);
//printf("a.a=%s\n",a.a);
return EXIT_SUCCESS; …
Run Code Online (Sandbox Code Playgroud) 可以在Coca Touch中使用矢量吗?如果是这样,必须包含哪些库?
我正在关注他们的一般C教程,唯一需要的是 #include <vector>
但XCode声明没有这样的文件或目录.
任何指向提供此类功能的库的指针都是值得赞赏的.
问候~dhp
我有一个稀疏数组,例如:
rare = [[0,1], [2,3], [4,5], [7,8]]
Run Code Online (Sandbox Code Playgroud)
我想用这些数据绘制图表,每对都是点坐标.如你所见,我没有x = 1,x = 3,x = 5,x = 6的分数
我想用以前的值填充数组,所以对于上面的例子,我将得到:
filled = [[0,1], [1,1], [2,3], [3,3], [4,5], [5,5], [6,5], [7,8]
Run Code Online (Sandbox Code Playgroud)
如您所见,为了计算y值,我只需使用我使用的最后一个y值.
完成此任务的最佳方法是什么?
在C中,是以下等价物:
long int x = 3L;
(注意L
)
和
long int x = 3
他们似乎是一样的.如果是,应该使用哪一个?应该L
明确指定吗?
如果它们不同,有什么区别?
如何从第一列中删除第二个和其余数字?
例如,
HP_000083.21423 N -1 NO 99.8951% 0.000524499999999983
NP_075561.1_1908 N -1 NO 99.9697% 0.000151499999999971
Run Code Online (Sandbox Code Playgroud)
我想从"NP_075561.1_1908"中删除"_1908"
和"1423来自"HP_000083.21423"
不从后续列中删除其他项目.
预期的行将是:
HP_000083.2 N -1 NO 99.8951% 0.000524499999999983
NP_075561.1 N -1 NO 99.9697% 0.000151499999999971
Run Code Online (Sandbox Code Playgroud)
这是我的代码:你们中的一些人过去曾提供过这个解决方案的一部分.
for line in fname:
line = re.sub('[\(\)\{\}\'\'\,<>]','', line)
line = re.sub(r"(\.\d+)_\d+", r"\1", line)
fields = line.rstrip("\n").split()
outfile.write('%s %s %s %s %s %s\n' % (fields[0],fields[1],fields[2],fields[3],fields[4],(fields[5])))
Run Code Online (Sandbox Code Playgroud)
先谢谢你们,干杯,
我在c ++中搜索最佳源代码/算法,将帧数转换为时间码hh:mm:ss:ff,给定fps,例如.25fps的...
这段代码很好 - http://www.andrewduncan.ws/Timecodes/Timecodes.html(页面底部)但价格昂贵 - 它包含4个mod和6个div操作
我需要在每个帧上显示时间码,因此计算此算法可能需要一些时间.
我当然可以存储评估的时间码以避免计算.
但了解更好的算法会非常有帮助...
在此先感谢你的.
我正在尝试为嵌入式系统编译 ncurses 5.9(使用 buildroot),但收到以下错误消息:
\n\nIn file included from ../c++/cursesm.h:39:0,\n from ../c++/cursesm.cc:35:\n../c++/cursesp.h: In member function \xe2\x80\x98T* NCursesUserPanel<T>::UserData() const\xe2\x80\x99:\n../c++/cursesp.h:256:43: error: no matching function for call to \n\xe2\x80\x98NCursesUserPanel<T>::get_user() const\xe2\x80\x99\n return reinterpret_cast<T*>(get_user ());\n
Run Code Online (Sandbox Code Playgroud)\n\n这是有问题的代码:
\n\n/* We use templates to provide a typesafe mechanism to associate\n * user data with a panel. A NCursesUserPanel<T> is a panel\n * associated with some user data of type T.\n */\ntemplate<class T> class NCursesUserPanel : public NCursesPanel\n{\npublic:\n NCursesUserPanel (int nlines,\n int ncols,\n int begin_y = 0,\n …
Run Code Online (Sandbox Code Playgroud)