================================
x^3-4x+2 =0 在0.0到2.0之間的解
================================Plot[x^3-4x+2=0 ]
https://www.wolframalpha.com/input/?i=Plot%5Bx%5E3-4x%2B2%3D0+%5D
/* ex2-1.c is used for finding out the domains
* which exist the roots of f(x).
*/
#include <stdio.h>
#include <math.h>
#define f(x) (pow(x,3)-4.0*x+2.0)
void main()
{
double a=0.0,b=2.0,x;
int i;
x=a;
printf(" i x f(x)\n");
for(i=1;;i++)
{
printf("%2d %5.2lf %10.5lf\n",i,x,f(x));
if(x > b)
exit(0);
x=x+0.1;
}
}
====================
輸出畫面
====================i x f(x)
1 0.00 2.00000
2 0.10 1.60100
3 0.20 1.20800
4 0.30 0.82700
5 0.40 0.46400
6 0.50 0.12500
7 0.60 -0.18400
8 0.70 -0.45700
9 0.80 -0.68800
10 0.90 -0.87100
11 1.00 -1.00000
12 1.10 -1.06900
13 1.20 -1.07200
14 1.30 -1.00300
15 1.40 -0.85600
16 1.50 -0.62500
17 1.60 -0.30400
18 1.70 0.11300
19 1.80 0.63200
20 1.90 1.25900
21 2.00 2.00000
沒有留言:
張貼留言