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

10 Ansichten (letzte 30 Tage)
Salem Almahri
Salem Almahri am 24 Nov. 2020
Bearbeitet: Stephan am 24 Nov. 2020
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 Kommentar
Salem Almahri
Salem Almahri am 24 Nov. 2020
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Nov. 2020
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.

Weitere Antworten (1)

Stephan
Stephan am 24 Nov. 2020
Bearbeitet: Stephan am 24 Nov. 2020
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 Kommentare
Salem Almahri
Salem Almahri am 24 Nov. 2020
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 am 24 Nov. 2020
Bearbeitet: Stephan am 24 Nov. 2020
You define
syms k
and then use it to index an array V in the next line - this does not work.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by