【问题标题】:I am trying to write a program of trapezoidal rule using maple我正在尝试使用枫编写梯形规则程序
【发布时间】:2016-05-10 10:29:26
【问题描述】:

我正在尝试使用 maple 编写一个梯形规则的程序,我将发布我的代码,但问题是当我阅读这篇文章时,我发现很难编写所有的数值示例,有人可以帮助我吗?

此网址上的文章:http://www.cs.technion.ac.il/~asidi/Sidi_Journal_Papers/P097_JCAM.sinpq.trans.pdf 我枫的代码:

with(linalg); with(LinearAlgebra); with(plots); with(MTM); 
a := 0; b := 1; p := 20; 
k := 1; R := vector(p); 
f := proc (x) options operator, arrow; x*(1-x)/(1+x) end proc;
Uex := int(f(x), x = a .. b); 
Uex := evalf(Uex);
for N to p do 
    h := (b-a)/N;
    U[N] := (f(a)+f(b))*(1/2);
    for j to N-1 do
        U[N] := U[N]+f(a+j*(b-a)/N)
    end do;
    U[N] := h.U[N]
end do;
for N to p do
    R[N] := -evalf(log(abs(Uex-U[N]))/log(10));
    print(N, evalf(Uex-U[N]))
end do;
plot(f); listplot(R)

【问题讨论】:

    标签: algorithm numerical maple


    【解决方案1】:

    试试这个:

    a:= 0: b:= 1: p:= 20: 
    R:= Vector(p): H:= Vector(p): 
    f:= x-> x*(1-x)/(1+x);
    Uex:= int(f(x), x= a..b); 
    for n to p do
        N:= 2^n; 
        h:= (b-a)/N;
        H[n]:= h;
        R[n]:= evalhf(abs(Uex-h*((f(a)+f(b))/2 + add(f(a+j*h), j= 1..N-1))))    
    end do:
    unassign('h');
    err = Statistics:-PowerFit(H,R,h);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      相关资源
      最近更新 更多