[JAVA程式語言]例題3-2 依據下表求f'(x)一階微分值
x f(x) f'(x)
======================
-0.3 -0.20431 ????
-0.1 -0.08993 ????
0.1 0.11007 ????
0.3 0.39569 ????
======================
/* ex3-2.java is used for solving nonlinear equation
* based on Fixed-Point Algorithm g(x)=x with initial
* approximation P0.
例題3-2 一下表求f'(x)一階微分值
x f(x) f'(x)
================================
-0.3 -0.20431 ????
-0.1 -0.08993 ????
0.1 0.11007 ????
0.3 0.39569 ????
x=[-0.3 , -0.1 , 0.1 , 0.3]
f=[-0.20431 , -0.08993 , 0.11007 , 0.39569]
(A) 向前差近似 (三點)
fi' = [ -f(i+2) + 4f(i+1) -3 f(i) ] / 2h ,
O(h) = 1/3 * h*h * < fi 三次微分 >
(B) 向後差近似(三點)
fi' = [ 3f(i) - 4f(i-1) + f(i-2) ] / 2h ,
O(h) = 1/3 * h*h * < fi 三次微分 >
(C) 中央近似 (雙點)
fi' = [f(i+1) - f(i-1)] / 2h ,
O(h) = -1/6 * h *h * < fi 三次微分 >
中央近似沒有三點
*/
public class Main {
double FordDiff(int i ){ // 前差微分
// 前差微分 fi' = [ -f(i+2) + 4f(i+1) -3 f(i) ] / 2h ,
double h1,h2,h3,s;
double x[]={-0.3 , -0.1 , 0.1 , 0.3};
double f[]={-0.20431 , -0.08993 , 0.11007 , 0.39569};
h1=x[i+1];
h2=x[i];
h3=Math.abs(h1-h2);
s= -f[i+2] + 4*f[i+1] -3*f[i];
return ( s / (2* h3));
}
double BackDiff(int i ){ // 前差微分
// // 後差微分 fi' = [ 3f(i) - 4f(i-1) + f(i-2) ] / 2h ,
double h1,h2,h3,s;
double x[]={-0.3 , -0.1 , 0.1 , 0.3};
double f[]={-0.20431 , -0.08993 , 0.11007 , 0.39569};
h1=x[i];
h2=x[i-1];
h3=Math.abs(h1-h2);
s= 3*f[i]-4*f[i-1] +f[i-2];
return ( s / (2* h3));
}
public static void main(String args[]){
Main fun = new Main();
double x[]={-0.3 , -0.1 , 0.1 , 0.3};
double f[]={-0.20431 , -0.08993 , 0.11007 , 0.39569};
int i;
//===========================
//前差微分 fi' = [ -f(i+2) + 4f(i+1) -3 f(i) ] / 2h ,
for (i=0;i<=1;i++){
System.out.printf("x= %2.2f , f(x)= %2.6f , FordDiff : %10.6f\n",x[i],f[i],fun.FordDiff(i));
}
System.out.printf("\n\n");
for (i=3;i>1;i--){
System.out.printf("x= %2.2f , f(x)= %2.6f , BackDiff : %10.6f\n",x[i] ,f[i],fun.BackDiff(i));
}
}
}
輸出畫面
x= -0.30 , f(x)= -0.204310 , FordDiff : 0.357850
x= -0.10 , f(x)= -0.089930 , FordDiff : 0.785950
x= 0.30 , f(x)= 0.395690 , BackDiff : 1.642150
x= 0.10 , f(x)= 0.110070 , BackDiff : 1.214050
訂閱:
張貼留言 (Atom)
WOKWI LED + MQTT Node-Red SQLite
WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...
-
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 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言