在枫树中求解方程系统

发布于 2025-02-06 08:15:33 字数 565 浏览 2 评论 0原文

我有一个n个方程的系统和n个未知变量,符号总和。我想创建一个循环以在输入n时求解此方程系统。

y:= s-> 1/6 cos(3 s);

a:=(k,s) - > PICEEWISE(k<> 0,1/2 exp(k s i)/abs(k),k = 0,ln(2) exp(s 0 i) - sin(s));

s:=(j,n) - > 2 j pi/(2*n + 1);

n:= 1; 对于从-n到n的J eqn [j]:= sum((a(k,s(j,n))))。(a [k]),k = -n .. n .. n)= y(s(j,n)); 结束;

等式:= seq(eqn [i],i = -n .. n);

solve({eqs},{a [i]});

在此处输入图像描述 请帮助我!

I have a system of n equations and n unknown variables under symbol sum. I want to create a loop to solve this system of equations when inputting n.

y := s -> 1/6cos(3s);

A := (k, s) -> piecewise(k <> 0, 1/2exp(ksI)/abs(k), k = 0, ln(2)exp(s0I) - sin(s));

s := (j, n) -> 2jPi/(2*n + 1);

n := 1;
for j from -n to n do
eqn[j] := sum((A(k, s(j, n))) . (a[k]), k = -n .. n) = y(s(j, n));
end do;

eqs := seq(eqn[i], i = -n .. n);

solve({eqs}, {a[i]});

enter image description here
Please help me out!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香橙ぽ 2025-02-13 08:15:33

我在您的明文代码中添加了一些丢失的乘法符号,以重现它。

restart;
y:=s->1/6*cos(3*s):
A:=(k,s)->piecewise(k<>0,1/2*exp(k*s*I)/abs(k),
                    k=0,ln(2)*exp(s*I*0)-sin(s)):

s:=(j,n)->2*j*Pi/(2*n+1):
n:=1:

for j from -n to n do
  eqn[j]:=add((A(k,s(j,n)))*a[k],k=-n..n)=y(s(j,n));
end do:

eqs:=seq(eqn[i],i=-n..n);

   (-1/4+1/4*I*3^(1/2))*a[-1]+(ln(2)+1/2*3^(1/2))*a[0]+(-1/4-1/4*I*3^(1/2))*a[1] = 1/6,
   1/2*a[-1]+ln(2)*a[0]+1/2*a[1] = 1/6,
   (-1/4-1/4*I*3^(1/2))*a[-1]+(ln(2)-1/2*3^(1/2))*a[0]+(-1/4+1/4*I*3^(1/2))*a[1] = 1/6

您可以将名称集(为此解决)作为可选参数。但这必须包含实际名称,而不仅仅是抽象占位符a [i]

solve({eqs},{seq(a[i],i=-n..n)});

     {a[-1] = 1/6*I/ln(2),
      a[0] = 1/6/ln(2),
      a[1] = -1/6*I/ln(2)}

您也可以在此处省略不确定的名称,作为可选的参数到solve(因为您希望为所有这些求解,并且没有其他名称)。

solve({eqs});

     {a[-1] = 1/6*I/ln(2),
      a[0] = 1/6/ln(2),
      a[1] = -1/6*I/ln(2)}

对于n:= 3n:= 4它有助于solve如果exp呼叫,请在此处更快获得结果变成触发电话。即,

solve(evalc({eqs}),{seq(a[i],i=-n..n)});

如果n高于4,则可能需要等待精确的结果(符号)结果。但是,即使在n:= 10对我来说,浮点结果也很快。也就是说,调用fsolve,而不是solve

fsolve({eqs},{seq(a[i],i=-n..n)});

但是,即使那也可能是不必要的,因为似乎以下是n&gt; = 3的解决方案。此处所有变量都设置为零,除A [-3]A [3]都设置为1/2

cand:={seq(a[i]=0,i=-n..-4),seq(a[i]=0,i=-2..2),
       seq(a[i]=0,i=4..n),seq(a[i]=1/2,i=[-3,3])}:

simplify(eval((rhs-lhs)~({eqs}),cand));

              {0}

I added some missing multiplication symbols to your plaintext code, to reproduce it.

restart;
y:=s->1/6*cos(3*s):
A:=(k,s)->piecewise(k<>0,1/2*exp(k*s*I)/abs(k),
                    k=0,ln(2)*exp(s*I*0)-sin(s)):

s:=(j,n)->2*j*Pi/(2*n+1):
n:=1:

for j from -n to n do
  eqn[j]:=add((A(k,s(j,n)))*a[k],k=-n..n)=y(s(j,n));
end do:

eqs:=seq(eqn[i],i=-n..n);

   (-1/4+1/4*I*3^(1/2))*a[-1]+(ln(2)+1/2*3^(1/2))*a[0]+(-1/4-1/4*I*3^(1/2))*a[1] = 1/6,
   1/2*a[-1]+ln(2)*a[0]+1/2*a[1] = 1/6,
   (-1/4-1/4*I*3^(1/2))*a[-1]+(ln(2)-1/2*3^(1/2))*a[0]+(-1/4+1/4*I*3^(1/2))*a[1] = 1/6

You can pass the set of names (for which to solve) as an optional argument. But that has to contain the actual names, and not just the abstract placeholder a[i] as you tried it.

solve({eqs},{seq(a[i],i=-n..n)});

     {a[-1] = 1/6*I/ln(2),
      a[0] = 1/6/ln(2),
      a[1] = -1/6*I/ln(2)}

You could also omit the indeterminate names here, as optional argument to solve (since you wish to solve for all of them, and no other names are present).

solve({eqs});

     {a[-1] = 1/6*I/ln(2),
      a[0] = 1/6/ln(2),
      a[1] = -1/6*I/ln(2)}

For n:=3 and n:=4 it helps solve to get a result quicker here if exp calls are turned into trig calls. Ie,

solve(evalc({eqs}),{seq(a[i],i=-n..n)});

If n is higher than 4 you might have to wait long for an exact (symbolic) result. But even at n:=10 a floating-point result was fast for me. That is, calling fsolve instead of solve.

fsolve({eqs},{seq(a[i],i=-n..n)});

But even that might be unnecessary, as it seems that the following is a solution for n>=3. Here all the variables are set to zero, except a[-3] and a[3] which are both set to 1/2.

cand:={seq(a[i]=0,i=-n..-4),seq(a[i]=0,i=-2..2),
       seq(a[i]=0,i=4..n),seq(a[i]=1/2,i=[-3,3])}:

simplify(eval((rhs-lhs)~({eqs}),cand));

              {0}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文