範例EX2-7 依據正割法求
f(x)= exp(x) + 1/pow(2,x) + 2*cos(x)-6 的根 , 誤差=0.00001
x0=1.8 , x1=2.0
輸入資料
1.8 2.0
0.00001 50
#include<stdio.h>
#include <math.h>
float f(float x)
{
return(exp(x) + 1/pow(2,x) + 2*cos(x)-6); // f(x)= exp(x) + 1/pow(2,x) + 2*cos(x)-6
}
float main()
{
float a,b,c,d,e;
int count=1,n;
printf("\n\nEnter the values of a and b:\n"); //(a,b) must contain the solution.
scanf("%f%f",&a,&b);
printf("Enter the values of allowed error and maximun number of iterations:\n");
scanf("%f %d",&e,&n);
do
{
if(f(a)==f(b))
{
printf("\nSolution cannot be found as the values of a and b are same.\n");
return;
}
c=(a*f(b)-b*f(a))/(f(b)-f(a));
a=b;
b=c;
printf("Iteration No-%d x=%f\n",count,c);
count++;
if(count==n)
{
break;
}
} while(fabs(f(c))>e);
printf("\n The required solution is %f\n",c);
}
Enter the values of a and b:
Enter the values of allowed error and maximun number of iterations:
Iteration No-1 x=1.825441
Iteration No-2 x=1.828860
Iteration No-3 x=1.829385
The required solution is 1.829385
訂閱:
張貼留言 (Atom)
MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構
MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 這張圖片展示了一個 結合 MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 (主要透過 Node-RED 進行資料整合)。 系統包含三個核心部分,其運作功能說明如下: 1. ESP32 終端設備(硬體控制層...
-
數位IC設計入門-Verilog combinational logic 8 to 1 Multiplexer 多工器 Behavioral Modeling (& Test Bench) //數位IC設計入門-Verilog combinationa...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
Line 發報機 Python TKinter (CONFIG_LINE Message API_2.py) import serial import serial.tools.list_ports import tkinter as tk from tkinter import...

沒有留言:
張貼留言