Tag: 数值方法

用于查找五次多项式的一个根的代码

我正在尝试编写一个代码,要求用户为5度多项式提供5个系数,并且还要求给出一个范围(两个值)程序检查是否存在解决方案(我被要求只找到一个),解决方案必须是一个整数,而系数可以是浮点数。 我正在考虑编写一个代码,该代码运行在该范围内的每个整数上,并将其替换为多余的描述,而不是我定义的多项式,并检查它是否等于零,但我决定如何制作循环。 另外,如果用户输入的区间中有多个根,那么我们必须打印根的最小值(但我也没有指示如何做到这一点)。 我将告诉你到目前为止我所写的内容,我们将不胜感激任何一种帮助: #include #define zero 0.00001 int main() { double a, b, c , d , e , f , y , beginning_of_range, end_of_range; int x; printf(“please enter the coefficients of the polynomial:\n”); scanf(“%lf%lf%lf%lf%lf”, &a, &b, &c, &d, &e); printf(“please enter two values to indicate the beginning and end of range:\n”); scanf(“%lf%lf”, &beginning_of_range, […]

Goldberg的log1p与gsl_log1p

我正在寻找一个简单的log1p可移植实现。 我遇到过两个实现。 第一个出现在Theorem 4这里http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html , 以上的实现 double log1p(double p) { volatile double y = p; return ( (1 + y) == 1 ) ? y : y * ( log( 1 + y) / ( ( 1 + y) – 1 ) ); } 第二个是在GSL http://fossies.org/dox/gsl-1.16/log1p_8c_source.html double gsl_log1p (const double x) { volatile double y, […]

C程序 – 泰勒series_long公式

这个公式来自我的一个朋友—我为他修好了。 但我似乎无法弄清楚如何在每个角度进行正确的正弦计算。 有人可以帮助我在罪恶部分得到正确的命令吗? 码: #include #define PI 3.141592653589 #define NUMBER_OF_TERMS 10 double factorial(double x) { double counter, total; counter=x; total=x; while(counter>1) { counter–; total = total * counter; } return total; } double power(double x, double y) { double counter, j; counter=0; j = x; while (counter<(y-1)) { counter++; x = x * j; } […]

数值微分

如何计算在无穷远处涉及指数和奇点的函数的数值二阶导数。 不幸的是,Ridder的方法在“C中的数值配方”中提供的数值导数只能计算一阶导数(它需要预先对函数进行解析表达式。)此外,我尝试了Chebyshev近似并在之后区分函数,但给出的值是方式关闭实际值。 我也尝试过在数学论文中提供的一些有限差分算法,但它们也容易出错。 函数是e ^(x / 2)/ x ^ 2。 对此事我感激不尽。 提前致谢 最新编辑:问题解决了C ++中提供的FADBAD库做得非常好。 它们可以通过http://www.fadbad.com/fadbad.html获得 编辑: // The compilation command used is given below // gcc Q3.c nrutil.c DFRIDR.c -lm -o Q3 #include #include #include “nr.h” #define LIM1 20.0 #define a -5.0 #define b 5.0 #define pre 100.0 // This defines the pre /* This […]

优化查找复数作为输入

我想知道是否有一个C / C ++库或Matlab代码技术来使用最小化求解器来确定实数和复数。 这是一个代码片段,显示了我想要做的事情。 例如,假设我知道Utilde ,但不知道x和U变量。 在给定的Utilde ,我想使用优化( fminsearch )来确定x和U 请注意, Utilde是一个复数。 x = 1.5; U = 50 + 1i*25; x0 = [1 20]; % starting values Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x); xout = fminsearch(@(v)optim(v, Utilde), x0); function diff = optim(v, Utilde) x […]

仅接受使用scanf输入的数值

如何确保用户仅输入数字值而不是字母数字或任何其他字符? 还有什么寻找插入错误信息的incorrent输入? #include int main() { int a, b, c; printf(“Enter first number to add\n”); scanf(“%d”,&a); printf(“Enter second number to add\n”); scanf(“%d”,&b); c = a + b; printf(“Sum of entered numbers = %d\n”,c); return 0; }

使C代码自动绘制图形

我编写了一个程序,将一个数据列表写入’.dat’文件,然后使用gnuplot单独绘制它。 有没有办法让我的代码自动绘制它? 我的输出forms如下: x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation …. 理想情况下,当我运行代码时,图形也会打印出x标签,y标签和标题(可以从我的C代码更改)。 非常感谢。