怎样用c语言编程解较复杂的方程

怎样用c语言编程解较复杂的方程?如exp(x)+x^2=C,log(x)+x^2=2^x;等等望各位高手指教!!

用牛顿迭代法我给一个例子求下面方程在1.5附近的根
2x^3-4x^2+3x-6=0
答案如下:
#include "stdio.h"
#include<math.h>
void main()
{
double f(double x);
double x1=-10.0,x2=10.0,xx;
while(1)
{
xx=(x1+x2)/2;
if(fabs(f(xx)-0)<1e-5)break;
if(f(xx)>0)x2=xx;
if(f(xx)<0)x1=xx;
}
printf("one foot of x is %f\n",xx);
}
double f(double x)
{
return (2*x*x*x-4*x*x+3*x-6);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-02
数值计算是一门专业,请参考 《numeric recipes》

这里的用户伤我太深,淡定中。。 适时离开