フィルターのクリア

Error using sym/subindex (Bessel function)

3 ビュー (過去 30 日間)
Sun Wook Han
Sun Wook Han 2021 年 2 月 22 日
コメント済み: Walter Roberson 2021 年 2 月 25 日
syms k
t = 0:1:100;
rho = 1000;
mu = 0.001;
dp = 1;
R = 0.05;
l = 1;
ram = besselzero(0,11);
tau = mu*t/(rho*R^2);
f1 = symsum(2*exp(-ram(k)^2*tau)/(ram(k)^3*besselj(1,ram(k))), k, 1, 11);
f11 = f1-(1/4);
f2 = symsum(4*exp(-ram(k)^2*tau)*besselj(1,ram(k))/(ram(k)^4*besselj(1,ram(k))), k, 1, 11);
f22 = f2-(1/8);
f3 = f11/f22;
plot(f3, tau)
I'm new to MATLAB and encountered the error message below. Please advice.
Error using sym/subsindex (line 857)
Invalid indexing or function definition. Indexing
must follow MATLAB indexing. Function arguments must
be symbolic variables, and function body must be sym
expression.

回答 (2 件)

Shadaab Siddiqie
Shadaab Siddiqie 2021 年 2 月 25 日
From my understanding you are getting an error with above code, please refer symbolic expression and solve for more information.

Steven Lord
Steven Lord 2021 年 2 月 25 日
syms k
t = 0:1:100;
rho = 1000;
mu = 0.001;
dp = 1;
R = 0.05;
l = 1;
ram = besselzero(0,11);
Unrecognized function or variable 'besselzero'.
Since you haven't showed us your besselzero function, we can't run your code. But if I had to guess:
tau = mu*t/(rho*R^2);
f1 = symsum(2*exp(-ram(k)^2*tau)/(ram(k)^3*besselj(1,ram(k))), k, 1, 11);
Don't use symsum here. What I think you're doing is along the line of:
>> x = 1:10;
>> syms k
>> symsum(x(k), k, 1, 10)
Error using sym/subsindex (line 855)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and
function body must be sym expression.
If I'm right, just use sum. This works even if the array you're trying to sum is symbolic. Just use element-wise operations, compute all the elements of the "body" of your symsum at once, and sum.
>> y = k.^x;
>> sum(y)
ans =
k^10 + k^9 + k^8 + k^7 + k^6 + k^5 + k^4 + k^3 + k^2 + k
snipped the rest of the code
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 25 日
Right. Symbolic variables can never be used as an index.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by