Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2008-12-25
年龄: 37
帖子: 2
声望力: 0 ![]() |
![]()
function result=tintergrate()
clear re_n re_2n; n=1; eps=0.00001; x=linspace(0,1,n+1); h=1/n; y=x./(4+x.^2); re_n=(y(1)+y(n+1))*h/2; for i=2:n re_n=re_n+y(i)*h; end xx=x(1:n)+h/2; y=x./(4+x.^2); re_2n=re_n/2; for i=1:n re_2n=re_2n+y(i)*h/2; end h=h/2; n=1/h; x=linspace(0,1,n+1); while abs(re_2n-re_n)>eps re_n=re_2n; xx=x(1:n)+h; y=x./(4+x.^2); re_2n=re_n/2; for i=1:n re_2n=re_2n+y(i)*h/2; end h=h/2; n=1/h+1; x=linspace(0,1,n+1); end result=re_2n; %the end |
![]() |
![]() |
![]() |
#2 |
高级会员
注册日期: 2008-01-02
帖子: 247
声望力: 22 ![]() |
![]()
function result=tintergrate() %定义函数:函数名tintergrate,函数计算后输出结果为result,没有输入项。
clear re_n re_2n; % 清除workspace中的变量re_n,re_2n。 n=1; eps=0.00001; % n,eps两个常数 x=linspace(0,1,n+1); %生成一个n+1维行向量,该向量元素是0开头、1结尾的等差数列。 h=1/n; y=x./(4+x.^2); %计算向量x对应的函数值向量y re_n=(y(1)+y(n+1))*h/2; for i=2:n re_n=re_n+y(i)*h; %for循环 end xx=x(1:n)+h/2; y=x./(4+x.^2); re_2n=re_n/2; for i=1:n re_2n=re_2n+y(i)*h/2; end h=h/2; n=1/h; x=linspace(0,1,n+1); while abs(re_2n-re_n)>eps %while循环 re_n=re_2n; xx=x(1:n)+h; y=x./(4+x.^2); re_2n=re_n/2; for i=1:n re_2n=re_2n+y(i)*h/2; end h=h/2; n=1/h+1; x=linspace(0,1,n+1); end result=re_2n; %输出结果result. |
![]() |
![]() |
![]() |
#3 |
高级会员
注册日期: 2008-01-02
帖子: 247
声望力: 22 ![]() |
![]()
该程序中的两处 xx 均应为 x。
计算结果为 0.1116。 |
![]() |
![]() |
![]() |
主题工具 | |
显示模式 | |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
请教程序为什么单步可运行,而整体出错?谢谢 | shirleyflh | MATLAB论坛 | 3 | 2009-03-04 19:32 |
[求助]prestd是不是就是归一化数据 | tomsq | MATLAB论坛 | 0 | 2009-01-18 11:46 |
Matlab声音合成和滤波的问题【附代码-自己写的】 | xmuer | MATLAB论坛 | 4 | 2008-12-17 08:58 |
[求助]一个有关用设计的滤波器处理声音信号的问题。 | fujinhai | MATLAB论坛 | 7 | 2008-11-13 09:31 |