Indexing in symsum-Funktion

3 visualizaciones (últimos 30 días)
Daniel Thoden
Daniel Thoden el 29 de Mzo. de 2011
Editada: VBBV el 2 de Feb. de 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

Respuestas (2)

Walter Roberson
Walter Roberson el 29 de Mzo. de 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 comentarios
Walter Roberson
Walter Roberson el 6 de Abr. de 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 el 25 de Jul. de 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?

Iniciar sesión para comentar.


VBBV
VBBV el 2 de Feb. de 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 comentario
VBBV
VBBV el 2 de Feb. de 2023
Editada: VBBV el 2 de Feb. de 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)

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by