C語言例題2-9 利用定點迴路法Fixed point method 求 x^4-3x^2 - 3 = 0
x^4= 3x^2+3
x = pow ( (3x^2+3) , (1/4))
f(x)=x , g(x)= pow ( (3x^2+3) , (1/4))
程式
#include <stdio.h>
#include <math.h>
double f(double x)
{
return x*x*x*x-3*x*x-3; //change equation for each problem
}
double g(double x)
{
return pow((3*x*x+3),.25); //change equation for each problem
}
int main()
{
double p, p0, Tol;
int i=1;
int No;
printf("Enter approximate p: ");
scanf ("%lf", &p0);
printf("Desired Tolerance: ");
scanf ("%lf", &Tol);
printf("Maximum Iterations: ");
scanf ("%d", &No);
printf("\n\n");
while (i<=No)
{
p = g(p0);
if((fabs(p-p0))<Tol)
{
//printf("%lf", &p);
break;
}
printf("Iteration %d: Current value = %lf , the root value = %lf\n", i, p , f(p));
i++; //i=i+1
p0=p;
if (i>No)
{
printf("Method Failed after %d", No);
printf(" iterations");
}
}
}
STDIN輸入資料
1
0.0001
20
輸出畫面
Enter approximate p: Desired Tolerance: Maximum Iterations:
Iteration 1: Current value = 1.565085 , the root value = -4.348469
Iteration 2: Current value = 1.793573 , the root value = -2.302242
Iteration 3: Current value = 1.885944 , the root value = -1.019640
Iteration 4: Current value = 1.922848 , the root value = -0.421680
Iteration 5: Current value = 1.937508 , the root value = -0.169775
Iteration 6: Current value = 1.943317 , the root value = -0.067636
Iteration 7: Current value = 1.945617 , the root value = -0.026833
Iteration 8: Current value = 1.946527 , the root value = -0.010628
Iteration 9: Current value = 1.946887 , the root value = -0.004207
Iteration 10: Current value = 1.947030 , the root value = -0.001665
訂閱:
張貼留言 (Atom)
ESP32 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中
一個典型的 IoT(物聯網)與工業自動化系統整合(SCADA/機台連線) 的架構圖。它透過 Node-RED 作為核心資料網關,將前端 ESP32 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中。 1. 各模組功能拆解...
-
Line 發報機 Python TKinter (CONFIG_LINE Message API_2.py) import serial import serial.tools.list_ports import tkinter as tk from tkinter import...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
沒有留言:
張貼留言