MATLAB Answers

Error using sym/subindex (Bessel function)

17 views (last 30 days)
Sun Wook Han
Sun Wook Han on 22 Feb 2021
Commented: Walter Roberson on 25 Feb 2021
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.

Answers (2)

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

Steven Lord
Steven Lord on 25 Feb 2021
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 Comment
Walter Roberson
Walter Roberson on 25 Feb 2021
Right. Symbolic variables can never be used as an index.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!