【问题标题】:Octave Matrix of discretized Legendre polynomials离散勒让德多项式的八度矩阵
【发布时间】:2013-08-02 03:29:50
【问题描述】:

我需要得到 N x 列 (L) 的 Legendre 多项式矩阵,在 L 上对任意 N 进行评估。

除了显式评估每行的多项式向量之外,还有更好的计算矩阵的方法吗?这种方法的代码 sn-p (N = 4) 在这里:

L = linspace(-1,1,800);

# How to do this in a better way?
G = [legendre_Pl(0,L); legendre_Pl(1,L); legendre_Pl(2,L); legendre_Pl(3,L)];

谢谢, 沃伊塔

【问题讨论】:

  • 首先,您如何定义“最佳”,其次是否可以接受任何不准确之处?例如,您可以简单地每隔一个点计算 L 并进行插值。
  • 我只需要在 L 上找到从 1 到 N 的 legendre_Pl(n, L) 的行(N 是结果矩阵的行数)并将它们保存为 Nxcols 的矩阵( L)。使用 n = 1:N 作为 legendre_Pl 的参数在这里不起作用。 “最佳”是指使 N 变量,因此我不必手动输入所有 legendre_Pl。另外,最好不要使用 for 循环。不准确不是这个问题的主题

标签: matrix octave discretization


【解决方案1】:

创建一个匿名函数。 http://www.gnu.org/software/octave/doc/interpreter/Anonymous-Functions.html的文档

f = @(x) legendre_Pl(x,L);

然后使用 arrayfun 将函数 f 应用到数组 [1:N] http://www.gnu.org/software/octave/doc/interpreter/Function-Application.html 的文档

CellArray = arrayfun(f, [1:N], "UniformOutput", false);

这为您提供了一个元胞数组。如果您想在矩阵中得到答案,请使用cell2mat

G = cell2mat(CellArray);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    相关资源
    最近更新 更多