程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告_1_第1頁
程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告_1_第2頁
程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告_1_第3頁
程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告_1_第4頁
已閱讀5頁,還剩8頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告學(xué)生實(shí)驗(yàn)報(bào)告院系:測(cè)繪學(xué)院專業(yè)班級(jí):測(cè)繪13級(jí)3班學(xué)號(hào):2013305517學(xué)生姓名:王澤指導(dǎo)教師:郭輝老師2016年05月20日 安徽理工大學(xué)實(shí)驗(yàn)報(bào)告 實(shí)驗(yàn)課程名稱:數(shù)據(jù)結(jié)構(gòu)與軟件開發(fā)上機(jī)實(shí)驗(yàn)開課院系及實(shí)驗(yàn)室:測(cè)繪學(xué)院紅樓二樓機(jī)房實(shí)驗(yàn)1 編程基本知識(shí)練習(xí)實(shí)驗(yàn)?zāi)康模和ㄟ^該實(shí)驗(yàn)課內(nèi)容的練習(xí),學(xué)生應(yīng)掌握vb 編程的基本語法、變量的定義、數(shù)組(動(dòng)態(tài)數(shù)組)的定義、vb 語言中子過程與函數(shù)的定義以及文本文件的讀寫等知識(shí)。實(shí)驗(yàn)內(nèi)容:1)變量的定義動(dòng)態(tài)數(shù)組的定義與應(yīng)用;2)矩陣的加、減、乘運(yùn)算(定義sub()子過程或function()來實(shí)現(xiàn));3)數(shù)據(jù)文件的建立、數(shù)據(jù)的讀取與寫入。實(shí)驗(yàn)步驟

2、:1.編輯界面1.1 打開vb 編程工具,進(jìn)入編程主界面。 1.2 在窗體上新建“讀入數(shù)據(jù)”和“輸出數(shù)據(jù)”兩個(gè)按鈕。1.3 雙擊“窗體”進(jìn)入代碼輸入界面,進(jìn)行代碼編輯。2.用vb 編寫的源代碼2.1 矩陣基本運(yùn)算源碼詳見附錄一。(1)兩矩陣相加(2)兩矩陣相減(3)矩陣轉(zhuǎn)置(4)兩矩陣相乘(5)矩陣求逆2.2 文本文件(本實(shí)驗(yàn)中data.txt)的讀取源代碼(1)建立文本文件并輸入數(shù)據(jù)在桌面上新建一“data.txt” ( 文本文件路徑為c:users whdesktop練習(xí)data.txt”)。輸入以下內(nèi)容:6,7,4,0.005a,35.418b,45.712c,25.270 d,24.6

3、78 在桌面上新建一“result.txt” ( 文本文件路徑為c:users whdesktop練習(xí)result.txt”)。(2)從文本文件中讀數(shù)據(jù)dim linedata as string, m_gaochan as integer,m_pnumber asinteger,m_knpnumber as integer,m as double,k1 as integerlinedata 為存儲(chǔ)文本文件一行信息的字符串變量dim a() as string,h() as doublea()為存儲(chǔ)點(diǎn)名,h()存儲(chǔ)高程open“c:users whdesktop練習(xí)data.txt”for i

4、nput as #1line input #1, linedatak = split(linedata, ,)m_gaochan = val(k(0)m_pnumber = val(k(1)m_knpnumber = val(k(2)m = cdbl(k(3)for k1 = 1 to m_knpnumberline input #1, linedatak = split(linedata, ,)a(k1)= k(0)getstationnumber (a)h(k1) = cdbl(k(1)nextclose #1(3)將讀入點(diǎn)名存儲(chǔ)到點(diǎn)名數(shù)組中,且返回該點(diǎn)名所對(duì)應(yīng)編號(hào)function get

5、stationnumber(name as string)dim i as integerfor i = 1 to m_pnumberif p_name(i) then將待查點(diǎn)名與已經(jīng)存入點(diǎn)名數(shù)組的點(diǎn)比較if p_name(i) = name thengetstationnumber = iexit forend ifelse 待查點(diǎn)是新的點(diǎn)名,將新點(diǎn)名放到p_name 數(shù)組中p_name(i) = namegetstationnumber = iexit forend ifnext iend function(4)從文本文件中寫數(shù)據(jù)(將從data.txt 讀入的數(shù)據(jù),寫入到result.tx

6、t 文件中) open“c:users whdesktop 練習(xí)result.txt” for output as #1outstring = outstring + str(m_gaochan) +, outstring = outstring + str(m_pnumber) + , outstring = outstring + str(m_knpnumber) + ,outstring = outstring + str(m) + vbcrlffor k1 = 1 to m_knpnumberoutstring = outstring +a(k1)+ ,+format(h(k1), #

7、0.000) + vbcrlfnextprint #1, outstring 實(shí)驗(yàn)2 水準(zhǔn)網(wǎng)平差程序設(shè)計(jì) 實(shí)驗(yàn)?zāi)康模和ㄟ^本次實(shí)驗(yàn)的練習(xí),使學(xué)生掌握水準(zhǔn)網(wǎng)平差中近似高程計(jì)算算法、組成誤差方程系數(shù)陣b、組成誤差方程常數(shù)項(xiàng)l及權(quán)陣生成算法。掌握法方程的組建參數(shù)改正值的計(jì)算以及單位權(quán)中誤差的計(jì)算。掌握水準(zhǔn)網(wǎng)平差中輸出高程平差值和高程中誤差、輸出觀測(cè)值及其改正數(shù)與平差值等信息并保存為平差成果文件的方法。實(shí)驗(yàn)內(nèi)容:1)在讀入水準(zhǔn)網(wǎng)數(shù)據(jù)后,進(jìn)行待定點(diǎn)近似坐標(biāo)的計(jì)算;2)基于間接平差的思想,以觀測(cè)的測(cè)段高差為觀測(cè)值,組成誤差方程系數(shù)矩陣b 及常數(shù)項(xiàng)矩陣l;3)基于水準(zhǔn)網(wǎng)平差中定權(quán)的方法(測(cè)段長(zhǎng)或測(cè)站數(shù)定權(quán)),

8、生成權(quán)陣p。4) 利用矩陣的基本運(yùn)算(調(diào)用矩陣運(yùn)算函數(shù)即可)得到法方程系數(shù)矩陣及常數(shù)項(xiàng)矩陣。該實(shí)驗(yàn)的內(nèi)容其實(shí)質(zhì)就是調(diào)用矩陣運(yùn)算函數(shù)。5)熟悉vb 中輸出函數(shù)print 的用法,及控制輸出格式的函數(shù)的用法,如space()、string()6)水準(zhǔn)網(wǎng)平差結(jié)束后,將變量及數(shù)組中的數(shù)據(jù)輸出到平差結(jié)果文件中。實(shí)驗(yàn)步驟:1.讀入水準(zhǔn)網(wǎng)數(shù)據(jù)(1)建立文本文件并輸入數(shù)據(jù)在桌面上新建一“data.txt” ( 文本文件路徑為c:users whdesktop練習(xí)1data.txt”)。輸入以下內(nèi)容:10,7,2,0.001a,0.000f,11.414a,b,73.795,20.4a,d,14.005,18.

9、8a,g,14.167,15.4c,b,71.949,8.9d,b,59.780,14.2c,d,12.159,12.8c,e,15.364,9.8f,e,5.797,19.6g,e,3.044,15.1d,g,0.169,10.0在桌面上新建一“result.txt” ( 文本文件路徑為c:users whdesktop練習(xí)1 out.txt”)。private sub command1_click() (2)讀入水準(zhǔn)網(wǎng)數(shù)據(jù) open c:userswhdesktop練習(xí)1data.txt for input as #1line input #1, linedatak = split(lin

10、edata, ,)m_gaochan = val(k(0)m_pnumber = val(k(1)m_knpnumber = val(k(2)m = cdbl(k(3)redim a(1 to m_knpnumber), h(1 to m_knpnumber)for k1 = 1 to m_knpnumberline input #1, linedatak = split(linedata, ,)a(k1) = k(0)h(k1) = cdbl(k(1)nextredim startp(1 to m_gaochan), endp(1 to m_gaochan), gaocha(1 to m_g

11、aochan), li(1 to m_gaochan)for k2 = 1 to m_gaochanline input #1, linedatak = split(linedata, ,)startp(k2) = k(0)endp(k2) = k(1)gaocha(k2) = cdbl(k(2)li(k2) = cdbl(k(3)nextclose #1end sub2.編輯界面打開vb 編程工具,進(jìn)入編程主界面。在窗體上利用控件新建“載入數(shù)據(jù)”、“開始計(jì)算”、“導(dǎo)出結(jié)果”、“清空”四個(gè)按鈕和一個(gè)文本框。 3.定義相應(yīng)變量、數(shù)組和實(shí)現(xiàn)各功能的函數(shù)(過程)詳見附錄二(1)水準(zhǔn)網(wǎng)中近似坐標(biāo)計(jì)算(

12、2)生成誤差方程系數(shù)矩陣b 及常數(shù)項(xiàng)矩陣l(3)生成權(quán)陣p(4)殘差及中誤差計(jì)算函數(shù)(5)組成法方程及平差計(jì)算(6)平差結(jié)果輸出 附件1 矩陣基本運(yùn)算源碼 (1)兩矩陣相加private function msum(m as integer, n as integer, matrixsum() as double, matrix1() as double, matrix2() as double)矩陣求和函數(shù)dim i1 as integer, i2 as integerredim matrixsum(1 to m, 1 to n)for i1 = 1 to mfor i2 = 1 to nm

13、atrixsum(i1, i2) = matrix1(i1, i2) + matrix2(i1, i2)next i2next i1end function(2)兩矩陣相減function mminus(m as integer, n as integer, matrixminus() asdouble, matrix1() as double, matrix2() as double)矩陣求差函數(shù)dim i1 as integer, i2 as integerredim matrixminus(1 to m, 1 to n)for i1 = 1 to mfor i2 = 1 to nmatr

14、ixminus(i1, i2) = matrix1(i1, i2) - matrix2(i1, i2)next i2next i1end function(3)矩陣轉(zhuǎn)置function mchange(m as integer, n as integer, matrixchange() as double, matrix1() as double)矩陣轉(zhuǎn)置函數(shù)matrix1()需轉(zhuǎn)置的矩陣,matrixchange()為轉(zhuǎn)置后的矩陣dim i1 as integer, i2 as integerredim matrixchange(1 to n, 1 to m) 動(dòng)態(tài)分配用來存儲(chǔ)轉(zhuǎn)置后的矩陣f

15、or i1 = 1 to mfor i2 = 1 to nmatrixchange(i2, i1) = matrix1(i1, i2)next i2next i1end function(4)兩矩陣相乘矩陣相乘函數(shù),matrixmultiply()為存儲(chǔ)ab 后的矩陣,matrix1()為a矩陣,matrix2()為b 矩陣,注意矩陣相乘的順序mi 為行,ni 為列,i=1,2function mmultiply(m1 as integer, n1 as integer, m2 as integer,n2 as integer, matrixmultiply() as double, matr

16、ix1() as double,matrix2() as double) dim i1 as integer, i2 as integer, i3 as integer if n1 m2 thenmsgbox 兩矩陣不能相乘,請(qǐng)檢查!, vbokcancel + vbcritical + vbdefaultbutton1 exit functionend ifredim matrixmultiply(1 to m1, 1 to n2)for i1 = 1 to m1for i2 = 1 to n2matrixmultiply(i1, i2) = 0for i3 = 1 to n1matrixm

17、ultiply(i1, i2) = matrixmultiply(i1, i2) +matrix1(i1, i3) * matrix2(i3, i2)next i3next i2next i1end function(5)矩陣求逆function mrinv(n as integer, mtxa() as double) as boolean功能:實(shí)矩陣求逆的全選主元高斯約當(dāng)法參數(shù):n - integer 型變量,矩陣的階數(shù)mtxa - double 型二維數(shù)組,體積為n x n。存放原矩陣a;返回時(shí)存放其逆矩陣a-1。返回值:boolean型,失敗為false,成功為trueredim ni

18、s(n) as integer, njs(n) as integerdim i as integer, j as integer, k as integerdim d as double, p as double全選主元,消元for k = 1 to nd = 0#for i = k to nfor j = k to np = abs(mtxa(i, j)if (p d) thend = pnis(k) = injs(k) = jend ifnext jnext i求解失敗if (d + 1# = 1#) thenmrinv = falseexit functionend if if (nis(k) k) then for j = 1 to np = mtxa(k, j)mtxa(k, j) = mtxa(nis(k), j)mtxa(nis(k), j) = pnext jend ifif (njs

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論