2018年12月27日 星期四

EX2-1 x^3-4x+2 =0 在0.0到2.0之間的解


================================
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

沒有留言:

張貼留言

2024產專班 作業2

 2024產專班 作業2   1. 系統圖       ESP32+MFRC522 組成RFID Reader 可以將RFID卡片的UID 透過 MQTT協定    上傳(發行 主題 (:topic) alex9ufo/2024/RFID/RFID_UID  ,, Payload...