MATLAB Answers


Creating a Simbolic vector and setting assumptions on it

Francesco Giuseppe Fornari さんによって質問されました 2019 年 8 月 8 日
最新アクティビティ Francesco Giuseppe Fornari さんによって コメントされました 2019 年 8 月 13 日
I'm trying to build a symbolic vector with variable dimension N, and I would like it to be real...
I managed to build the vector with the desired lenght throug str2sym, but I don't know how to set assumption "real" on its variables.
(I would like to use this vector for a linear system).
stot2=[' '];
for i=1:N
A = i;
s1=sprintf(' u%d, ',A);
s2=sprintf(' v%d, ',A);
s3=sprintf(' w%d ',A);
stot2=strcat(stot2, s1, s2, s3);
U1=['[' stot2 ']'];
Thanks for any help!

  0 件のコメント

サインイン to comment.

2 件の回答

Walter Roberson
回答者: Walter Roberson
2019 年 8 月 12 日

u = sym('u', [1 N], 'real');
v = sym('v', [1 N], 'real');
w = sym('w', [1 N], 'real');
U = [u, v, w];

  3 件のコメント

This work. But I want the count for each triplet u,v,w in the final vector:
u1, v1, w1, u2, v2, w2, u3, v3, w3
How would you do this?
madhan ravi
2019 年 8 月 13 日
thanks, it works perfectly!

サインイン to comment.

回答者: Divya Gaddipati 2019 年 8 月 12 日

You can declare assumptions on symbolic variables using the assume function from the Symbolic Math Toolbox. For more information on how to use this function, refer to this link.
In your code, since “U” is a sym object, you can directly loop over U and set each of the variable to real.
for i = 1 : length(U)
assume(U(i), 'real');

  1 件のコメント

Walter Roberson
2019 年 8 月 12 日
Yes, but there is no need to loop:
assume(U, 'real');

サインイン to comment.

Translated by