Unrecognized function or variable error code help required

I have created code on low rank assumption using nuclear norm using CVX. I am getting the following error code -
Unrecognized function or variable 'A_i'.
Error in Untitled3 (line 21)
y(i_m) == trace(A_i)*Xe;
here is my code any help will be appricated
r = 2; % the rank;
n = 4; % the dimension
a = randn(n,r);
b = randn(n,r);
X = a*b'; % low rank Matrix;
m=fix(n^2-1);
A = randn(n, n);
y = trace(A*X);
% low rank approximation using nuclear norm
cvx_begin
variable Xe(n,m)
minimize norm_nuc(Xe)
subject to
A*Xe == y
cvx_end
for i_m = 1 : m
y(i_m) == trace(A_i*Xe);
end
error = norm(X-Xe)
for m = 1 : 10 : n^2
for mc = 1 : MONTE_CARLO
% Generate measurements
y = zeros(m, 1);
for i_m = 1 : m
A_i = randn(n, n);
y(i_m) = trace(A_i*X);
end
% Solve problem
% Store results
end
end

回答 (1 件)

Tayyab Khalil
Tayyab Khalil 2021 年 1 月 22 日

0 投票

This is because A_i is undefined in the code but is being used. What value do you want it to have?

8 件のコメント

Karim Wahdan
Karim Wahdan 2021 年 1 月 22 日
I am definding A_i to have random n x n. So im not sure if it has a proper value
Tayyab Khalil
Tayyab Khalil 2021 年 1 月 22 日
That's A, but you are trying to use A_i. If you want to use the ith entry of A, use A(i_m) since you are looping with i_m.
Jan
Jan 2021 年 1 月 22 日
@Karim: You are defining A_i after it is used. Of course it must be defined before you can use it.
Karim Wahdan
Karim Wahdan 2021 年 1 月 22 日
編集済み: Karim Wahdan 2021 年 1 月 22 日
@Tayyab Khalil A(i_m) wont work because the matrix must be squared, when I implemented A(i_m) it now comes up with an error message saying Matrix must be squared on line 12 (minimize norm_nuc(Xe)) . So in this case would we assign a value to A_i
Karim Wahdan
Karim Wahdan 2021 年 1 月 22 日
@Jan I see, how would I define it? What code would I have to add?
Jan
Jan 2021 年 1 月 22 日
I cannot guess, what you want A_i to be.
Karim Wahdan
Karim Wahdan 2021 年 1 月 22 日
@Jan Ok I want A_i to be the value 10. How would I put this into my code and fix my "matrix needs to be squared" error
Jan
Jan 2021 年 1 月 23 日
Of course you should do this by:
A_i = 10;
Please post the complete error message and the corresponding code. I cannot guess where this error occurs.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeParticle & Nuclear Physics についてさらに検索

質問済み:

2021 年 1 月 22 日

コメント済み:

Jan
2021 年 1 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by