How to write Subscript in MATLAB?

조회 수: 220 (최근 30일)
Ankitha Pai
Ankitha Pai 2021년 2월 24일
답변: Yasmine 2023년 2월 22일
Hello, So in my code i need to have subcripts in order to have multiple values of that varibale. I used the format given in matlab documents but still hvaing error
syms d_1 d_2 d_3 d_4 d_5 d_6 d_7 d_8 d_9 d_10 u_k a_i y_k y_(k-i)
A = [0.2867, -0.2428];
B = [0.6607 , -0.2732];
d_1 = 1;
v_k = d_1*u_k+d_2*u_k^2+d_3*u_k^3+d_4*u_k^4+d_5*u_k^5+d_6*u_k^6+d_7*u_k^7+d_8*u_k^8+d_9*u_k^9+d_10*u_k^10;
%yk formula
for k = 1:2
for i = 1:10
x = a_i*y_(k-i)
z = b_i(u_(k-i)+symsum(d_p*u^p(k-i),2, 10))
y_k = -x +z
end
end
Please help me out and let me know if the declaration of syms and the other varibales is wrong and how to correct it.
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 2월 24일
편집: KALYAN ACHARJYA 2021년 2월 24일
Problem is here y_(k-i) what exactly are you trying to do? Is it sys variable or sym function.
You can use y(k,i) as sym function directly.
Ankitha Pai
Ankitha Pai 2021년 3월 16일
it is system variable. So basically i have the y(k) values those are the outputs and y(k-i) will be the past outputs so using for loop i needed to go through the data set and get the value.
Right now writing it like y(k-i) works well for me and i used live editor
Thankss for you help.

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

채택된 답변

Bhomik Kankaria
Bhomik Kankaria 2021년 2월 27일
Hi Ankitha,
Currently, MATLAB Live Editor displays symbolic variables with subscripts, superscripts, and accents in standard mathematical notation.
Hence you need to use live scripts to use the subscript functionality. Also live editor does not support naming the variable as y_(k-i) and will throw an error. You can use name like y_k_i etc. depending on the use case.
To see more examples of the variable names refer the below link-
  댓글 수: 2
Ankitha Pai
Ankitha Pai 2021년 3월 16일
Thanks alot for the relpy.
Currently using y(k-i) works for me. And yes live editor is helping.
ALFIE NELSON
ALFIE NELSON 2022년 3월 20일
편집: ALFIE NELSON 2022년 3월 20일
Is there any way to create subscripts in the regulat editor and not the live editor? Or is there a way to publish on the live editor?

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

추가 답변 (2개)

Steven Lord
Steven Lord 2022년 3월 20일
You don't need to explicitly create so many symbolic variables.
d = sym('d', [1 10])
d = 
y = sym('y', [1 2])
y = 
syms u_k a_i
A = [0.2867, -0.2428];
B = [0.6607 , -0.2732];
d(1) = 1;
v = d*u_k.^(1:10).'
v = 
Now work with v, d(someNumber), and y(someNumber) instead of trying to dynamically create variable names d_1, d_2, etc.

Yasmine
Yasmine 2023년 2월 22일
Y_mean

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by