资源描述:
《数值分析实验五(分段线性插值)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、《数值分析》实验报告实验编号:实验五课题名称:分段线性插值一、算法介绍给定的函数为f(x)=l/(l+25x*x),-1<=x<=1,将给定区间分成10分,得到11个节点:x[0],x[l],...,x[10],对于[x⑹,x[l]]区间上,插值基函数L[0]=(x-x[l])/(x[0]-x[l]),其他区间上为零。对于[x[i-l],x[i]]区间上,插值基函数L[i]=(x-x[i-l])/(x[i]-x[j-l])o对于(x[i],x[i+l]]上,插值基函数L[i]=(x-x[i+l])
2、/(x[i]-x[i+l]),其中i=l,2,…,10。对于(x[n-l],x(n]]区间上,L[i]=(x-x[10])/(x[9]-x[10]),M他区间上为零。构造得到的多项式g(x)二工f(x[i])*l[i],其中i=0,1,2,…,10。二、程序代码//testView.cpp:implementationoftheCTestViewclass//#include"stdafx.h"#include"test.h"#include"testDoc.h"#include"testView
3、.h"#ifdef.DEBUG#definenewDEBUG.NEW#undefTHIS_FILEstaticcharTHIS_F1LELJ=_FILE_;#endiflllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll//CTestViewIMPLEMENT_DYNCREATE(CTestView,CView)BEGIN_MESSAGE_MAP(CTestView,CView)//{〔AFX_M
4、SG_MAP(CTestView)//NOTE-theClassWizardwilladdandremovemappingmacroshere.//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!〃}}AFX_MSG_MAP//StandardprintingcommandsON_COMMAND(ID_F1LE_PRINT,CView::OnFilePrint)ON_COMMAND(ID_FILE_PRlNT_DIRECT,CView::OnFile
5、Print)ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView::OnFilePrintPreview)END_MESSAGE_MAP()///////〃/////////////////%///////////////////////////////////////////////////CTestViewconstruction/destructionCTestView::CTestView(){//TODO:addconstructioncodehere}CTest
6、View::〜CTestView。{}BOOLCTestView::PreCreateWindow(CREATESTRUCT&cs)//TODO:ModifytheWindowclassorstylesherebymodifying//theCREATESTRUCTcsreturnCView::PreCreateWindow(cs);lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll//CTes
7、tViewdrawingvoidCTestView::OnDraw(CDC*pDC){CTestDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);//TODO:adddrawcodefornativedatahereinti,j,k;doublex,y,p_x,p_y,l,xx[100],f[100],F[100],sum,p_sum;CPenMyPen,*OldPen;pDC->SetViewportOrg(400,400);〃定义坐标原点for(i=-500;
8、i<500;i++){pDC->SetPixel(0,i,RGB(0,0,0));pDC・>SetPixel(i,0,RGB(0,0,0));〃画出坐标}pDC->TextOut(-210,5,,,-ln);pDC->TextOut(196,5;,r,);〃原函数MyPen.CreatePen(PS_SOLID,1,RGB(255,0,0));〃定义画笔颜色OldPen=pDC->SelectObject(&MyPen);x=-l.0,y=1/(1+25*x*x);p_x=x*20