Why are the values ,the result of rho_k, are the same?it shouldn't be the same

1 visualización (últimos 30 días)
First, i introduce the code A, this code A can help me find the minimum value when the rho_k=0.6, and the loop does the code for 100 times, i called the minimum value called meann
bd=100
AXX3=zeros(1,bd);
rho_k=0.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for dd=1:bd
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%In this code, each time of loop will produce a value name cvx_optval,
%so this loop run for 100 times,theorically,it will produce 100 cvx_optval
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c3(dd)=AXX3(dd)+cvx_optval;%i have 100 cvx_optval, i will store each cvx_optval into the c3 matrix,that is
%when dd=1, the first cvx_optval will plus the first element,0, which is in the AXX3,that's how i store the cvx_optval into the c3 matrix
%obviously,there will be 100 values in c3 matrix, that is, c3 matrix is a 1 by 100 matrix
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
allthings=c3
c3_noninf=allthings(~isinf(allthings))%because some of element in this matrix are inf, these are not what i want, so i delete them
%and remain the non-inf values, these non-inf values are also the elements of vector c3_noninf
meann=min(c3_noninf) %now, i find the minimum element in the vector c3_noninf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
So in this code, i can find the minimum value when the rho_k=0.6, and the loop does the code for 100 times, i called the minimum value called meann
Now, i want to let the rho_k become 0, 0.2 ,0.4, and 0.6, and i want to let rho_k change automatically, so i must write
for rho_k=0:0.2:0.6
...
end
So, i write the code like this below
bdc=4
lkk=1:bdc %lkk=1, 2, 3, 4
lkkspace=zeros(1,bdc)
%
for rho_k=0:0.2:0.6
code A
mini_for_constant(lkk)=meann
us(lkk)=lkkspace(lkk)+mini_for_constant
end
allthings_compare=us
theorically, us will have four different values, these are the meann of rho_k=0 , rho_k=0.2, rho_k=0.4, rho_k=0.6, and it will combine to a 1 by 4 vector called "us", however,the window show me this
us =
17.8487 17.8487 17.8487 17.8487
yes! the "us" is a 1 by 4 vector, but each element is the same, why? where do i make a mistake?
  5 comentarios
Walter Roberson
Walter Roberson el 31 de Mzo. de 2019
yang-En Hsiao:
The only explanation your code gave for AXX3 was "the first element,0, which is in the AXX3". That does not give us any idea of why you included AXX3 in your code instead of just leaving it out.
Your code has the comment, "i have 100 cvx_optval" . When we look at
c3(dd)=AXX3(dd)+cvx_optval
if cvx_optval is a vector of length 100, then AXX3(dd)+cvx_optval is a vector of length 100, and that result is too large to store into the single location c3(dd) . In order to get past that statement, your cvx_optval would have to be scalar. Your posted code does not change cvx_optval in the dd loop, so your code appears to be copying the same value, cvx_optval, to a number of locations, and adding the zero from AXX3 as it goes. This seems inefficient and is confusing. This leads us to believe that your code might be something other than what you posted. We cannot properly debug code when the person posts code that is different than what they really have: the cause of the problem they are noticing might be in the code they did not post.
Guillaume
Guillaume el 1 de Abr. de 2019
" why do i need to write about that?"
I don't understand you. You come here asking for help, give us code that we don't understand and when we ask for clarification about said code, you lash out. We're not the ones in need of help.
You have to write out about it because it's used in your code. And as said, in your code it's all 0s, so the variable doesn't make any sense. I don't see how we can help you if we can't even understand what you're doing.
Anyway, you seem to have solve your problem yourself so it does not matter anymore.

Iniciar sesión para comentar.

Respuesta aceptada

yang-En Hsiao
yang-En Hsiao el 1 de Abr. de 2019
The original code is like this
bdc=4
lkk=1:bdc %lkk=1, 2, 3, 4
lkkspace=zeros(1,bdc)
%
for rho_k=0:0.2:0.6
code A
mini_for_constant(lkk)=meann
us(lkk)=lkkspace(lkk)+mini_for_constant
end
allthings_compare=us
However,as we can see,the the value of lkkspace(lkk) won't change with the rho_k changing,so if we want that when rho_k become 0.2,should be the "second" value of rho_k ,and there will be a value to store value in the "second" position
bdc=4
lkk=1:bdc %lkk=1, 2, 3, 4
lkkspace=zeros(1,bdc)
rho_k=[0 0.2 0.4 0.6]
%
for lkk=1:bdc
code A (the rho_k in this code A have to be modified to rho_k(lkk))
mini_for_constant(lkk)=meann
us(lkk)=lkkspace(lkk)+meann
end
allthings_compare=us
Now,we can find that us is a 1 by 4 matrix,and each element in it is the minimum scalar when the rho_k is 0,0.2,0.4 and 0.6

Más respuestas (1)

Walter Roberson
Walter Roberson el 31 de Mzo. de 2019
c3_noninf=allthings(~isinf(allthings))
When you do logical indexing with only a single index, the result is always going to be either empty or a scalar or a vector -- never a 2 or more dimensional array.
meann=min(c3_noninf)
Minimum of empty would be empty; minimum of a scalar or a vector would be a scalar.
lkk=1:bdc %lkk=1, 2, 3, 4
lkkspace=zeros(1,bdc)
So lkkspace is all zero.
%
for rho_k=0:0.2:0.6
code A
mini_for_constant(lkk)=meann
We showed above that meann is a scalar. It is constant for all rho_k values because it is not being changed in the rho_k loop. So mini_for_constant(lkk) will all be set to the same value.
us(lkk)=lkkspace(lkk)+mini_for_constant
lkkspace(lkk) is all zero. mini_for_constant is all the same value. Therefore us(lkk) is going to all be the same value.
end
Your code does not use the value of rho_k in the loop.
  1 comentario
yang-En Hsiao
yang-En Hsiao el 1 de Abr. de 2019
thanks for your suggestion,the key i can't do what i want is your last sentence: Your code does not use the value of rho_k in the loop.
i will answer the question below,again, thankyou

Iniciar sesión para comentar.

Categorías

Más información sobre Coordinate Transformations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by