
这个matlab程序运行没反应是怎么回事?在线急等 5
functionI=trapezia(a,b,eps)h=b-a;T1=h*(f(a)+f(b))/2;while1u=h/2;x=a+u;H=0;whilex<bH=H...
function I=trapezia(a,b,eps)
h=b-a;
T1=h*(f(a)+f(b))/2;
while 1
u=h/2;
x=a+u;
H=0;
while x<b
H=H+f(x);
x=x+h;
end
T2=(T1+h*H)/2;
if abs(T2-T1)<eps
I=T2+(T2-T1)/3;
break
end
h=u;
T1=T2;
end
function c=dichotomy(a,b,eps)
aa=a;
bb=b;
I=trapezia(a,b,eps);
err=b-a;
while err>=eps
c=(a+b)/2;
if I-f(c)*(bb-aa)==0
break
end
if(I-f(a)*(bb-aa)* (I-f(c)*(bb-aa))<0)
b=c;
else
a=c;
end
err=b-a;
end
a=input('a=');
b=input('b=');
eps=input('eps=')
c=dichotomy(a,b,eps);
fill([a,a,b,b],[0,f(c),f(c),0],'y')
hold on
x=a:0.001:b;
y=f(x);
plot(x,y,'b')
plot([c,c],[0,f(c)],'r:')
string=['c=',num2str(c)];
text(c,0.03,string)
title('定积分中的几何意义')
hold off
显示出来是这个错误 不知道什么意思
Error in ==> C:\MATLAB6p5\work\trapezia.m
On line 2 ==> h=b-a; 展开
h=b-a;
T1=h*(f(a)+f(b))/2;
while 1
u=h/2;
x=a+u;
H=0;
while x<b
H=H+f(x);
x=x+h;
end
T2=(T1+h*H)/2;
if abs(T2-T1)<eps
I=T2+(T2-T1)/3;
break
end
h=u;
T1=T2;
end
function c=dichotomy(a,b,eps)
aa=a;
bb=b;
I=trapezia(a,b,eps);
err=b-a;
while err>=eps
c=(a+b)/2;
if I-f(c)*(bb-aa)==0
break
end
if(I-f(a)*(bb-aa)* (I-f(c)*(bb-aa))<0)
b=c;
else
a=c;
end
err=b-a;
end
a=input('a=');
b=input('b=');
eps=input('eps=')
c=dichotomy(a,b,eps);
fill([a,a,b,b],[0,f(c),f(c),0],'y')
hold on
x=a:0.001:b;
y=f(x);
plot(x,y,'b')
plot([c,c],[0,f(c)],'r:')
string=['c=',num2str(c)];
text(c,0.03,string)
title('定积分中的几何意义')
hold off
显示出来是这个错误 不知道什么意思
Error in ==> C:\MATLAB6p5\work\trapezia.m
On line 2 ==> h=b-a; 展开
2个回答
展开全部
这个程序运行肯定是没反应的 这是一个函数脚本
你要用调用函数的方式,
function I=trapezia(a,b,eps)函数中有三个参数 必须个a b eps 赋值
比方说:我让 a=8 b=9 esp=0.001
然后我再命令窗口输入命令:result=trapezia(8,9,0.01) 回车
(当然你前提是这个函数文件在matlab当前路径)
你要用调用函数的方式,
function I=trapezia(a,b,eps)函数中有三个参数 必须个a b eps 赋值
比方说:我让 a=8 b=9 esp=0.001
然后我再命令窗口输入命令:result=trapezia(8,9,0.01) 回车
(当然你前提是这个函数文件在matlab当前路径)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |