编写一个C#程序,求方程f(x)=x3-5x+2在1.5附近的一个实根。
用牛顿法求根,不要C语言,不要C++
真心不会啊等待高手[img=http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/9.gif][/img
高手快点帮帮我吧,现在很是焦急
用牛顿法求根,不要C语言,不要C++
真心不会啊等待高手[img=http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/9.gif][/img
高手快点帮帮我吧,现在很是焦急
解决方案 »
- 关于SSL通信协议
- [==========] 图片 上 控件 随不同分辨率 错位问题
- 一个特别的字符串匹配的问题
- maskedtextbox如何调成没有分和秒的,
- remoting能用静态方法吗?怎样用?
- .net,c#查询sql数据库的语句?
- 关于datagrid的当前页的问题。。。
- Ueditor怎么加载数据库中的内容
- 请教大家:为何我的.net web服务器达到一定访问量的时候出现“服务器太忙”??
- 为什么无法在C#.net中使用Microsoft Communications Control ,Version 6.0 ,系统提示我“您没有使用此ActiveX控件的许可证。
- 怎么将做好的C#+sqL编写的程序打包成一个安装程序
- 急求:DirectShow 详细步骤
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static double f(int w_f, int x_f, int y_f, int z_f, double sol_f) //当根为x时,用来求f(x)的值
{
double f_result=w_f*Math.Pow(sol_f,3)+x_f*Math.Pow(sol_f,2)+y_f*sol_f+z_f;
// cout<<"f_result is "<<f_result<<endl; //调试时用
return f_result;
} static double f1(int w_f1, int x_f1, int y_f1, int z_f1, double sol_f1) //当根为x时,用来求f'(x)的值
{
double f1_result=3*w_f1*Math.Pow(sol_f1,2)+2*x_f1*sol_f1+y_f1;
// cout<<"f1_result is "<<f1_result<<endl; //调试时用
return f1_result;
} static double get_solution(int w, int x, int y, int z, double sol) //求根函数,调用了上面两个函数
{
double value,tmp; value=sol;
do //使用了x1=x0-f(x0)/f'(x0),不断循环逼近
{
tmp=f(w,x,y,z,value);
value=value-tmp/f1(w,x,y,z,value); // cout<<"funciont_value is "<<tmp<<";value is "<<value<<endl; //调试时用
}while(Math.Abs(tmp)>=1e-5); //当式子的值与0的绝对值小于1e-5时就认为取到了值 return value;
} static void Main(string[] args)
{
int a = 1, b = 0, c = -5, d = 2;
double solution = 1.5d, solution_value; solution_value = get_solution(a, b, c, d, solution);
if (solution_value <= 1e-5) //当求得的根很小时,直接让它为0
solution_value = 0;
Console.WriteLine("the solution near {0} is {1}.", solution, solution_value);
}
}
}the solution near 1.5 is 2.00000000000033.
Press any key to continue . . .