- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Linklist 的 Simpson 1/3 积分方法。
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
struct term{
int power;
int coefficient;
struct term *nxt;
};
struct term *start=NULL;
int deg=0;
double valOfFuncAt(double);
void createEquationTermsInLL(int);
int main(){
double xo,xoTemp,xn,*fx,value;
double h;
double y=0.0,y_=0.0,z=0.0;
int n,i;
printf("Enter The Degree Of The Equation:: ");
scanf("%d",°);
createEquationTermsInLL(deg);
printf("\n\nEnter The Lower Limit,Upper Limit And No. Of Intervals(Must Be Even)::");
scanf("%lf %lf %d",&xo,&xn,&n);
h = (xn - xo)/n;
fx = (double*)malloc((n+1)*sizeof(double));
i=0;
xoTemp=xo;
while(i<=n){
*(fx + i)=valOfFuncAt(xoTemp);
xoTemp = xoTemp + h;
i++;
}
y = (*(fx+0)) + (*(fx + n));
i=1;
while(i<n){
z = z + *(fx + i);
i+=2;
}
z = 4*z;
i=2;
while(i<n){
y_ = y_ + *(fx + i);
i+=2;
}
y_ = 2*y_;
value = (h/3)*(y + z + y_);
printf("Integral Is:: %ld",value);
getch();
}
double valOfFuncAt(double x){
double fx1=0; int i;
struct term *temp=start;
for(i=deg;i>=0;i--){
fx1 = fx1 + (temp->coefficient) * pow(x,temp->power);
temp=temp->nxt;
}
return fx1;
}
void createEquationTermsInLL(int deg1){ /*Creating link list nodes */
static int i=0;
int j,coefficient;
int degClone=deg1;
struct term *temp=NULL;
for(j=1;j<=deg1+1;j++){
if(i==0){
start=(struct term*)malloc(sizeof(struct term));
printf("Enter Coefficient of %dst term",j);
scanf("%d",&coefficient);
start->coefficient=coefficient;
start->power=degClone; i++;
degClone-=1;
temp=start;
}
else{
temp->nxt=(struct term*)malloc(sizeof(struct term));
temp=temp->nxt;
if(j==2)
printf("Enter Coefficient of %dnd term",j);
else if(j==3)
printf("Enter Coefficient of %drd term",j);
else
printf("Enter Coefficient of %dth term",j);
fflush(stdin);
scanf("%d",&coefficient);
temp->power=degClone;
temp->coefficient=coefficient;
degClone-=1;
}
}
temp->nxt=NULL;
}
expecting output to be 60.00 but getting 0, don't know why?尝试通过辛普森 1/3 积分法对任何非线性方程进行积分。在代码块 IDE 中尝试过此操作。应用辛普森1/3规则的正确逻辑进行积分,仍然使被积分值始终为零,不知道我在这段代码中哪里做错了。
最佳答案
/* DEFINING TRAPEZIUM RULE FUNCTION */
double trapeziumrule (Variables *p){
printf("You have chosen the Trapezium Rule!\n");
printf("Please enter the highest order polynomial.\n");
scanf("%d",&p->poly);
for(int i=p->poly ; i>=0 ; --i){
printf("Please enter the coefficient for x^%d: ", i);
scanf("%lg",&p->coeff[i]);
}
//Establishing conditions
printf("\nPlease enter the lower bound \n");
scanf("%lg",&p->lbound);
printf("Please enter the higher bound \n");
scanf("%lg",&p->hbound);
//Sanity Check
if (p->hbound<=p->lbound){
printf("The higher bound must be higher than the lower bound!\n");
return -1;
}
printf("Please enter how many intervals you wish to use \n");
scanf("%lg",&p->interval);
printf("\n You chose a lower bound of %lg, an upper bound of %lg and %lg intervals \n",p->lbound, p->hbound,p->interval);
p->width = (p->hbound-p->lbound)/p->interval;
//Finding the x values to evaluate y at
for (int i=0 ; i<=p->interval ; ++i){
p->x[i]=p->lbound + i*p->width;
}
for (int k=0; k<=p->interval; ++k){
for (int i=0; i<=p->poly; ++i){
//Case for y(0) and y(interval)
if (k==0 || k==p->interval){
p->value=p->coeff[i]*pow(p->x[k],i)*(1.0/2.0);
}
//Case for middle y values
else if (k!=0 || k!=p->interval){
p->value=p->coeff[i]*pow(p->x[k],i);
}
//Adding each segment onto the previous
p->area=p->area+p->value;
}
}
//Finding the area under the curve
p->area=p->area*p->width;
printf("\n The result of the integration via Trapezium rule is %lg \n", p->area);
return 0;
}
/* DEFINING SIMPSONS RULE FUNCTION */
double simpsonsrule (Variables *s){
printf("You have chosen Simpsons rule!\n");
printf("Please enter the highest order polynomial.\n");
scanf("%d",&s->poly);
for(int i=s->poly ; i>=0 ; --i){
printf("Please enter the coefficient for x^%d: ", i);
scanf("%lg",&s->coeff[i]);
}
//Conditions
printf("Please enter the lower bound \n");
scanf("%lg",&s->lbound);
printf("Please enter the higher bound \n");
scanf("%lg",&s->hbound);
//Sanity Check
if (s->hbound<=s->lbound){
printf("The higher bound must be higher than the lower bound!\n");
return -1;
}
printf("Please enter how many intervals you wish to use \n");
scanf("%lg",&s->interval);
printf("\nYou chose a lower bound of %lg, an upper bound of %lg and %lg intervals \n",s->lbound, s->hbound,s->interval);
s->width = (s->hbound-s->lbound)/s->interval;
//Finding the x values to evaluate y at
for (int i=0 ; i<=s->interval ; ++i){
s->x[i]=s->lbound + i*s->width;
}
for (int k=0; k<=s->interval; ++k){
for (int i=0; i<=s->poly; ++i){
//Case for y(0) and y(interval)
if (k==0 || k==s->interval){
s->value=s->coeff[i]*pow(s->x[k],i)*(1.0/3.0);
}
//Case for odd values of y(interval)
else if (k%2!=0 && k!=s->interval){
s->value=s->coeff[i]*pow(s->x[k],i)*(4.0/3.0);
}
//Case for even values of y(interval)
else if (k%2==0 && k!=s->interval){
s->value=s->coeff[i]*pow(s->x[k],i)*(2.0/3.0);
}
s->area=s->area+s->value;
}
}
s->area=s->area*s->width;
printf("\n The result of the integration via Simpsons rule is %lg \n", s->area);
return 0;
}
double midptrule (Variables *m){
printf("You have chosen the Midpoint Rule!\n");
printf("Please enter the highest order polynomial.\n");
scanf("%d",&m->poly);
for(int i=m->poly ; i>=0 ; --i){
printf("Please enter the coefficient for x^%d: ", i);
scanf("%lg",&m->coeff[i]);
}
//Conditions
printf("Please enter the lower bound \n");
scanf("%lg",&m->lbound);
printf("Please enter the higher bound \n");
scanf("%lg",&m->hbound);
printf("Please enter how many intervals you wish to use \n");
scanf("%lg",&m->interval);
printf("\nYou chose a lower bound of %lg, an upper bound of %lg and %lg intervals \n",m->lbound, m->hbound, m->interval);
m->width = ((m->hbound-m->lbound)/m->interval)/2;
//Finding and storing x values
for (int i=0 ; i<m->interval ; ++i){
m->x[i]=m->lbound + (m->width+i*2*m->width);
}
//Calculating the y values
for (int k=0; k<m->interval; ++k){
for (int i=0; i<=m->poly; ++i){
m->value=m->coeff[i]*pow(m->x[k],i);
m->area=m->area+m->value;
}
}
m->area=m->area*2*m->width;
printf("\n The result is %lg \n", m->area);
return 0;
}
关于c - C语言中任意非线性方程的辛普森1/3积分法积分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48549804/
请提出一个数据结构来表示内存中的记录列表。每条记录由以下部分组成: 用户名 积分 排名(基于积分)- 可选字段- 可以存储在记录中或可以动态计算 数据结构应该支持高效实现以下操作: Insert(re
我正在使用 integrate 将一些集成到循环中我想出了一个我无法理解的错误,也无法摆脱。这是我可以提取的 MWE: u_min = 0.06911363 u_max = 1.011011 m =
掌上生活17要吃节签到抽腾讯视频爱奇艺会员月卡 5元饭票 积分 打开掌上生活APP,首页全部专区进入找到活动日历往下拉可以看到17要吃节进入活动页面 可以集3个赞兑换星巴克喝,也可以签到抽爱
我遇到了一个有趣但相当烦人的问题。 我正在尝试集成一个从数据集计算出来的函数。 数据可以在这里找到:Link to sample.txt . 我首先将一条线拟合到我的数据中。这可以通过 approxf
当我使用 Three.js 创建一个点时,它看起来像一个正方形。我怎样才能使它看起来圆?我在文档中看到了一些混合因素,但我不太明白如何在我的观点中使用它们,我什至不知道这是否是正确的方法。 最佳答案
我尝试了此处找到的示例代码: https://developers.facebook.com/docs/creditsapi/即使我添加了我的公司地址和付款方式,我仍然会收到此错误: API Erro
我想使用 scipy.integrate.ode 求解器。我只能将可调用函数 f 定义为离散点数组(因为它取决于先前迭代的积分结果)。但是从文档来看,集成商似乎希望可调用函数是一个连续函数。我想需要进
我无法理解 sympy.integrate() 函数的行为。最简单的例子,整合和分化: t = sy.Symbol('t') t1 = sy.Symbol('t1') f = sy.Function(
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我在 zeroSSL 面板中有一个过期的 SSL 证书,但我无法更新它,因为我生成了 3/3 证书。 1 仍处于事件状态,但其他两个已过期(已为这些相同的域提前生成)。是否有可能以某种方式删除其中一个
我有一个数据结构,例如表达式树或图形。我想添加一些“测量”功能,例如depth和 size . 如何最好地键入这些函数? 我认为以下三个变体的用处大致相同: depth :: Expr -> Int
让 Mathematica 7 或 8 进行积分的最佳方法是什么 NIntegrate[Exp[-x]/Sin[Pi x], {x, 0, 50}] 每个整数都有极点 - 我们需要柯西原理值。这个想法
只是想知道是否有人知道如何查询 Facebook Credits (FBC) API 以获取用户拥有的信用数?我的应用程序有此要求,并且 FBC API 中没有对此进行解释或提及。 谢谢 最佳答案 也
好的,所以这让我难住了超过 3 天,在离解决方案还差一步之后,我要在这里试试运气。 过去,我为一个特定的排序数据集编写了一些代码,它是这样的: n maxobs){FG = 1} else {
在激活通过 MSDN 订阅获得的 Azure 积分时,我使用了工作帐户。 事实证明,由于我没有 Active Directory 管理员权限,因此无法注册应用程序等。这使得它毫无用处。我也不太可能获得
如何使用 Romberg 积分近似计算以下积分, min:1, max:1.6, integral (2x)/((x^2)-4) 还计算 Romberg 表,直到 |R_n-1,n-1 - R_n,n
我正在尝试计算积分 sin(x)/x , x = [0,inf] 我做了以下事情: import math from scipy.integrate import quad t = float("in
所以我的代码有效,只是出于某种原因,我的代码总是运行两个 if 语句(两个 y 方程,无论我为第一个 fprintf 问题输入哪个数字)。此外,t,y 列总是比 t,y2 列长得多(编辑,即如果我输入
我有一个简单的问题。我正在尝试使用 Matlab R2012a 评估 0 阶贝塞尔函数的不正确积分: v = integral(@(x)(besselj(0, x), 0, Inf) 这给了我 v =
我正在与 iPhone Native Game App 一起开发 Facebook Canvas Game 项目,该项目使用 Facebook 积分作为唯一的虚拟货币。 据我们所知,Apple 应用内
我是一名优秀的程序员,十分优秀!