Error using sym/subindex (Bessel function)

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일

0 개 추천

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일

0 개 추천

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

Right. Symbolic variables can never be used as an index.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2021년 2월 22일

댓글:

2021년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by