- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float f(float x);
float df(float x);
void main()
{
float x0, x1, maxerror, error, g, e1, e2, e3;
printf("NEWTON-RAPHSON PROGRAM \n\n");
printf("Enter x0 : ");
scanf("%f",&x0);
printf("Enter allowed error (in percentage): ");
scanf("%f", &maxerror);
while(error>maxerror){
g=f(x0)/df(x0);
x1=x0-g;
printf("x1 : %.6f",x1);
e1=x1-x0;
e2=e1/x1;
e3=abs(e2);
error=e3*100;
printf("error : %.6f",error);
x0=x1;
}
}
float f(float x)
{
return pow(x,2)+3*x+2;
}
float df(float x)
{
return 2*x+3;
}
有人可以告诉我为什么“while”循环不起作用吗?它只会询问,直到出现允许的错误行,然后程序结束。 “NZEC”代码还存在运行时错误。
最佳答案
while(error>maxerror){
这里的 while 循环不起作用,因为 error>maxerror
没有给出 true,那是因为您还没有初始化 error
(将具有值 0.0f)并且当达到 while 循环内的条件时, maxerror
会更大,您可以在声明它时初始化它,如下所示:
float 错误=22.42
或者可以通过用户输入,例如:
scanf("%f", &error);
关于c - Newton-Raphson C 中的 While 循环不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49344290/
我是这个主题的新手,找不到原因:程序有时有效,有时无效(问完问题后,它根本不想接受我的答案,而我可以我想写多少就写多少,它没有反应,只是列出数字,我给了小费) #include float ab
我警告你,这可能会造成混淆,而且我编写的代码与其说是完成的代码,不如说是思维导图。 我正在尝试实现 Newton-Raphson 方法来求解方程。我想不通的是如何写这个 Python 中的方程,用于根
在下面的代码中,当我选择例如“max_n_iterations”等于 1 时,列表“approximations”在打印时显示两个元素,而它应该只显示一个元素(初始 x)。 这是什么原因? #This
我正在尝试使用 Newton Raphson 方法找到 N 个根。这是我对相同的实现... double derive(int guess, int m, int n) { return gues
我有一个大问题。我需要用 C++ 函数或类求解 3 个变量的 3 个方程的非线性系统。我考虑过使用 Newton-Raphson 方法来执行解决方案。不幸的是,我没有找到可以为我做到这一点的源代码。会
问题的简要说明:我使用 Newton Raphson 算法在多项式中求根,但在某些情况下不起作用。为什么? 我从“c++ 中的数值食谱”中获取了一种 Newton Raphson 混合算法,该算法会在
我编写了牛顿拉夫森求根算法的简单实现,它采用初始猜测 init、一元函数 f 和公差 tol 作为参数,如下所示: bool newton_raphson(double& init,
我正在尝试在 R 中使用 Newton-Raphson 算法来最小化我为一个非常具体的问题编写的对数似然函数。老实说,估计方法超出了我的能力范围,但我知道我的领域(心理测量学)中有很多人使用 NR 算
public class Sqrt { public static void main(String[] args) { double EPS = 1
我在一个简单的程序中工作,该程序使用 Newton-Raphson 方法计算任何给定函数的根。在这个程序中,我必须打印找到的根和进行的迭代次数。程序本身很好,我可以找到任何给定函数的根,但我无法正确计
x=float(raw_input('Enter a number to show its square root')) precise = 0.01 g=x/2.0 while abs(g**2-x
我在 Newton-Raphson 迭代的脚本中收到 'float' object is not Iterable 错误。我将迭代应用于函数 f(x) = sin(x),并将 x0 = 3 应用于迭代
#include #include #include float f(float x); float df(float x); void main() { float x0, x1, m
我目前正在学习一门类(class),讲师使用以下代码在 Java 中实现平方根功能 - public class Sqrt { public static void main(String[]
我已经编写了以下代码来使用牛顿法计算平方根,但每次运行它都会溢出。我试过自己检查,但没有发现任何错误。你们能帮帮我吗? double root(double n,double init){ i
我正在编写一个程序,用一个方程在 Java 中应用 Newton-Raphson 方法: f(x) = 3x - e^x + sin(x) 和 g(x) = f'(x) = 3- e^x + cos
我是 matlab 的新手,我需要创建一个函数,以起始近似值 x = a 执行 Newton-Raphson 方法的 n 次迭代。此起始近似值不算作交互,另一个要求是需要 for 循环。我查看了发布的
Newton-Raphson 平方法的时间复杂度是多少? Wikipedia: Newton's method 最佳答案 来自 http://en.citizendium.org/wiki/Newto
对于这个问题,我们需要利用 Newton-Raphson 方法来定位特定函数的根。 该代码适用于输入为单个值的情况,但当输入为向量时,答案不太正确。 例如,当 x=2是一个输入,值 2.5933返回时
我目前正在遍历一组非常大的数据~85GB(~600M 行)并简单地使用 newton-raphson 来计算一个新参数。截至目前,我的代码非常慢,关于如何加快速度的任何提示? BSCallClass
我是一名优秀的程序员,十分优秀!