【问题标题】:MATLAB error using symfun/subsindex使用 symfun/subsindex 的 MATLAB 错误
【发布时间】:2015-04-29 15:19:51
【问题描述】:

我在将dsolve 与符号函数一起使用时遇到了问题。我收到一条错误消息:

“使用 symfun/subsindex 时出错(第 121 行)
索引值必须是正整数、逻辑或符号变量。

VK3 中的错误(第 9 行)
[F(n), G(n), H(n)] = dsolve(diff(F) == F2, diff(G) == G2,..."

这是我的代码。这对某些人来说可能看起来很愚蠢,但我对 Matlab 的经验相对较少。如果有人能告诉我哪里出错了,我将不胜感激。

syms F(n) G(n) H(n) F2(n) G2(n)

c = 1.004e-6;
m = input('Angular Velocity = ');
z = 0:1:20;
r = input('Radial Distance = ');
n = z*sqrt(m/c);

[F(n), G(n), H(n)] = dsolve(diff(F) == F2, diff(G) == G2,...
                            diff(F2) == F^2 - G^2 + F2*H,...
                            diff(G2) == 2*F + G2*H,...
                            diff(H) == -2*F,...
                            F(0) == 0, H(0) == 0, G(0) == 1, F(20) == 0, G(20) == 0);

U = m*r*F(n);
V = m*r*G(n);
W = sqrt(m/v)*H(n);

subplot(3,1,1)      
plot(U,n), xlabel('U'), ylabel('z'),...
           title('Radial Velocity Component')

subplot(3,1,2)      
plot(V,n), xlabel('V'), ylabel('z'),...
           title('Azimuthal Velocity Component')

subplot(3,1,3)         
plot(W,n), xlabel('W'), ylabel('z'),...
           title('Axial Velocity Component')

【问题讨论】:

    标签: algorithm matlab symbolic-math symbolic-computation


    【解决方案1】:

    正如错误消息所述,问题在于调用dsolve 的行。作为文档indicates,此函数要么返回

    • 包含方程解的符号数组。符号数组的大小对应于解的数量。

    • 包含方程组解的结构数组。结构体数组中的字段数对应于系统中自变量的个数。

    • 求解器分配方程组解的变量。输出变量或符号数组的数量必须等于系统中自变量的数量。工具箱按字母顺序对自变量进行排序,然后将这些变量的解分配给输出变量或符号数组。

    换句话说,它不返回符号函数 (symfun)。因此,Matlab 将F(n) 视为数组索引而不是符号函数。我推荐使用结构体数组形式:

    S = dsolve(diff(F) == F2,
               diff(G) == G2,...
               diff(F2) == F^2 - G^2 + F2*H,...
               diff(G2) == 2*F + G2*H,...
               diff(H) == -2*F,...
               F(0) == 0, H(0) == 0, G(0) == 1, F(20) == 0, G(20) == 0);
    

    但是,您的系统可能没有解析解(您有理由相信它有吗?),因为您会收到警告:

    警告:找不到显式解决方案。

    并且输出S 将为空。你可以试试applying assumptions。 (Mathematica 10 也好不到哪里去,因为它的价值。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 2013-04-04
      • 1970-01-01
      相关资源
      最近更新 更多