| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1098 人关注过本帖
标题:期末作业 希望大家帮个忙 是龙贝格求积的 大家看下啊
只看楼主 加入收藏
wisefox
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-5-21
收藏
 问题点数:0 回复次数:2 
期末作业 希望大家帮个忙 是龙贝格求积的 大家看下啊

下面是同学发给我的m文件
我的matlab去年没学 所以不怎么会 那位高手可不可以帮个忙 把他改成C语言的
在线等啊!!!!!焦急啊 马上要交了

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
% introductory 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);

搜索更多相关主题的帖子: 龙贝格求积 作业 table The romberg 
2007-07-06 19:49
mikle
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-4-9
收藏
得分:0 
可有偿提供代码解决方案

专业matlab源码工作室,有偿提供各类算法程序##email:fshguo@期待与您合作
2007-07-07 14:44
静夜嘶
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2007-7-2
收藏
得分:0 
哈哈,又是来要作业的

2007-07-08 03:03
快速回复:期末作业 希望大家帮个忙 是龙贝格求积的 大家看下啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019367 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved