弦截法求解方程
2007-09-08 15:59
239 查看
/*弦截法求解方程 Micro_lee*/
#include <stdio.h>
#include <string.h>
#include <math.h>
void asterisk_triangle(int n);
float f(float x)
{
return x*( x*(x-5)+16 )-80;
}
float xpoint(float x1, float x2)
{
return (x1*f(x2) - x2*f(x1))/( f(x2)-f(x1) );
}
float root(float x1, float x2)
{
float x,y,y1,y2;
y1=f(x1);
y2=f(x2);
do{
x=xpoint(x1,x2);
y=f(x);
if(y*y1 > 0)
{
y1=y;
x1=x;
}
else
{
y2=y;
x2=x;
}
}while( fabs(y)>=0.0001);
return (x);
}
int main()
{
float x1,x2,f1,f2,x;
do{
printf("input x1,x2:/n");
scanf("%f,%f", &x1, &x2 );
f1=f(x1);
f2=f(x2);
}while(f1*f2>=0 );
x=root(x1,x2);
printf("A root is %8.4f/n/n", x);
return 0;
}
void asterisk_triangle(int n)
{
int i,j,k, num=0;
for(i=1; i<=n; i++)
{
num= (2*i-1) > n ? 2*(n+1-i)-1: 2*i-1 ;
for(k=1; k<=(n-num)/2; k++)
printf(" ");
for(j=1; j<=num; j++)
printf("*");
printf("/n");
}
}
#include <stdio.h>
#include <string.h>
#include <math.h>
void asterisk_triangle(int n);
float f(float x)
{
return x*( x*(x-5)+16 )-80;
}
float xpoint(float x1, float x2)
{
return (x1*f(x2) - x2*f(x1))/( f(x2)-f(x1) );
}
float root(float x1, float x2)
{
float x,y,y1,y2;
y1=f(x1);
y2=f(x2);
do{
x=xpoint(x1,x2);
y=f(x);
if(y*y1 > 0)
{
y1=y;
x1=x;
}
else
{
y2=y;
x2=x;
}
}while( fabs(y)>=0.0001);
return (x);
}
int main()
{
float x1,x2,f1,f2,x;
do{
printf("input x1,x2:/n");
scanf("%f,%f", &x1, &x2 );
f1=f(x1);
f2=f(x2);
}while(f1*f2>=0 );
x=root(x1,x2);
printf("A root is %8.4f/n/n", x);
return 0;
}
void asterisk_triangle(int n)
{
int i,j,k, num=0;
for(i=1; i<=n; i++)
{
num= (2*i-1) > n ? 2*(n+1-i)-1: 2*i-1 ;
for(k=1; k<=(n-num)/2; k++)
printf(" ");
for(j=1; j<=num; j++)
printf("*");
printf("/n");
}
}
相关文章推荐
- 用弦截法求解方程的根
- 求解方程根的近似解:弦截法
- LA3485二分+求解积分方程+辛普森算法计算积分
- 第三周练习——二分法2 方程求解
- matlab ode方程的求解
- 一元高次方程的求解
- 弦截法求一元三次方程的近似解
- POJ2115——C Looooops(扩展欧几里德+求解模线性方程)
- 方程求解
- Graeffe法求解多项式方程单实根
- Timus1132(二次剩余方程求解)
- hdu_2348_三分求解最值方程_数学题_少用tan
- Eqs 源自罗马尼亚2002年信息学竞赛------------五元三次方程求解
- 快速弦截法求解方程
- Q144:FS,求解流体方程(逻辑总结)
- UVa11300 - Spreading the Wealth(方程求解+中位数)
- C语言——方程求解
- 二分法求解方程的解
- HDU 4033【数学几何余弦定理+二分求解方程】
- AtCoder Beginner Contest 085 C Otoshidama(计算机整数乘法问题+方程求解)