Creating a Simbolic vector and setting assumptions on it
조회 수: 3 (최근 30일)
이전 댓글 표시
Francesco Giuseppe Fornari
2019년 8월 8일
댓글: Francesco Giuseppe Fornari
2019년 8월 13일
Hi,
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);
end
U1=['[' stot2 ']'];
U=str2sym(U1)
Thanks for any help!
댓글 수: 0
채택된 답변
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
추가 답변 (1개)
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');
end
댓글 수: 1
Walter Roberson
2019년 8월 12일
Yes, but there is no need to loop:
assume(U, 'real');
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!