DEV C++ 求 f(x)=log e (x) 之值
使用c++ Code
// C++ program for implementation of Lagrange's Interpolation
#include<bits/stdc++.h>
using namespace std;
// To represent a data point corresponding to x and y = f(x)
struct Data
{
double x, y;
};
// function to interpolate the given data points using Lagrange's formula
// xi corresponds to the new data point whose value is to be obtained
// n represents the number of known data points
double interpolate(Data f[], double xi, int n)
{
double result = 0; // Initialize result
for (int i=0; i<n; i++)
{
// Compute individual terms of above formula
//double term = f[i].y;
double term = 1;
for (int j=0;j<n;j++)
{
if (j!=i)
term = term*(xi - f[j].x)/double(f[i].x - f[j].x);
}
// Add current term to result
result = result+term*f[i].y;
}
return result;
}
// driver function to check the program
int main()
{
// creating an array of 4 known data points
Data f[] = {{1,0}, {2,0.693}, {3,1.099}, {4,1.386}};
// Using the interpolate function to obtain a data point
// corresponding to x=1.5
cout << "Value of f(1.5) is : " << interpolate(f, 1.5, 4);
return 0;
}
//=====================================================
// driver function to check the program
int main()
{
// creating an array of 4 known data points
Data f[] = {{1,0}, {1.2,0.182}, {1.4,0.336}, {2.0,0.693}};
// Using the interpolate function to obtain a data point
// corresponding to x=1.5
cout << "Value of f(1.5) is : " << interpolate(f, 1.5, 4);
return 0;
}
訂閱:
張貼留言 (Atom)
Messaging API作為替代方案
LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...
-
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 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言