Why do I get 'Array indices must be positive or logical values' in symsum function?

syms n
h=0.05;
U=0.02;
delta_t=1;
v=1.846*10^-5;
d=1.117;
t=50;
y=0.2;
P=pi;
F=symsum((1/n)*exp(-((n^2)*(P^2)*v*t)/(d*(h^2)))*sin(n*P(1-y/h)),n,1,300);
Array indices must be positive integers or logical values.
u=U*y/h-(2*U/P)*F(n);

 Accepted Answer

h=0.05;
U=0.02;
delta_t=1;
v=1.846*10^-5;
d=1.117;
t=50;
y=0.2;
P=pi;
n = 1:300;
Fn = 1./n.*exp(-(n.^2*P^2*v*t)/(d*h^2)).*sin(n*P*(1-y/h));
F = cumsum(Fn);
u=U*y/h-(2*U/P)*F;

More Answers (1)

The error is because you appear to be indexing P with a non-integer. Did you mean to write,
sin(n*P*(1-y/h))
?

5 Comments

Yes you are right.
But I still get 'Error using sym/subsindex Invalid// indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.' after changing it.
syms n
h=0.05;
U=0.02;
delta_t=1;
v=1.846*10^-5;
d=1.117;
t=50;
y=0.2;
P=pi;
F=symsum((1/n)*exp(-((n^2)*(P^2)*v*t)/(d*(h^2)))*sin(n*P*(1-y/h)),n,1,300)
F = 
0
u=U*y/h-(2*U/P)*F(n);
Error using indexing
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.

Error in indexing (line 936)
R_tilde = builtin('subsref',L_tilde,Idx);
The only variable set in the expression is n, other values are all given. Why is this not functioning?
What do you mean by F(n) in the expression
u=U*y/h-(2*U/P)*F(n);
?
Maybe you want
u=U*y/h-(2*U/P)*F;
?
Probably because F is not a function of anything. It is just sym(0). So, F(n) doesn't make sense.
So basically I want to get the summation of F values by substituting n from 1 to 300 into this equation. F(n) is an array storing values with indices n=[1:300]. For example, F(3)=Fsum(1)+Fsum(2)+Fsum(3), F(2)=Fsum(1)+Fsum(2).
Torsten's answer should give that to you, but in the meantime, since I have answered your posted question, please Accept-click the answer and, if Torsten's response doesn't get you where you need, post a new question.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 18 Mar 2023

Commented:

on 19 Mar 2023

Community Treasure Hunt

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

Start Hunting!