Error using sym/subsindex () while using the symsum function

조회 수: 11 (최근 30일)
Salem Almahri
Salem Almahri 2020년 11월 24일
편집: Stephan 2020년 11월 24일
Y = [-12.5j +12.5j 0 0 0 0 0 0;
+12.5j -16.649j +1.297j +1.815j +1.037j 0 0 0;
0 +1.297j 5.899+2.288j -5.899-5.984j 0 +2.399j 0 0;
0 +1.815j -5.899-5.984j 5.899+2.169j 0 0 +2j 0;
0 +1.037j 0 0 -3.537j 0 0 +2.5j;
0 0 +2.399j 0 0 -2.399j 0 0;
0 0 0 +2j 0 0 0.871-1.505j -0.871-0.495j;
0 0 0 0 +2.5j 0 -0.871-0.495j 0.871-2.005j];
V = [0 1+0.5j 1+0.5j 1+0.5j 1+0.5j 1+0.5j 1+0.5j 1+0.5j];
syms k
f = abs(V(4))*abs(V(k))*abs(Y(4,k))*sin(angle(Y(4,k))-angle(V(4)+V(k)));
E = subs (f, k, 0:7);
Q = sum(E);
I got the error in line(13), in the f equation, i dont know what is the reason for that, i tried several things and it still did not work, so if anyone know what is the problem exactly, and could help me, as i need to finish this as soon as possible
  댓글 수: 1
Salem Almahri
Salem Almahri 2020년 11월 24일
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.
This is the error i got

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 24일
You can never use an unresolved symbolic variable as a subscript.
You must always use definite numeric or logical values for subscripts (though table() extends this, it still does not permit symbolic).
Define your numeric k and then have the expression that uses it, making sure that you have vectorized the expression.

추가 답변 (1개)

Stephan
Stephan 2020년 11월 24일
편집: Stephan 2020년 11월 24일
There are two possible ways in Matlab, that allow a syntax like
V(k)
The first is indexing with a variable like in a for loop:
> V = 5:10
V =
5 6 7 8 9 10
>> k = 3
k =
3
>> V(k)
ans =
7
The second one is using symbolic functions:
>> syms k
>> V(k) = 3*k + 1
V(k) =
3*k + 1
>> V(3)
ans =
10
What you do is mixing both possibilities, which is not allowed. So you have to rethink your code to what you want to do
  댓글 수: 2
Salem Almahri
Salem Almahri 2020년 11월 24일
Thank You for the reply, but what i mean by V(k), is the kth number of the V array, or V(4) is the 4th integer in the V array that i defined above, so if i can not do V(k) what should i use, since i want to itterate the value of V from the array and sum them.
Stephan
Stephan 2020년 11월 24일
편집: Stephan 2020년 11월 24일
You define
syms k
and then use it to index an array V in the next line - this does not work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by