Indexing in symsum-Funktion

3 views (last 30 days)
Daniel Thoden
Daniel Thoden on 29 Mar 2011
Edited: VBBV on 2 Feb 2023
Hello,
how do I index the A in a function like this?
anz = 5;
A = sym('A',[anz 1]);
q = symsum( A(vpa(n))*r^n * cos(n*phi) ,'n' ,2,anz)
The error message in this case is:
??? Error using ==> mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Can anyone help me? Thanks in advance. Daniel

Answers (2)

Walter Roberson
Walter Roberson on 29 Mar 2011
I think you are missing
syms n
before this code.
I do not see any reason to use vpa(n) there:
syms n;
q = symsum( A(n)*r^n * cos(n*phi), n, 2, anz );
  5 Comments
Walter Roberson
Walter Roberson on 6 Apr 2011
Thanks, Christopher. The MuPad documentation available online tends not to talk about these kind of nuances.
I do not have the Symbolic Toolkit so it is not uncommon for me to slip in to Maple practices.
Aaron J. Hendrickson
Aaron J. Hendrickson on 25 Jul 2017
Walter. When I run:
syms n
anz = 5;
A = sym('A',[anz 1]);
q = symsum(A(n)*r^n*cos(n*phi), n, 2, anz);
I get an error in MATLAB saying:
Error using sym/subsindex (line 766)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
Error in sym/subsref (line 805)
R_tilde = builtin('subsref',L_tilde,Idx);
Not sure how to index variables in sums and products...do you know what is going on here?

Sign in to comment.


VBBV
VBBV on 2 Feb 2023
syms n r phi % declare r and phi as symbolic also
anz = 5;
A = sym('A',[anz 1])
A = 
q = symsum(A.*r^n*cos(n*phi), n, 2, anz) % As error shows Matlab indexing is numeric & not symbolic
q = 
  1 Comment
VBBV
VBBV on 2 Feb 2023
Edited: VBBV on 2 Feb 2023
koAs A is symbolic vector , you can access the elements of that vector through integers and not using symbols e.g n as below
A(n)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!