回 帖 发 新 帖 刷新版面

主题:那位高手指点一下啊!

各位高手,帮我回答一个问题吧!
    以下是一道书上的题目。可是却运行不了啊!
     program intege(input,output);
  var
    s1,s2:real;
  function f1(x:real):real;
    begin
      f1:=1/(1+x);
    end;
  function f2(x:real):real;
    begin
      f2:=x*exp(-x*x);
    end;
  [color=FF00FF]function simpson(function f(x:real):real;a,b:real):real;
    const[/color]      n:=40;
    var
      h,s:real;
      i:integer;
    begin
      h:=(b-a)/n;
      s:=f(a)+f(b);
      for i:=1 to n-1 do
        if odd(i)
           then s:=s+4*(a+i*h)
           else s:=s+2*(a+i*h);
      simpson:=h/3*s
        end;
  begin
    s1:=simpson(f1,0,1);
    s2:=simpson(f2,1,2.5);
    writeln('s1=',s1,'s2=',s2)
  end
   运行的时候说那个simpson程序处missmatch!
   能有高手指教指教吗?.(好像是这种不合乎标识符的啊!为什么啊!帮帮忙啊!)

回复列表 (共3个回复)

沙发

有人指点一下吗???

板凳

我给改了改,但好像问题更大了。
(运行时系统出错停止程序)

  program intege(input,output);
  type
    funct=function (x:real):real;
    functype=^funct;

  var
    s1,s2:real;
  function f1(x:real):real;
    begin
      f1:=1/(1+x);
    end;
  function f2(x:real):real;
    begin
      f2:=x*exp(-x*x);
    end;
  function simpson(f:functype;a,b:real):real;
    const      n=40;
    var
      h,s:real;
      i:integer;
    begin
      h:=(b-a)/n;
      s:=f^(a)+f^(b);
      for i:=1 to n-1 do
        if odd(i)
           then s:=s+4*(a+i*h)
           else s:=s+2*(a+i*h);
         simpson:=h/3*s
    end;
  begin
    s1:=simpson(@f1,0,1);
    s2:=simpson(@f2,1,2.5);
    writeln('s1=',s1,'s2=',s2)
  end.

3 楼

不管运行怎样,还是很感谢的!

我来回复

您尚未登录,请登录后再回复。点此登录或注册