所以我试图做一个主函数来计算曲线下的面积。我有三个独立的函数,每个函数都以不同的方式计算区域:函数1使用梯形法则计算,函数2使用Simpsons法则计算,函数3使用Gauss Quadrature计算。我有每个单独的程序运行良好,现在正在尝试将它们从主要功能更改为从称为“数字整合”的单独主程序调用。调用外部函数C
到目前为止,我有我的主:
#include <math.h>
#include <stdlib.h>
#define pi 3.1415927;
void TrapezoidRule(float area);
void SimpsonsRule(float area);
void GaussQuadrature(float area);
int main() {
int userInput, N;
float area, error;
printf("Choose which method to use to calculate the area of the function sin(x) from 0 to pi:\n");
printf("Enter 1 to use the Trapezoid Rule, enter 2 to use Simpson's Rule, enter 3 to use Gauss' Quadrature.\n");
scanf("%d", &userInput);
printf("\nEnter the number of intervals to use to calculate the area.\n");
scanf("%d", &N);
if (userInput == 1) { //Call Trapezoid rule function
TrapezoidRule(area);
}
if (userInput == 2) {
SimpsonsRule(area);
}
if (userInput == 3) {
GaussQuadrature(area);
}
//Print the area calculated using the chosen method
return 0;
}
如果需要的话,我会包括三个独立的功能,但会保持这个贴子短,我会排除他们现在。他们是各自称为:
void TrapezoidRule(float area) {
void GaussQuadrature(float area) {
void SimpsonsRule(float area) {
一个错误,当我尝试编译 我得到(使用icc -o num numericalIntegration.c GaussQuadrature.c TrapezoidRule.c SimpsonsRule.c
) 是梯形规则和辛普森的规则都使用一个小功能在他们度转换为弧度,其我猜在数值积分中没有被正确调用。
因此,这里有我的具体问题:
- 这是正确的方法为在主调用函数?
- 我应该让度数为弧度函数头文件包含在主?我不知道如何做到这一点...
更新:我得到的错误说: 1错误: 第二次错误“‘degtorad’的多个定义”:这里首先定义
我想我明白我需要使功能degtorad头文件,但我不知道如何做到这一点?
不要在散文描述的错误消息。将其剪切并粘贴为编译器生成的100%。它是否说像*未解决的符号*? – Jens
不需要定义'pi',''已经有'M_PI' - 至少它应该。 –
drahnr
'M_PI'不是标准的。 –