




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上例1 設(shè)為定義在0,3上的函數(shù),有下列函數(shù)值表:xi0123yi00.521.5且,試求區(qū)間0,3上滿足上述條件的三次樣條插值函數(shù)本算法求解出的三次樣條插值函數(shù)將寫成三彎矩方程的形式:其中,方程中的系數(shù),將由Matlab代碼中的變量Coefs_1、Coefs_2、Coefs_3以及Coefs_4的值求出。以下為Matlab代碼:%=% 本段代碼解決作業(yè)題的例1%=clear allclc % 自變量x與因變量y,兩個(gè)邊界條件的取值IndVar = 0, 1, 2, 3;DepVar = 0, 0.5, 2, 1.5; LeftBoun = 0.2;RightBoun
2、= -1; % 區(qū)間長度向量,其各元素為自變量各段的長度h = zeros(1, length(IndVar) - 1);for i = 1 : length(IndVar) - 1 h(i) = IndVar(i + 1) - IndVar(i);end % 為向量賦值mu = zeros(1, length(h);for i = 1 : length(mu) - 1 mu(i) = h(i) / (h(i) + h(i + 1);endmu(i + 1) = 1; % 為向量賦值lambda = zeros(1, length(h);lambda(1) = 1;for i = 2 : le
3、ngth(lambda) lambda(i) = h(i) / (h(i - 1) + h(i);end % 為向量d賦值d = zeros(1, length(h) + 1);d(1) = 6 * ( (DepVar(2) - DepVar(1) ) / ( IndVar(2) - IndVar(1) ) - LeftBoun) / h(1);for i = 2 : length(h) a = ( DepVar(i) - DepVar(i - 1) ) / ( IndVar(i) - IndVar(i - 1) ); b = ( DepVar(i + 1) - DepVar(i) ) / (
4、 IndVar(i + 1) - IndVar(i) ); c = (b - a) / ( IndVar(i + 1) - IndVar(i - 1) ); d(i) = 6 * c;endd(i + 1) = 6 *( RightBoun - ( DepVar(i + 1) - DepVar(i) ) / ( IndVar(i + 1) - IndVar(i) ) ) / h(i); % 為矩陣A賦值% 將主對角線上的元素全部置為2A = zeros( length(d), length(d) );for i = 1 : length(d) A(i, i) = 2;end% 將向量的各元素賦
5、給主對角線右側(cè)第一條對角線for i = 1 : length(d) - 1 A(i, i + 1) = lambda(i);end% 將向量d的各元素賦給主對角線左側(cè)第一條對角線for i = 1 : length(d) - 1 A(i + 1, i) = mu(i);end % 求解向量MM =A d' % 求解每一段曲線的函數(shù)表達(dá)式 for i = 1 : length(h) Coefs_1 = M(i) / (6 * h(i); Part_1 = conv( Coefs_1, . conv( -1, IndVar(i + 1), . conv( -1, IndVar(i + 1
6、), -1, IndVar(i + 1) ) ) ); S_1 = polyval (Part_1, IndVar(i) : 0.01 : IndVar(i + 1); Coefs_2 = M(i + 1)/(6 * h(i); Part_2 = conv( Coefs_2, . conv( 1, -IndVar(i), . conv( 1, -IndVar(i), 1, -IndVar(i) ) ) ); S_2 = polyval (Part_2, IndVar(i) : 0.01 : IndVar(i + 1); Coefs_3 = (DepVar(i) - M(i) * h(i)2 /
7、 6) / h(i); Part_3 = conv(Coefs_3, -1, IndVar(i + 1); S_3 = polyval (Part_3, IndVar(i) : 0.01 : IndVar(i + 1); Coefs_4 = (DepVar(i + 1) - M(i + 1) * h(i)2 / 6) / h(i); Part_4 = conv(Coefs_4, 1, -IndVar(i); S_4 = polyval (Part_4, IndVar(i) : 0.01 : IndVar(i + 1); S = S_1 + S_2 + S_3 + S_4; plot (IndV
8、ar(i) : 0.01 : IndVar(i + 1), S, 'LineWidth', 1.25) % 在樣條插值曲線的相應(yīng)位置標(biāo)注該段曲線的函數(shù)表達(dá)式 text(i - 1, polyval(Part_1, 3), . 'itS', num2str(i), '(x)=', num2str(Coefs_1), '(', num2str( IndVar(i + 1) ), '-x)3+', . num2str(Coefs_2), '(x-', num2str( IndVar(i) ), '
9、)3+', num2str(Coefs_3), . '(', num2str( IndVar(i + 1) ), '-x)+', num2str(Coefs_4), '(x-', num2str( IndVar(i) ), ')', . 'FontName', 'Times New Roman', 'FontSize', 14) hold onend % 過x=1和x=2兩個(gè)橫軸點(diǎn)作垂線 %line(1, 1, 2.5, -0.5, 'LineStyle',
10、'-');line(2, 2, 2.5, -0.5, 'LineStyle', '-'); % 為x軸和y軸添加標(biāo)注xlabel( 'itx', 'FontName', 'Times New Roman', . 'FontSize', 14, 'FontWeight', 'bold');ylabel( 'its(x)', 'FontName', 'Times New Roman', .'Rotat
11、ion', 0, 'FontSize', 14, 'FontWeight', 'bold');最終,三次樣條插值函數(shù)s(x)表達(dá)式為:曲線的圖像如圖所示:專心-專注-專業(yè)例2 已知函數(shù)值表:xi1245yi1342試求在區(qū)間1,5上滿足上述函數(shù)表所給出的插值條件的三次自然樣條插值函數(shù)本算法求解出的三次樣條插值函數(shù)將寫成三彎矩方程的形式:其中,方程中的系數(shù),將由Matlab代碼中的變量Coefs_1、Coefs_2、Coefs_3以及Coefs_4的值求出。以下為Matlab代碼:%=% 本段代碼解決作業(yè)題的例2%=clear allclc
12、 % 自變量x與因變量y的取值IndVar = 1, 2, 4, 5;DepVar = 1, 3, 4, 2; % 區(qū)間長度向量,其各元素為自變量各段的長度h = zeros(1, length(IndVar) - 1);for i = 1 : length(IndVar) - 1 h(i) = IndVar(i + 1) - IndVar(i);end % 為向量賦值mu = zeros(1, length(h);for i = 1 : length(mu) - 1 mu(i) = h(i) / (h(i) + h(i + 1);endmu(i + 1) = 0; % 為向量賦值lambda
13、 = zeros(1, length(h);lambda(1) = 0;for i = 2 : length(lambda) lambda(i) = h(i) / (h(i - 1) + h(i);end % 為向量d賦值d = zeros(1, length(h) + 1);d(1) = 0;for i = 2 : length(h) a = ( DepVar(i) - DepVar(i - 1) ) / ( IndVar(i) - IndVar(i - 1) ); b = ( DepVar(i + 1) - DepVar(i) ) / ( IndVar(i + 1) - IndVar(i)
14、 ); c = (b - a) / ( IndVar(i + 1) - IndVar(i - 1) ); d(i) = 6 * c;endd(i + 1) = 0; % 為矩陣A賦值% 將主對角線上的元素全部置為2A = zeros( length(d), length(d) );for i = 1 : length(d) A(i, i) = 2;end% 將向量的各元素賦給主對角線右側(cè)第一條對角線for i = 1 : length(d) - 1 A(i, i + 1) = lambda(i);end% 將向量d的各元素賦給主對角線左側(cè)第一條對角線for i = 1 : length(d)
15、- 1 A(i + 1, i) = mu(i);end % 求解向量MM =A d' % 求解每一段曲線的函數(shù)表達(dá)式 for i = 1 : length(h) Coefs_1 = M(i) / (6 * h(i); Part_1 = conv( Coefs_1, . conv( -1, IndVar(i + 1), . conv( -1, IndVar(i + 1), -1, IndVar(i + 1) ) ) ); S_1 = polyval (Part_1, IndVar(i) : 0.01 : IndVar(i + 1); Coefs_2 = M(i + 1)/(6 * h(i
16、); Part_2 = conv( Coefs_2, . conv( 1, -IndVar(i), . conv( 1, -IndVar(i), 1, -IndVar(i) ) ) ); S_2 = polyval (Part_2, IndVar(i) : 0.01 : IndVar(i + 1); Coefs_3 = (DepVar(i) - M(i) * h(i)2 / 6) / h(i); Part_3 = conv(Coefs_3, -1, IndVar(i + 1); S_3 = polyval (Part_3, IndVar(i) : 0.01 : IndVar(i + 1); C
17、oefs_4 = (DepVar(i + 1) - M(i + 1) * h(i)2 / 6) / h(i); Part_4 = conv(Coefs_4, 1, -IndVar(i); S_4 = polyval (Part_4, IndVar(i) : 0.01 : IndVar(i + 1); S = S_1 + S_2 + S_3 + S_4; plot (IndVar(i) : 0.01 : IndVar(i + 1), S, 'LineWidth', 1.25) % 在樣條插值曲線的相應(yīng)位置標(biāo)注該段曲線的函數(shù)表達(dá)式 text(i, polyval(Part_1, 5
18、), . 'itS', num2str(i), '(x)=', num2str(Coefs_1), '(', num2str( IndVar(i + 1) ), '-x)3+', . num2str(Coefs_2), '(x-', num2str( IndVar(i) ), ')3+', num2str(Coefs_3), . '(', num2str( IndVar(i + 1) ), '-x)+', num2str(Coefs_4), '(x-'
19、, num2str( IndVar(i) ), ')', . 'FontName', 'Times New Roman', 'FontSize', 14) hold onend % 過x=2和x=4兩個(gè)橫軸點(diǎn)作垂線 %line(2, 2, 4.5, 0.5, 'LineStyle', '-');line(4, 4, 4.5, 0.5, 'LineStyle', '-'); % 為x軸和y軸添加標(biāo)注xlabel( 'itx', 'FontName
20、', 'Times New Roman', . 'FontSize', 14, 'FontWeight', 'bold');ylabel( 'its(x)', 'FontName', 'Times New Roman', .'Rotation', 0, 'FontSize', 14, 'FontWeight', 'bold');最終,三次自然樣條插值函數(shù)s(x)表達(dá)式為:曲線的圖像如圖所示:例3 課后習(xí)題與思考題
21、第7題xi0.250.300.390.450.53yi0.50000.54770.62450.67080.7280試求在區(qū)間0.25,0.53上滿足上述函數(shù)表所給出的插值條件的三次自然樣條插值函數(shù)s(x)求解出的三次樣條插值函數(shù)將寫成三彎矩方程的形式:本題采用和例2基本相同的Matlab代碼,只改變初始條件。最終,三次自然樣條插值函數(shù)s(x)表達(dá)式為:曲線的圖像如圖所示:例4 課后習(xí)題與思考題第6題求的二次插值式,使:并計(jì)算的近似值并估計(jì)誤差。本題采用拉格朗日二次插值法進(jìn)行計(jì)算:以下為Matlab代碼:%=% 本段代碼解決課本第2章習(xí)題與思考題第6題%=clear allclc % 自變量x與
22、因變量y的取值IndVar = 100, 121, 144;DepVar = 10, 11, 12; % 構(gòu)造拉格朗日插值函數(shù)Coefs_1 = DepVar(1) /. ( ( IndVar(1) - IndVar(2) ) * ( IndVar(1) - IndVar(3) ) );Part_1 = conv( Coefs_1,. conv( 1, -IndVar(2), 1, -IndVar(3) ) );f_1 = polyval (Part_1, IndVar(1) : 0.01 : IndVar(3); Coefs_2 = DepVar(2) /. ( ( IndVar(2) -
23、IndVar(1) ) * ( IndVar(2) - IndVar(3) ) );Part_2 = conv( Coefs_2,. conv( 1, -IndVar(1), 1, -IndVar(3) ) );f_2 = polyval (Part_2, IndVar(1) : 0.01 : IndVar(3); Coefs_3 = DepVar(3) /. ( ( IndVar(3) - IndVar(1) ) * ( IndVar(3) - IndVar(2) ) );Part_3 = conv( Coefs_3,. conv( 1, -IndVar(1), 1, -IndVar(2)
24、) );f_3 = polyval (Part_3, IndVar(1) : 0.01 : IndVar(3); f = f_1 + f_2 + f_3; plot (IndVar(1) : 0.01 : IndVar(3), f, 'LineWidth', 1.25); % 在樣條插值曲線的相應(yīng)位置標(biāo)注該段曲線的函數(shù)表達(dá)式text(110, polyval(Part_1, 110) + polyval(Part_2, 110) + polyval(Part_3, 110), .'itP_2(x)=', num2str(Coefs_1), '(x-', num2str(IndVar(2), .')(x-', num2str(IndVar(3), ')+', num2str(Coefs_2),
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年演講與口才考試試題及答案
- 2025年循環(huán)經(jīng)濟(jì)與環(huán)境保護(hù)基礎(chǔ)知識考試卷及答案
- 2025年融資與投資管理考試題及答案
- 2025年民法學(xué)考試試題及答案
- 2025年經(jīng)濟(jì)學(xué)學(xué)位論文答辯試題及答案
- 2025年環(huán)境工程專業(yè)考核試卷及答案
- 2025年廣告設(shè)計(jì)師考試模擬題及答案
- 我的同學(xué)700字10篇
- 中考英語滿分創(chuàng)建和諧校園14篇范文
- 人文素養(yǎng)啟蒙課程-初中自然歷史研究教案
- 項(xiàng)目勞務(wù)招投標(biāo)管理辦法
- 《無人機(jī)飛行操控技術(shù)》項(xiàng)目5 無人直升機(jī)飛行操控
- 國開(陜西)2024年秋《刑法學(xué)#》形考作業(yè)1-4答案
- 行政職業(yè)能力測驗(yàn)公務(wù)員考試行測試卷及答案指導(dǎo)(2025年)
- 2024年式電動出租車租賃合同
- 賓館轉(zhuǎn)讓協(xié)議范本
- 代理人招聘協(xié)議范例
- 2024年黑龍江、吉林、遼寧高考生物試卷(含答案解析)
- 中醫(yī)疾病癥狀評分總表(終極版)
- 實(shí)驗(yàn)室安全教育課件
- 2024年湖北省中考語文試卷二套合卷附答案
評論
0/150
提交評論