I have a problem with my code, it works fine but the results it isn't correct because the code is not compatible with the equations .. description below

1 view (last 30 days)
clc;
clear;
M = 60;
N = 36;
K = 5;
x = rand(1,N);
theta = (2*pi)*x; % generated randomly
Phi = diag(exp(1i*theta)); %NxN
H_hermitian = randn(N,M)+i*randn(N,M); %NxM Matrix ......... (h_n)hermitian = 1xM which represnt each row of H_hermitian
G = randn(K,N)+i*randn(K,N); %KxN ......... g = 1xN and which represnt each row of G .. g* Nx1
H_dk = randn(K,M)+i*randn(K,M); %KxM ......... h_dk = 1xM which represnt each row of H_dk
HT = H_dk+G*Phi*H; % KxM .. this matrix needs to be updated after computing the new theta by updating phi.
W = pinv(HT); % MxK ......... w = Mx1 .. Updateing HT means updating W and that is what I need
  7 Comments

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 2 Jul 2021
Edited: John D'Errico on 2 Jul 2021
This is one of those questions that tend to languish unanswered on the site. Why? Because you just say that your code does not work, does not produce the correct results. So we see a complicated code, lacking much in the way of comments about what you did. Worse, those comments seem to make little sense. For example, I see:
Alfa_i(t) = 0;
for t2=1:K
Alfa_i(t) = Alfa_i(t) + 1/(abs(H_dk(t2,:)*W(:,t2)));
end
Alfa_i(t) = Alfa_i(t) - Alfa_k(t); % Sum of Alfa_i
end
There is clearly a sum happening in there, but exctly what is being summed is not Alpha_i. At best, Alpha_i is the result of a sum.
And that was one of the only comments in your entire code. Oh. One other, where you tell the reader the completely obvious:
G = G(idx,:); % sort the whole matrix using the sort idx
I could compare your code to one I was given to maintian. In some 300 lines of code, there was only one comment. In a code block, where a matrix called C was clearly constructed, the ONLY comment was: "Create C matrix here". There was no information offered as to what C meant, or what will be done with it. Your code is almost analogous. And you want us to read that code and debug it, knowing only that it possibly does not work properly for some ungiven reason?
Then we must guess what it does wrong. Yes, it is supposed to follow the given pseudo-code. But then we must dive deeply into code written by you, to figure out where the problem is, when nobody has even said what it does wrong. And that is going to take some serious luck, for someone to wander by who has many hours to waste for probably no success.
If you want help, then I would first explain CLEARLY what answer you think it should produce. Then explain what it does produce, and why you think it is a problem. Remember, that if you go to a doctor and tell them only that your leg does not hurt, will they be able to know what is the reason you went to see them, and perhaps how to help you?
Better yet is to help yourself. Extract this code from what contains it. Use the code, by providing a simple, sample problem where you will know the answer that JUST this code fragment should perform correctly. Does it work? If not, then you can lean why. This, by the way, is why modular code is valuable. You can test every piece. NEVER throw together a huge mess of code and expect it all to work the first time. Write code in SMALL fragment. Test EVERY such code fragment. Only when they all work as you know they should do you build the larger code.
Next, learn to use the debugger! Trace through the code. Verify every line of code. Does it do what you expect it to do on the sample subproblem I suggested you formulate?
So I'm sorry that this is not really an answer, because I think no answer is really possible. You are the best person to solve this problem. You have the most incentive to want to solve it, to spend what may be a few hours tracking down the problem. I recall a saying from my misspent youth: "God helps those who help themselves." At the very least, make it possible for someone to help you. Good luck.
  1 Comment
Matthew Worker
Matthew Worker on 2 Jul 2021
sir thank you for your response.
I think I wrote all the matrices which needed to compute these equations.
I just don't know how to do these for loops.
I tried to do it too many times in different ways but I think my code is not compatible with for loops in the picture.
I wrote a brief description in front of each line and I deleted the rest of the code

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!