gpt4 book ai didi

algorithm - 使用 symfun/subsindex 的 MATLAB 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:07:01 25 4
gpt4 key购买 nike

我在使用带有符号函数的 dsolve 时遇到问题。我收到一条错误消息:

"Error using symfun/subsindex (line 121)
Indexing values must be positive integers, logicals or symbolic variables.

Error in VK3 (line 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')

最佳答案

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

  • Symbolic array that contains solutions of an equation. The size of a symbolic array corresponds to the number of the solutions.

  • Structure array that contains solutions of a system of equations. The number of fields in the structure array corresponds to the number of independent variables in a system.

  • Variables to which the solver assigns the solutions of a system of equations. The number of output variables or symbolic arrays must equal the number of independent variables in a system. The toolbox sorts independent variables alphabetically, and then assigns the solutions for these variables to output variables or symbolic arrays.

换句话说,它不返回符号函数 ( 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);

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

Warning: Explicit solution could not be found.

并且输出 S 将为空。你可以试试 applying assumptions . (就其值(value)而言,Mathematica 10 并没有更好的表现。)

关于algorithm - 使用 symfun/subsindex 的 MATLAB 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29948003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com