小编Cod*_*key的帖子

布尔的N间隔规则(C)

我试图使用这个公式在n个区间内实施Boole的规则 博尔的规则 X =

到目前为止我已经开发了这个代码:

//f = function on the range [a,b] n = number of intervals
long double booles(long double (*f) (long double), 
                double a, double b, int n) 
{
  long double sum=7*f(a); //because the starting value is not doubled 
  long double h = (b - a)/(n-1); //width of each interval
  int mod;
  int i =1;
  while (i<n-1)
    {
      mod = i%4;
      if (mod==0)
        sum+=14*f(a+i*h);
      else if (mod==1)
        sum+=32*f(a+i*h);
      else if (mod==2)
        sum+=12*f(a+i*h);
      else
        sum+=32*f(a+i*h);
      ++i;
    }
  return 2* h/45 * sum; …
Run Code Online (Sandbox Code Playgroud)

c c++ math integral floating-point-precision

3
推荐指数
1
解决办法
1968
查看次数

"未定义的主要引用"与main在单独的脚本/规则中

这可能是makefile错误的重复:主Makefile中的mainUndefined引用的未定义引用或其他一些引用.crc64和getWord都支持mainProg文件,其中包含我的main函数.当我尝试运行我的make文件时,我收到以下有关crc64.o规则的编译错误.在c文件中,我有在这篇文章中列出的include语句和头文件在C中创建自己的头文件所以我不应该有与链接头到主体相关的链接错误.

错误: gcc -g -Wall -std=c99 crc64.o -o crc64 /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function ``_start': (.text+0x20): undefined reference to ``main' collect2: error: ld returned 1 exit status
Makefile

CC=gcc
COPTS=-g -Wall -std=c99
ALL=crc64 getWord mainProg
all: $(ALL)

crc64: crc64.o
   $(CC) $(COPTS) $^ -o $@
getWord: getWord.o
   $(CC) $(COPTS) $^ -o $@
mainProg: getWord.o crc64.o mainProg.o 
   $(CC) $(COPTS) $^ -o $@
crc64.o: crc64.c crc64.h
getWord.o: getWord.c getWord.h
mainProg.o: mainProg.c getWord.h crc64.h …
Run Code Online (Sandbox Code Playgroud)

c linux gcc makefile

0
推荐指数
1
解决办法
185
查看次数

标签 统计

c ×2

c++ ×1

floating-point-precision ×1

gcc ×1

integral ×1

linux ×1

makefile ×1

math ×1