Error using sym/subindex (Bessel function)
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (2)
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.
0 Comments
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);
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
See Also
Categories
Find more on Bessel functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!