您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 汽车理论 > 分段线性插值法教学提纲
分段线性插值法精品文档收集于网络,如有侵权请联系管理员删除《数值分析》实验报告实验序号:实验五实验名称:分段线性插值法1、实验目的:随着插值节点的增加,插值多项式的插值多项式的次数也增加,而对于高次的插值容易带来剧烈的震荡,带来数值的不稳定(Runge现象)。为了既要增加插值的节点,减小插值的区间,以便更好的逼近插值函数,又要不增加插值多项式的次数以减少误差,可采用分段线性插值。2、实验内容:求一个函数(x)用来近似函数f(x),用分段线性插值的方法来求解近似函数(x)并画出近似函数图像及原函数图像。设在区间[a,b]上,给定n+1个插值节点bxxxxan...210和相应的函数值nyyy,...,,10,求一个插值函数)(x,满足以下条件:(1)),...,2,1,0()(njyxjj;(2))(x在每一个小区间[1,jjxx]上是线性函数。对于给定函数11-,2511)(2xxxf。在区间11-,上画出f(x)和分段线性插值函数)(x的函数图像。1.分段线性插值的算法思想:分段线性插值需要在每个插值节点上构造分段线性插值基函数)(xlj,然后再作它们的线性组合。分段线性插值基函数的特点是在对应的插值节点上函数值取1,其它节点上函数值取0。插值基函数如下:精品文档收集于网络,如有侵权请联系管理员删除其它,0,)(101010xxxxxxxxl其它,0,,)(111111jjjjjjjjjjjxxxxxxxxxxxxxxxl其它,0,)(111nnnnnnxxxxxxxxl设在节点a≤x0x1…≤b=f(xi),(i=0,1,2,…,n)求折线函数L(x)满足:(1)L(x)∈C[a,b](2)L(x[i]=y[i])(3)L(x)在每个小区间(x[i],x[i+1])上是线性插值函数¢(x)叫做区间[a,b]上对数据(x[j],y[j])(j=0,1,2,…,n)的分段区间函数。利用一介拉格朗日函数,直接得到线性插值函数为:L(x0)=(x-x[1])/x[0]-x[1];(x[0]≤x≤x[1])L(x0)=0(x[1]≤x≤x[n])分段线性方程的表达式:¢(x)=∑(j=0,..,n)y[j]*L[j](x);3、实验代码://LDlg.cpp:implementationfile//#includestdafx.h#includeL.h#includeLDlg.h#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif精品文档收集于网络,如有侵权请联系管理员删除///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD)精品文档收集于网络,如有侵权请联系管理员删除{//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//Nomessagehandlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CLDlgdialogCLDlg::CLDlg(CWnd*pParent/*=NULL*/):CDialog(CLDlg::IDD,pParent){//{{AFX_DATA_INIT(CLDlg)//NOTE:theClassWizardwilladdmemberinitializationhere//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32精品文档收集于网络,如有侵权请联系管理员删除m_hIcon=AfxGetApp()-LoadIcon(IDR_MAINFRAME);}voidCLDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CLDlg)//NOTE:theClassWizardwilladdDDXandDDVcallshere//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CLDlg,CDialog)//{{AFX_MSG_MAP(CLDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_LARGRI,OnLargri)ON_BN_CLICKED(IDC_BUTTON2,OnButton2)ON_BN_CLICKED(IDC_HERMITE,OnHermite)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CLDlgmessagehandlersBOOLCLDlg::OnInitDialog(){CDialog::OnInitDialog();精品文档收集于网络,如有侵权请联系管理员删除//AddAbout...menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX0xF000);CMenu*pSysMenu=GetSystemMenu(FALSE);if(pSysMenu!=NULL){CStringstrAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu-AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);//SetbigiconSetIcon(m_hIcon,FALSE);//Setsmallicon//TODO:AddextrainitializationherereturnTRUE;//returnTRUEunlessyousetthefocustoacontrol}精品文档收集于网络,如有侵权请联系管理员删除voidCLDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX){CAboutDlgdlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCLDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);//devicecontextforpaintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);//CentericoninclientrectangleintcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON);精品文档收集于网络,如有侵权请联系管理员删除CRectrect;GetClientRect(&rect);intx=(rect.Width()-cxIcon+1)/2;inty=(rect.Height()-cyIcon+1)/2;//Drawtheicondc.DrawIcon(x,y,m_hIcon);}else{CDialog::OnPaint();}}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCLDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCLDlg::OnOK(){intx00=300,y00=350,i,j;doublex;CDC*pDC=GetDC();pDC-SetMapMode(MM_LOMETRIC);精品文档收集于网络,如有侵权请联系管理员删除pDC-SetViewportOrg(x00,y00);//画坐标轴与原函数for(i=-700;i=700;i++){pDC-SetPixel(i,0,RGB(0,0,0));pDC-SetPixel(0,i,RGB(0,0,0));}for(x=-1;x=1;x+=0.001){doublej=400.0/(1+25*x*x);pDC-SetPixel(x*500,j,RGB(255,0,0));}pDC-TextOut(-30,-10,0);pDC-TextOut(-30,430,1);pDC-TextOut(490,-10,1);pDC-TextOut(-490,-10,-1);pDC-MoveTo(-10,680);//x箭头pDC-LineTo(0,700);pDC-MoveTo(0,700);pDC-Line
本文标题:分段线性插值法教学提纲
链接地址:https://www.777doc.com/doc-5989490 .html