InterpolaterDlg.cpp
上传用户:weigute
上传日期:2007-03-02
资源大小:1287k
文件大小:22k
源码类别:

数学计算

开发平台:

Visual C++

  1. // InterpolaterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Interpolater.h"
  5. #include "InterpolaterDlg.h"
  6. #include "Interpolate.h"
  7. #include "Spline3Dlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAboutDlg dialog used for App About
  15. class CAboutDlg : public CDialog
  16. {
  17. public:
  18. CAboutDlg();
  19. // Dialog Data
  20. //{{AFX_DATA(CAboutDlg)
  21. enum { IDD = IDD_ABOUTBOX };
  22. //}}AFX_DATA
  23. // ClassWizard generated virtual function overrides
  24. //{{AFX_VIRTUAL(CAboutDlg)
  25. protected:
  26. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  27. //}}AFX_VIRTUAL
  28. // Implementation
  29. protected:
  30. //{{AFX_MSG(CAboutDlg)
  31. //}}AFX_MSG
  32. DECLARE_MESSAGE_MAP()
  33. };
  34. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  35. {
  36. //{{AFX_DATA_INIT(CAboutDlg)
  37. //}}AFX_DATA_INIT
  38. }
  39. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CAboutDlg)
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  46. //{{AFX_MSG_MAP(CAboutDlg)
  47. // No message handlers
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CInterpolaterDlg dialog
  52. CInterpolaterDlg::CInterpolaterDlg(CWnd* pParent /*=NULL*/)
  53. : CDialog(CInterpolaterDlg::IDD, pParent)
  54. {
  55. //{{AFX_DATA_INIT(CInterpolaterDlg)
  56. m_strXi = _T("");
  57. m_strYi = _T("");
  58. m_nNumNodes = 0;
  59. m_nNumTargetNodes = 1;
  60. m_strTargetXi = _T("");
  61. m_strStepOrBorderCondition = _T("");
  62. //}}AFX_DATA_INIT
  63. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  64. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  65. }
  66. void CInterpolaterDlg::DoDataExchange(CDataExchange* pDX)
  67. {
  68. CDialog::DoDataExchange(pDX);
  69. //{{AFX_DATA_MAP(CInterpolaterDlg)
  70. DDX_Text(pDX, IDC_EDIT1, m_strXi);
  71. DDX_Text(pDX, IDC_EDIT2, m_strYi);
  72. DDX_Text(pDX, IDC_EDIT3, m_nNumNodes);
  73. DDX_Text(pDX, IDC_EDIT5, m_nNumTargetNodes);
  74. DDX_Text(pDX, IDC_EDIT6, m_strTargetXi);
  75. DDX_Text(pDX, IDC_EDIT4, m_strStepOrBorderCondition);
  76. //}}AFX_DATA_MAP
  77. }
  78. BEGIN_MESSAGE_MAP(CInterpolaterDlg, CDialog)
  79. //{{AFX_MSG_MAP(CInterpolaterDlg)
  80. ON_WM_SYSCOMMAND()
  81. ON_WM_PAINT()
  82. ON_WM_QUERYDRAGICON()
  83. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  84. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  85. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  86. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  87. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  88. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  89. ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
  90. ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
  91. ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
  92. ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
  93. ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
  94. ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
  95. ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
  96. ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
  97. ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
  98. ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
  99. ON_BN_CLICKED(IDC_BUTTON17, OnButton17)
  100. //}}AFX_MSG_MAP
  101. END_MESSAGE_MAP()
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CInterpolaterDlg message handlers
  104. BOOL CInterpolaterDlg::OnInitDialog()
  105. {
  106. CDialog::OnInitDialog();
  107. // Add "About..." menu item to system menu.
  108. // IDM_ABOUTBOX must be in the system command range.
  109. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  110. ASSERT(IDM_ABOUTBOX < 0xF000);
  111. CMenu* pSysMenu = GetSystemMenu(FALSE);
  112. if (pSysMenu != NULL)
  113. {
  114. CString strAboutMenu;
  115. strAboutMenu.LoadString(IDS_ABOUTBOX);
  116. if (!strAboutMenu.IsEmpty())
  117. {
  118. pSysMenu->AppendMenu(MF_SEPARATOR);
  119. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  120. }
  121. }
  122. // Set the icon for this dialog.  The framework does this automatically
  123. //  when the application's main window is not a dialog
  124. SetIcon(m_hIcon, TRUE); // Set big icon
  125. SetIcon(m_hIcon, FALSE); // Set small icon
  126. // TODO: Add extra initialization here
  127. return TRUE;  // return TRUE  unless you set the focus to a control
  128. }
  129. void CInterpolaterDlg::OnSysCommand(UINT nID, LPARAM lParam)
  130. {
  131. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  132. {
  133. CAboutDlg dlgAbout;
  134. dlgAbout.DoModal();
  135. }
  136. else
  137. {
  138. CDialog::OnSysCommand(nID, lParam);
  139. }
  140. }
  141. // If you add a minimize button to your dialog, you will need the code below
  142. //  to draw the icon.  For MFC applications using the document/view model,
  143. //  this is automatically done for you by the framework.
  144. void CInterpolaterDlg::OnPaint() 
  145. {
  146. if (IsIconic())
  147. {
  148. CPaintDC dc(this); // device context for painting
  149. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  150. // Center icon in client rectangle
  151. int cxIcon = GetSystemMetrics(SM_CXICON);
  152. int cyIcon = GetSystemMetrics(SM_CYICON);
  153. CRect rect;
  154. GetClientRect(&rect);
  155. int x = (rect.Width() - cxIcon + 1) / 2;
  156. int y = (rect.Height() - cyIcon + 1) / 2;
  157. // Draw the icon
  158. dc.DrawIcon(x, y, m_hIcon);
  159. }
  160. else
  161. {
  162. CDialog::OnPaint();
  163. }
  164. }
  165. // The system calls this to obtain the cursor to display while the user drags
  166. //  the minimized window.
  167. HCURSOR CInterpolaterDlg::OnQueryDragIcon()
  168. {
  169. return (HCURSOR) m_hIcon;
  170. }
  171. /*
  172. 10
  173. 0.10,0.15,0.25,0.40,0.50,0.57,0.70,0.85,0.93,1.00
  174. 0.904837,0.860708,0.778801,0.670320,0.606531,0.565525,0.496585,0.427415,0.394554,0.367879
  175. 1
  176. 0.63
  177. */
  178. // 一元全区间不等距插值
  179. void CInterpolaterDlg::OnButton1() 
  180. {
  181. // 获取数据
  182. UpdateData();
  183. double *x = new double[m_nNumNodes];
  184. double *y = new double[m_nNumNodes];
  185. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  186. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  187. // 插值运算
  188. double *t = new double[m_nNumTargetNodes];
  189. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  190. // 显示结果
  191. m_strTargetYi = "";
  192. for (int i=0; i<m_nNumTargetNodes; ++i)
  193. {
  194. double yt = CInterpolate::GetValueLagrange(m_nNumNodes, x, y, t[i]);
  195. CString s;
  196. s.Format("f(%f) = %frn", t[i], yt);
  197. m_strTargetYi += s;
  198. }
  199. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  200. // 释放内存
  201. delete[] t;
  202. delete[] x;
  203. delete[] y;
  204. }
  205. /*
  206. 10
  207. 0.1
  208. 0.1;
  209. 0.904837,0.818731,0.740818,0.670320,0.606531,0.548812,0.496585,0.449329,0.406570,0.367879
  210. 3
  211. 0.25,0.63,0.95
  212. */
  213. // 一元全区间等距插值
  214. void CInterpolaterDlg::OnButton2() 
  215. {
  216. // 获取数据
  217. UpdateData();
  218. double x0;
  219. double *y = new double[m_nNumNodes];
  220. CInterpolate::GetNodesFromString(m_strXi, 1, &x0, ",");
  221. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  222. // 插值运算
  223. double *t = new double[m_nNumTargetNodes];
  224. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  225. // 显示结果
  226. double dblStep = atof(m_strStepOrBorderCondition);
  227. m_strTargetYi = "";
  228. for (int i=0; i<m_nNumTargetNodes; ++i)
  229. {
  230. double yt = CInterpolate::GetValueLagrange(m_nNumNodes, x0, dblStep, y, t[i]);
  231. CString s;
  232. s.Format("f(%f) = %frn", t[i], yt);
  233. m_strTargetYi += s;
  234. }
  235. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  236. // 释放内存
  237. delete[] t;
  238. delete[] y;
  239. }
  240. /*
  241. 5
  242. 1.615,1.634,1.702,1.828,1.921
  243. 2.41450,2.46459,2.65271,3.03035,3.34066
  244. 2
  245. 1.682,1.813
  246. */
  247. // 一元三点不等距插值
  248. void CInterpolaterDlg::OnButton3() 
  249. {
  250. // 获取数据
  251. UpdateData();
  252. double *x = new double[m_nNumNodes];
  253. double *y = new double[m_nNumNodes];
  254. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  255. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  256. // 插值运算
  257. double *t = new double[m_nNumTargetNodes];
  258. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  259. // 显示结果
  260. m_strTargetYi = "";
  261. for (int i=0; i<m_nNumTargetNodes; ++i)
  262. {
  263. double yt = CInterpolate::GetValueLagrange3(m_nNumNodes, x, y, t[i]);
  264. CString s;
  265. s.Format("f(%f) = %frn", t[i], yt);
  266. m_strTargetYi += s;
  267. }
  268. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  269. // 释放内存
  270. delete[] t;
  271. delete[] x;
  272. delete[] y;
  273. }
  274. /*
  275. 10
  276. 0.1
  277. 0.1
  278. 0.904837,0.818731,0.740818,0.670320,0.606531,0.548812,0.496585,0.449329,0.406570,0.367879
  279. 3
  280. 0.23,0.63,0.95
  281. */
  282. // 一元三点等距插值
  283. void CInterpolaterDlg::OnButton4() 
  284. {
  285. // 获取数据
  286. UpdateData();
  287. double x0;
  288. double *y = new double[m_nNumNodes];
  289. CInterpolate::GetNodesFromString(m_strXi, 1, &x0, ",");
  290. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  291. // 插值运算
  292. double *t = new double[m_nNumTargetNodes];
  293. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  294. // 显示结果
  295. double dblStep = atof(m_strStepOrBorderCondition);
  296. m_strTargetYi = "";
  297. for (int i=0; i<m_nNumTargetNodes; ++i)
  298. {
  299. double yt = CInterpolate::GetValueLagrange3(m_nNumNodes, x0, dblStep, y, t[i]);
  300. CString s;
  301. s.Format("f(%f) = %frn", t[i], yt);
  302. m_strTargetYi += s;
  303. }
  304. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  305. // 释放内存
  306. delete[] t;
  307. delete[] y;
  308. }
  309. /*
  310. 10
  311. -1.0,-0.8,-0.65,-0.4,-0.3,0.0,0.2,0.45,0.8,1.0
  312. 0.0384615,0.0588236,0.0864865,0.2,0.307692,1.0,0.5,0.164948,0.0588236,0.0384615
  313. 2
  314. 0.85,0.25
  315. */
  316. // 连分式不等距插值
  317. void CInterpolaterDlg::OnButton5() 
  318. {
  319. // 获取数据
  320. UpdateData();
  321. double *x = new double[m_nNumNodes];
  322. double *y = new double[m_nNumNodes];
  323. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  324. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  325. // 插值运算
  326. double *t = new double[m_nNumTargetNodes];
  327. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  328. // 显示结果
  329. m_strTargetYi = "";
  330. for (int i=0; i<m_nNumTargetNodes; ++i)
  331. {
  332. double yt = CInterpolate::GetValuePqs(m_nNumNodes, x, y, t[i]);
  333. CString s;
  334. s.Format("f(%f) = %frn", t[i], yt);
  335. m_strTargetYi += s;
  336. }
  337. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  338. // 释放内存
  339. delete[] t;
  340. delete[] x;
  341. delete[] y;
  342. }
  343. /*
  344. 11
  345. 0.2
  346. -1.0
  347. 0.0384615,0.0588236,0.1,0.2,0.5,1.0,0.5,0.2,0.1,0.0588236,0.0384615
  348. 2
  349. -0.75, -0.05
  350. */
  351. // 连分式等距插值
  352. void CInterpolaterDlg::OnButton6() 
  353. {
  354. // 获取数据
  355. UpdateData();
  356. double x0;
  357. double *y = new double[m_nNumNodes];
  358. CInterpolate::GetNodesFromString(m_strXi, 1, &x0, ",");
  359. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  360. // 插值运算
  361. double *t = new double[m_nNumTargetNodes];
  362. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  363. // 显示结果
  364. double dblStep = atof(m_strStepOrBorderCondition);
  365. m_strTargetYi = "";
  366. for (int i=0; i<m_nNumTargetNodes; ++i)
  367. {
  368. double yt = CInterpolate::GetValuePqs(m_nNumNodes, x0, dblStep, y, t[i]);
  369. CString s;
  370. s.Format("f(%f) = %frn", t[i], yt);
  371. m_strTargetYi += s;
  372. }
  373. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  374. // 释放内存
  375. delete[] t;
  376. delete[] y;
  377. }
  378. /*
  379. 10
  380. 0.1,0.15,0.3,0.45,0.55,0.6,0.7,0.85,0.9,1.0
  381. 0.904837,0.860708,0.740818,0.637628,0.576950,0.548812,0.496585,0.427415,0.406570,0.367879
  382. 1
  383. 0.356
  384. */
  385. // 埃尔米特不等距插值
  386. void CInterpolaterDlg::OnButton7() 
  387. {
  388. // 获取数据
  389. UpdateData();
  390. double *x = new double[m_nNumNodes];
  391. double *y = new double[m_nNumNodes];
  392. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  393. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  394. double *dy = new double[m_nNumNodes];
  395. for (int i=0; i<m_nNumNodes; ++i)
  396. dy[i]=-y[i];
  397. // 插值运算
  398. double *t = new double[m_nNumTargetNodes];
  399. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  400. // 显示结果
  401. m_strTargetYi = "";
  402. for (i=0; i<m_nNumTargetNodes; ++i)
  403. {
  404. double yt = CInterpolate::GetValueHermite(m_nNumNodes, x, y, dy, t[i]);
  405. CString s;
  406. s.Format("f(%f) = %frn", t[i], yt);
  407. m_strTargetYi += s;
  408. }
  409. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  410. // 释放内存
  411. delete[] dy;
  412. delete[] t;
  413. delete[] x;
  414. delete[] y;
  415. }
  416. /*
  417. 10
  418. 0.1
  419. 0.1
  420. 0.904837,0.818731,0.740818,0.670320,0.606531,0.548812,0.496585,0.449329,0.406570,0.367879
  421. 1
  422. 0.752
  423. */
  424. // 埃尔米特等距插值
  425. void CInterpolaterDlg::OnButton8() 
  426. {
  427. // 获取数据
  428. UpdateData();
  429. double x0;
  430. double *y = new double[m_nNumNodes];
  431. CInterpolate::GetNodesFromString(m_strXi, 1, &x0, ",");
  432. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  433. double *dy = new double[m_nNumNodes];
  434. for (int i=0; i<m_nNumNodes; ++i)
  435. dy[i]=-y[i];
  436. // 插值运算
  437. double *t = new double[m_nNumTargetNodes];
  438. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  439. // 显示结果
  440. double dblStep = atof(m_strStepOrBorderCondition);
  441. m_strTargetYi = "";
  442. for (i=0; i<m_nNumTargetNodes; ++i)
  443. {
  444. double yt = CInterpolate::GetValueHermite(m_nNumNodes, x0, dblStep, y, dy, t[i]);
  445. CString s;
  446. s.Format("f(%f) = %frn", t[i], yt);
  447. m_strTargetYi += s;
  448. }
  449. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  450. // 释放内存
  451. delete[] dy;
  452. delete[] t;
  453. delete[] y;
  454. }
  455. /*
  456. 10
  457. -1.0,-0.8,-0.65,-0.4,-0.3,0.0,0.2,0.4,0.6,0.8,1.0
  458. 0.0384615,0.0588236,0.0864865,0.2,0.307692,1.0,0.5,0.2,0.1,0.0588236,0.0384615
  459. 2
  460. -0.75,0.05
  461. */
  462. // 埃特金不等距逐步插值
  463. void CInterpolaterDlg::OnButton9() 
  464. {
  465. // 获取数据
  466. UpdateData();
  467. double *x = new double[m_nNumNodes];
  468. double *y = new double[m_nNumNodes];
  469. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  470. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  471. // 插值运算
  472. double *t = new double[m_nNumTargetNodes];
  473. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  474. // 显示结果
  475. m_strTargetYi = "";
  476. for (int i=0; i<m_nNumTargetNodes; ++i)
  477. {
  478. double yt = CInterpolate::GetValueAitken(m_nNumNodes, x, y, t[i]);
  479. CString s;
  480. s.Format("f(%f) = %frn", t[i], yt);
  481. m_strTargetYi += s;
  482. }
  483. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  484. // 释放内存
  485. delete[] t;
  486. delete[] x;
  487. delete[] y;
  488. }
  489. /*
  490. 10
  491. 0.1
  492. 0.1
  493. 0.904837,0.818731,0.740818,0.670320,0.606531,0.548812,0.496585,0.449329,0.406570,0.367879
  494. 2
  495. 0.15,0.55
  496. */
  497. // 埃特金等距逐步插值
  498. void CInterpolaterDlg::OnButton10() 
  499. {
  500. // 获取数据
  501. UpdateData();
  502. double x0;
  503. double *y = new double[m_nNumNodes];
  504. CInterpolate::GetNodesFromString(m_strXi, 1, &x0, ",");
  505. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  506. // 插值运算
  507. double *t = new double[m_nNumTargetNodes];
  508. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  509. // 显示结果
  510. double dblStep = atof(m_strStepOrBorderCondition);
  511. m_strTargetYi = "";
  512. for (int i=0; i<m_nNumTargetNodes; ++i)
  513. {
  514. double yt = CInterpolate::GetValueAitken(m_nNumNodes, x0, dblStep, y, t[i]);
  515. CString s;
  516. s.Format("f(%f) = %frn", t[i], yt);
  517. m_strTargetYi += s;
  518. }
  519. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  520. // 释放内存
  521. delete[] t;
  522. delete[] y;
  523. }
  524. /*
  525. 11
  526. -1.0,-0.95,-0.75,-0.55,-0.3,0.0,0.2,0.45,0.6,0.8,1.0
  527. 0.0384615,0.0424403,0.06639,0.116788,0.307692,1.0,0.5,0.164948,0.1,0.0588236,0.0384615
  528. 2
  529. -0.85,0.15
  530. */
  531. // 光滑不等距插值
  532. void CInterpolaterDlg::OnButton11() 
  533. {
  534. // 获取数据
  535. UpdateData();
  536. double *x = new double[m_nNumNodes];
  537. double *y = new double[m_nNumNodes];
  538. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  539. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  540. // 插值运算
  541. double *t = new double[m_nNumTargetNodes];
  542. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  543. // 显示结果
  544. m_strTargetYi = "";
  545. for (int i=0; i<m_nNumTargetNodes; ++i)
  546. {
  547. double dblCoef[5];
  548. double yt = CInterpolate::GetValueAkima(m_nNumNodes, x, y, t[i], dblCoef);
  549. CString s;
  550. s.Format("f(%f) = %frns0 = %f  s1 = %f  s2 = %f  s3 = %frnrn", 
  551. t[i], yt, dblCoef[0], dblCoef[1], dblCoef[2], dblCoef[3]);
  552. m_strTargetYi += s;
  553. }
  554. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  555. // 释放内存
  556. delete[] t;
  557. delete[] x;
  558. delete[] y;
  559. }
  560. /*
  561. 11
  562. 0.2
  563. -1.0
  564. 0.0384615,0.0588236,0.1,0.2,0.5,1.0,0.5,0.2,0.1,0.0588236,0.0384615
  565. 2
  566. -0.65,0.25
  567. */
  568. // 光滑等距插值
  569. void CInterpolaterDlg::OnButton12() 
  570. {
  571. // 获取数据
  572. UpdateData();
  573. double x0;
  574. double *y = new double[m_nNumNodes];
  575. CInterpolate::GetNodesFromString(m_strXi, 1, &x0, ",");
  576. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  577. // 插值运算
  578. double *t = new double[m_nNumTargetNodes];
  579. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  580. // 显示结果
  581. double dblStep = atof(m_strStepOrBorderCondition);
  582. m_strTargetYi = "";
  583. for (int i=0; i<m_nNumTargetNodes; ++i)
  584. {
  585. double dblCoef[5];
  586. double yt = CInterpolate::GetValueAkima(m_nNumNodes, x0, dblStep, y, t[i], dblCoef);
  587. CString s;
  588. s.Format("f(%f) = %frns0 = %f  s1 = %f  s2 = %f  s3 = %frnrn", 
  589. t[i], yt, dblCoef[0], dblCoef[1], dblCoef[2], dblCoef[3]);
  590. m_strTargetYi += s;
  591. }
  592. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  593. // 释放内存
  594. delete[] t;
  595. delete[] y;
  596. }
  597. /*
  598. 12
  599. 1.86548,-0.046115
  600. 0.52,8.0,17.95,28.65,50.65,104.6,156.6,260.7,364.4,468.0,507.0,520.0
  601. 5.28794,13.84,20.2,24.9,31.1,36.5,36.6,31.0,20.9,7.8,1.5,0.2
  602. 8
  603. 4.0,14.0,30.0,60.0,130.0,230.0,450.0,515.0
  604. */
  605. // 第一种边界条件的三次样条函数插值、微商与积分
  606. void CInterpolaterDlg::OnButton13() 
  607. {
  608. // 获取数据
  609. UpdateData();
  610. double *x = new double[m_nNumNodes];
  611. double *y = new double[m_nNumNodes];
  612. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  613. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  614. double *dy = new double[m_nNumNodes];
  615. double *ddy = new double[m_nNumNodes];
  616. double dblTmp[2];
  617. CInterpolate::GetNodesFromString(m_strStepOrBorderCondition, 2, dblTmp, ",");
  618. dy[0] = dblTmp[0];
  619. dy[m_nNumNodes-1] = dblTmp[1];
  620. // 插值运算
  621. double *t = new double[m_nNumTargetNodes];
  622. double *z = new double[m_nNumTargetNodes];
  623. double *dz = new double[m_nNumTargetNodes];
  624. double *ddz = new double[m_nNumTargetNodes];
  625. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  626. double yt = CInterpolate::GetValueSpline1(m_nNumNodes, x, y, dy, ddy, m_nNumTargetNodes, t, z, dz, ddz);
  627. // 显示结果
  628. m_strTargetYi.Format("积分值 = %frnrn", yt);
  629. m_strTargetYi += "    t[i]t    z[i]t    dz[i]t    ddz[i]rn";
  630. for (int i=0; i<m_nNumTargetNodes; ++i)
  631. {
  632. CString s;
  633. s.Format("%f  %f  %f  %frn", t[i], z[i], dz[i], ddz[i]);
  634. m_strTargetYi += s;
  635. }
  636. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  637. // 释放内存
  638. delete[] t;
  639. delete[] x;
  640. delete[] y;
  641. delete[] dy;
  642. delete[] ddy;
  643. delete[] z;
  644. delete[] dz;
  645. delete[] ddz;
  646. }
  647. /*
  648. 12
  649. -0.279319,0.011156
  650. 0.52,8.0,17.95,28.65,50.65,104.6,156.6,260.7,364.4,468.0,507.0,520.0
  651. 5.28794,13.84,20.2,24.9,31.1,36.5,36.6,31.0,20.9,7.8,1.5,0.2
  652. 8
  653. 4.0,14.0,30.0,60.0,130.0,230.0,450.0,515.0
  654. */
  655. // 第二种边界条件的三次样条函数插值、微商与积分
  656. void CInterpolaterDlg::OnButton14() 
  657. {
  658. // 获取数据
  659. UpdateData();
  660. double *x = new double[m_nNumNodes];
  661. double *y = new double[m_nNumNodes];
  662. CInterpolate::GetNodesFromString(m_strXi, m_nNumNodes, x, ",");
  663. CInterpolate::GetNodesFromString(m_strYi, m_nNumNodes, y, ",");
  664. double *dy = new double[m_nNumNodes];
  665. double *ddy = new double[m_nNumNodes];
  666. double dblTmp[2];
  667. CInterpolate::GetNodesFromString(m_strStepOrBorderCondition, 2, dblTmp, ",");
  668. ddy[0] = dblTmp[0];
  669. ddy[m_nNumNodes-1] = dblTmp[1];
  670. // 插值运算
  671. double *t = new double[m_nNumTargetNodes];
  672. double *z = new double[m_nNumTargetNodes];
  673. double *dz = new double[m_nNumTargetNodes];
  674. double *ddz = new double[m_nNumTargetNodes];
  675. CInterpolate::GetNodesFromString(m_strTargetXi, m_nNumTargetNodes, t, ",");
  676. double yt = CInterpolate::GetValueSpline2(m_nNumNodes, x, y, dy, ddy, m_nNumTargetNodes, t, z, dz, ddz);
  677. // 显示结果
  678. m_strTargetYi.Format("积分值 = %frnrn", yt);
  679. m_strTargetYi += "    t[i]t    z[i]t    dz[i]t    ddz[i]rn";
  680. for (int i=0; i<m_nNumTargetNodes; ++i)
  681. {
  682. CString s;
  683. s.Format("%f  %f  %f  %frn", t[i], z[i], dz[i], ddz[i]);
  684. m_strTargetYi += s;
  685. }
  686. AfxMessageBox(m_strTargetYi, MB_OK|MB_ICONINFORMATION);
  687. // 释放内存
  688. delete[] t;
  689. delete[] x;
  690. delete[] y;
  691. delete[] dy;
  692. delete[] ddy;
  693. delete[] z;
  694. delete[] dz;
  695. delete[] ddz;
  696. }
  697. /*
  698. 37
  699. 36
  700. */
  701. // 第三种边界条件的三次样条函数插值、微商与积分
  702. void CInterpolaterDlg::OnButton15() 
  703. {
  704. // 获取数据
  705. UpdateData();
  706. double x[37], y[37], dy[37], ddy[37];
  707. double t[36], z[36], dz[36], ddz[36];
  708. for (int i=0; i<37; ++i)
  709. {
  710. x[i]=i*6.2831852/36.0;
  711.         y[i]=sin(x[i]);
  712. }
  713. // 插值运算
  714. for (i=0; i<36; ++i)
  715. {
  716.         t[i]=(0.5+i)*6.2831852/36.0;
  717. }
  718. double yt = CInterpolate::GetValueSpline3(37, x, y, dy, ddy, 36, t, z, dz, ddz);
  719. // 显示结果
  720. CString s, ss;
  721. s.Format("积分值 = %frnrn", yt);
  722.     ss.Format(" x(i) y(i)=sin(x) dy(i)=cos(x) ddy(i)=-sin(x)rnrn");
  723. s += ss;
  724.     ss.Format("%6.1f%10.6f%11.6f%12.6frn",x[0],y[0],dy[0],ddy[0]);
  725. s += ss;
  726.     for (i=0; i<36; i++)
  727.     { 
  728. double u=t[i]*36.0/0.62831852;
  729.         ss.Format("%6.1f%10.6f%11.6f%12.6frn",u,z[i],dz[i],ddz[i]);
  730. s += ss;
  731.         u=x[i+1]*36.0/0.62831852;
  732.         int j=i+1;
  733.         ss.Format("%6.1f%10.6f%11.6f%12.6frn",u,y[j],dy[j],ddy[j]);
  734. s += ss;
  735.     }
  736. CSpline3Dlg dlg;
  737. dlg.m_strResult = s;
  738. dlg.DoModal();
  739. }
  740. // 二元三点插值
  741. void CInterpolaterDlg::OnButton16() 
  742. {
  743. int i,j;
  744.     double u,v,w;
  745.     double x[6],y[5],z[30];
  746.     for (i=0;i<=5;i++) 
  747. x[i]=0.2*i;
  748.     for (j=0;j<=4;j++) 
  749. y[j]=0.25*j;
  750.     for (i=0;i<=5;i++)
  751.     {
  752. for (j=0;j<=4;j++)
  753. z[i*5+j]=exp(-(x[i]-y[j]));
  754. }
  755. // 插值运算
  756. CString s, ss;
  757.     u = 0.9; 
  758. v = 0.8;
  759.     w = CInterpolate::GetValueTqip(6, x, 5, y, z, u, v);
  760.     s.Format("z(%f, %f) = %fn",u,v,w);
  761.     u = 0.3; 
  762. v = 0.9;
  763.     w = CInterpolate::GetValueTqip(6, x, 5, y, z, u, v);
  764.     ss.Format("z(%f, %f) = %fn",u,v,w);
  765. s += ss;
  766. // 显示结果
  767. AfxMessageBox(s, MB_OK|MB_ICONINFORMATION);
  768. }
  769. // 二元全区间插值
  770. void CInterpolaterDlg::OnButton17() 
  771. {
  772. int i,j;
  773.     double u,v,w;
  774.     double x[11],y[11],z[121];
  775.     for (i=0;i<=10;i++)
  776.     { 
  777. x[i]=0.1*i; 
  778. y[i]=x[i];
  779. }
  780.     
  781. for (i=0;i<=10;i++)
  782.     {
  783. for (j=0;j<=10;j++)
  784. z[i*11+j]=exp(-(x[i]-y[j]));
  785. }
  786. // 插值运算
  787. CString s, ss;
  788.     u=0.35; 
  789. v=0.65;
  790.     w = CInterpolate::GetValueLagrange2(11, x, 11, y, z, u, v);
  791.     s.Format("z(%f, %f) = %fn",u,v,w);
  792.     u=0.45; 
  793. v=0.55;
  794.     w = CInterpolate::GetValueLagrange2(11, x, 11, y, z, u, v);
  795.     ss.Format("z(%f, %f) = %fn",u,v,w);
  796. s += ss;
  797. // 显示结果
  798. AfxMessageBox(s, MB_OK|MB_ICONINFORMATION);
  799. }