【问题标题】:How to translate this code from muPAD to Python?如何将此代码从 muPAD 转换为 Python?
【发布时间】:2021-03-23 20:38:58
【问题描述】:

我希望如果有人知道如何用 Python 表达以下 Mupad 代码:

for n from 1 to 6 do
 M:= matrix([[B(k,j) $ k = 0..n] $ j = 0..n]);
 C:=matrix([c(j)$ j = 0..n]);
 A:=linalg::matlinsolve(M, C);P:=sum(A[j+1]*x^j, j = 0..n);plot(P,fx, x =-1..1);
end_for:

【问题讨论】:

  • 这看起来是一段非常复杂的代码。它已被压缩以占用很少的空间并且不使用描述性变量。为什么需要这个翻译?
  • 确实,这是函数的最小二乘逼近方法的一部分,目前我正在尝试构建另一种代码,因为这个代码很难阅读,谢谢@Bluenix跨度>

标签: python translation mupad


【解决方案1】:

我完全看不懂这段代码,但这里有一些提示......

Python 中的 For 循环如下所示(这是 Python shell):

>>> for i in range(1, 6+1):
...     print(i)
...
1
2
3
4
5
6

不知道 Mupad 我不确定for n from 1 to 6 do 是否意味着:

a) 0、1、2、3、4、5 (range(0, 6))

b) 0、1、2、3、4、5、6 (range(0, 6+1))

c) 1、2、3、4、5、6 (range(1, 6+1))

我看到有“矩阵”的引用,为此请参阅常用库NumPy 及其在numpy.matrix 上的文档。为了您的简单,它已经有很多方法。

您最好的选择可能是搜索 NumPy 替代方案,而不是使用这段代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    相关资源
    最近更新 更多