maple中循环语句使用

自己做了一个简单的程序,可是循环语句,没有结果输出。这是为什么呢?> restart; SWCNT;> E := 3.3*10^12;upsilon := .27; rho := 2.3*10^3;h := 3.407*10^(-10); `ϕ` := evalf((1-upsilon^2)/(E*h)); beta := evalf(h^2/(12*r^2)); k := .6;G := .4*10^12;ES := 5.1882; tau := .9108;> K := 20; m := 1; pl := 0;> w := proc (x, t, `ϖ`) options operator, arrow; sin(m*Pi*x/L)*sin(`ϖ`*t) end proc; `ϕ` := proc (x, t, `ϖ`) options operator, arrow; cos(m*Pi*x/L)*sin(`ϖ`*t) end proc;> > r:=0.25*10^(-9):xx:=0.05*10^(-9):for i from 1 by 1 to 15 do r:=r+i*xx: HH:=evalf(4*tau*r):L:=K*2*r: p:=pl*L: aa:=evalf(Pi*((r+(h)/(2))^(2)-(r-(h)/(2))^(2))): bb:=evalf(Pi/(4)*((r+(h)/(2))^(4)-(r-(h)/(2))^(4))):QQ:=simplify(((E*bb+Pi*ES*r^(3))*D[1$2](`ϕ`)(x,t,`ϖ`)-k*G*aa*`ϕ`(x, t,`ϖ`)-rho*bb*D[2$2](`ϕ`)(x,t,`ϖ`)+p^(2)*k*G*aa*D[1$2](`ϕ`)(x,t,`ϖ`)+p^(2)*rho[]*bb*D[1$2,2$2](`ϕ`)(x,t,`ϖ`))/(cos((m*Pi)/(L)*x)*sin(`ϖ`*t))): RR:=simplify((k*G*aa*D[1$1](w)(x,t,`ϖ`)-p^(2)*k*G*aa*D[1$3](w)(x,t,`ϖ`))/(cos((m*Pi)/(L)*x)*sin(`ϖ`*t))): YY:=simplify((-k*G*aa*D[1$1](`ϕ`)(x,t,`ϖ`))/(sin((m*Pi)/(L)*x)*sin(`ϖ`*t))): ZZ:=simplify((HH*D[1$2](w)(x,t,`ϖ`)+k*G*aa*D[1$2](w)(x,t,`ϖ`)-rho*aa*D[2$2](w)(x,t,`ϖ`))/(sin((m*Pi)/(L)*x)*sin(`ϖ`*t))): with(LinearAlgebra):M:=Matrix(2,[[QQ,RR],[YY,ZZ]]):f:=(`ϖ`)->Determinant(M):solve(f(`ϖ`),`ϖ`);end do ;按照 greatdju说的 将with(LinearAlgebra):提前了,还是没有预期的效果。大师说错误很多,能不能麻烦您再指点一二。我把程序图上传了,小妹在这里多谢了。
2026年09月25日 11:37
有3个网友回答
网友(1):

把with(LinearAlgebra):拉到循环外面,放到最前面(restart后面),应该就能运行出结果了。

怎么说呢,很多地方都有错误,比如

f:=(`ϖ`)->Determinant(M):

看上去M里含有变量`&varpi`,但其实根本就不是f的输入变量,但这里因为你后面用的都是`&varpi`,所以这个错误也就没体现出来,我也就懒得改了。

————————————————

我给你看看我运行的截图吧。我用的是maple10

网友(2):

将Maple程序体Proc转化为对应的MATLAB程序,用CodeGeneration[Matlab]:

CodeGeneration[Matlab](程序体)

F := proc(n) local s,t,i,tmp;
if n=0 then return 0 end if;
(s,t) := (1,1);
for i from 2 to n do
tmp := s+t; s := t; t := tmp;
end do;
return s;
end:

> CodeGeneration[Matlab](F);
function Freturn = F(n)
if (n == 0)
Freturn = 0;
end
s = 1;
t = 1;
for i = 2:n
tmp = s + t;
s = t;
t = tmp;
end
Freturn = s;

网友(3):

因为没有用print()
输出相应的变量的值等。