C語言 例題5-1利用向前Euler尤拉 向前近似法 解一階常微分方程ODE y' = -y+x+1 0<= x <= 1 , y(0)=1 , h=0.2
/* ex5-1.c Forward Euler Method is used for solving y'=f(y,t) of first order
* ordinary differential equation with initial condition y(0)=y0 known.
*/
#include <stdio.h>
#include <math.h>
double F(double x, double y)
{
return (-y+x+1);
}
void main()
{
int i,n;
double h=0.2 , y,x,y0=1,x0=0,x1=1;
n=(x1-x0)/h ;
y=y0;
x=x0;
printf("x y(t) 真實解 abs(y(t)-真實解) \n");
printf("===========================================================\n");
printf("%.2lf %10.6lf %10.6lf %10.6lf \n",x,y,exp(-x)+x , fabs(y-(exp(-x)+x)) );
for(i=1;i<=n;i++)
{
y=y+h*F(x,y);
x=x+h;
printf("%.2lf %10.6lf %10.6lf %10.6lf \n",x,y,exp(-x)+x , fabs(y-(exp(-x)+x)) );
}
return;
}
輸出畫面
x y(t) 真實解 abs(y(t)-真實解)
===========================================================
0.00 1.000000 1.000000 0.000000
0.20 1.000000 1.018731 0.018731
0.40 1.040000 1.070320 0.030320
0.60 1.112000 1.148812 0.036812
0.80 1.209600 1.249329 0.039729
1.00 1.327680 1.367879 0.040199
Command exited with non-zero status 6
訂閱:
張貼留言 (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...
沒有留言:
張貼留言