How to ensure that dynamically create symbolically variables are real?
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hello,
I'm creating symbolic variables dynamically and I wanted to ensure that the symbolic variables are real.
I have the code
clear all
index = {'1'};
List = {'A','B','C'};
A=sym(strcat(List,index))
How can I modify this to make sure that the symbolic variables stored in A are real? I have tried changing to A=sym(strcat(List,index),'real'), but this doesn't work.
Thank you, Kevin
댓글 수: 1
Kevin Bachovchin
2014년 2월 14일
편집: Kevin Bachovchin
2014년 2월 14일
답변 (2개)
Azzi Abdelmalek
2014년 2월 14일
I don't think you can, for example force the variable A1 to be real. If
A1=5+j
Then
index = {'1'};
List = {'A','B','C'};
A=sym(strcat(List,index))
out=subs(A(1))
The result is a complex number
댓글 수: 5
Kevin Bachovchin
2014년 2월 14일
편집: Kevin Bachovchin
2014년 2월 14일
Azzi Abdelmalek
2014년 2월 14일
n=3
a=sprintf('A%d ',1:n)
eval(['syms ' a ' real'])
eval(['A=[' a ']'])
Kevin Bachovchin
2014년 2월 14일
Azzi Abdelmalek
2014년 2월 14일
s=regexp('A':'Z','.','match')
n=3
a=strjoin(strcat(s(1:n),'1'))
eval(['syms ' a ' real'])
eval(['A=[' a ']'])
Kevin Bachovchin
2014년 2월 14일
Kevin Bachovchin
2014년 2월 20일
댓글 수: 2
Walter Roberson
2014년 2월 21일
Not if the variable names are not all the same number of characters.
Kevin Bachovchin
2014년 2월 21일
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!