導航:首頁 > 源碼編譯 > 龍貝格演算法matlab

龍貝格演算法matlab

發布時間:2023-09-17 03:33:16

⑴ 用龍貝格法求積分

先用另外2種方法。

format long
%【1】精確值。符號積分
it=int('(2/sqrt(pi))*exp(-x)',0,1)
Accurate=eval(it)
y=inline('(2/sqrt(pi))*exp(-x)')
%【2】Simpson方法
Simpson=quad(y,0,1)
delta=Simpson-Accurate

結果:
Accurate = 0.713271669674918

y = Inline function:
y(x) = (2/sqrt(pi))*exp(-x)

Simpson = 0.713271671228492

delta = 1.553574158208448e-009

【3】從網上找到一個,存為romberg.m
%=================
function R = romberg(f, a, b, n)
format long
% ROMBERG -- Compute Romberg table integral approximation.
%
% SYNOPSIS:
% R = romberg(f, a, b, n)
%
% DESCRIPTION:
% Computes the complete Romberg table approximation to the integral
%
% / b
% I = | f(x) dx
% / a
%
% PARAMETERS:
% f - The integrand. Assumed to be a function callable as
% y = f(x)
% with `x' in [a, b].
% a - Left integration interval endpoint.
% b - Right integration interval endpoint.
% n - Maximum level in Romberg table.
%
% RETURNS:
% R - Romberg table. Represented as an (n+1)-by-(n+1) lower
% triangular matrix of integral approximations.
%
% SEE ALSO:
% TRAPZ, QUAD, QUADL.

% NOTE: all indices adjusted for MATLAB's one-based indexing scheme.

% Pre-allocate the Romberg table. Avoids subsequent re-allocation which
% is often very costly.
R = zeros([n + 1, n + 1]);

% Initial approximation. Single interval trapezoidal rule.
R(0+1, 0+1) = (b - a) / 2 * (feval(f, a) + feval(f, b));

% First column of Romberg table. Increasingly accurate trapezoidal
% approximations.
for i = 1 : n,
h = (b - a) / 2^i;

s = 0;
for k = 1 : 2^(i-1),
s = s + feval(f, a + (2*k - 1)*h);
end

R(i+1, 0+1) = R(i-1+1, 0+1)/2 + h*s;
end

% Richardson extrapolation gives remainder of Romberg table.
%
% Note: The table is computed by columns rather than the more
% traditional row version. The reason is that this prevents frequent
% (and needless) re-computation of the `fac' quantity.
%
% Moreover, MATLAB matrices internally use ``column major'' ordering so
% this version is less harmful to computer memory cache systems. This
% reason is an implementational detail, though, and less important in
% introctory courses such as MA2501.
for j = 1 : n,
fac = 1 / (4^j - 1);
for m = j : n,
R(m+1, j+1) = R(m+1, j-1+1) + fac*(R(m+1, j-1+1) - R(m-1+1, j-1+1));
end
end

function ff=f(x)
ff=2/sqrt(pi)*exp(-x);
%=================

運行:
>> R=romberg('f', 0, 1, 5)

R =

0.771743332258054 0 0 0 0 0
0.728069946441243 0.713512151168973 0 0 0 0
0.716982762290904 0.713287034240791 0.713272026445579 0 0 0
0.714200167058928 0.713272635314936 0.713271675386546 0.713271669814180 0 0
0.713503839348432 0.713271730111600 0.713271669764711 0.713271669675476 0.713271669674932 0
0.713329714927254 0.713271673453528 0.713271669676323 0.713271669674920 0.713271669674918 0.713271669674918

⑵ 用matlab,龍貝格演算法計算∫(0到1)[x/(4+x²)]dx的近似值。 求程序代碼!!!

%龍貝格求積演算法function I=romberg(a,b)h=b-a;T(1)=h/2*(fun(a)+fun(b));m=1;while 1 h=h/2; S(1)=1/2*T(1)+h*sumf(2^(m-1),a,h); for j=1:m S(j+1)=S(j)+(S(j)-T(j))/(4^j-1); end if abs(S(m+1)-T(m))<1e-6 break; end T=S;m=m+1;endI=S(m+1);end
function f=sumf(m,a,h)for j=1:m y(j)=fun(a+(2*j-1)*h);endf=sum(y);end
function f=fun(x)f=x/(4+x^2);end結果:
>> I=romberg(0,1)
I =
0.111571775646293
>>

⑶ 龍貝格演算法 橢圓周長 請幫忙修改一下程序~!!!!!!

1、在for(i=1;i<=pow(2,k-1);i++)之前加t=0;否則t重復累加;

2、for(i=1;i<pow(2,k-1);i++)改成for(i=1;i<=pow(2,k-1);i++),i需執行到i=pow(2,k-1);

3、調換for(k=0;k<20;k++)

{

for(m=1;m<4;m++)

的順序,改為

for(m=1;m<4;m++)

{

for(k=0;k<21-m;k++)否則在算T[k][m]時,T[k+1][m-1]還未知

4、並把k<20改成k<21-m;因為辛普森序列比梯形序列少一項,科茨序列比辛普森序列少一項,龍貝格序列比科茨序列少一項

話說哦。k取20是不太大了點啊,2的20次方可是很大的咯。其實k取6應該就能達到精度要求了吧。

閱讀全文

與龍貝格演算法matlab相關的資料

熱點內容
加密晶元的計算方法 瀏覽:187
手機存儲為什麼找不到微信文件夾 瀏覽:695
msf埠遷移命令 瀏覽:880
工商app積分怎麼查詢 瀏覽:143
鐵路app怎麼買火車票 瀏覽:309
移魅族除的app怎麼添加 瀏覽:240
兔籠子大號加密 瀏覽:171
單片機程序燒錄操作成功 瀏覽:878
指標高拋低吸點位源碼 瀏覽:205
25匹壓縮機銅管 瀏覽:570
單片機單燈左移05 瀏覽:150
買伺服器練手什麼配置 瀏覽:783
伺服器被毀該怎麼辦 瀏覽:939
python私有庫 瀏覽:514
Python有中文嗎 瀏覽:736
麥塊的伺服器為什麼都進不去 瀏覽:474
新買的伺服器如何打開 瀏覽:35
安卓軟體游戲怎麼開發 瀏覽:319
用撲克擺愛心解壓神器怎麼擺 瀏覽:70
松下製冷壓縮機 瀏覽:275