I made up some input data in the first line, and then ran the following in CVX Version 2.1 Build 1117.

```
>> K=3; M_T=3; E_theta1=randn(3); phi=2;
>> cvx_begin
>> variable R(M_T, M_T) semidefinite
>> for i = 1 : K
>> Designed_beam(i) = E_theta1(:,i)'*R*E_theta1(:,i);
>> end
>> cost_func = sum_square(Designed_beam - phi)
cost_func =
cvx convex expression (scalar)
```

Does this work for you? If so, what is the difference between this and what you ran which resulted in the error message?

Note that removing the semicolon from

`Designed_beam(i) = E_theta1(:,i)'*R*E_theta1(:,i)`

produces the output

```
Designed_beam =
cvx real affine expression (scalar)
Designed_beam =
cvx real affine expression (1x2 vector)
Designed_beam =
cvx real affine expression (1x3 vector)
```

So why isn’t your `Designed_beam - phi`

real and affine?