# Error using max(a,0) function in CVX

Hello Mark, I have a question, could you help me?
When I use the max(a,0) function in CVX has an error in Matlab. For example, b = max(a,0).

As shown in this

figure, the energy matrix is not equal to max (Vz, 0).
I’m looking forward to your reply, have a nice day!

Please post your complete program by copy and paste into your post , using the Preformatted text icon, (6th icon from left at top of posting box, not posting an image.

Dear Mark, thanks for your help! There has a question is that the `energy` is totally different from the results of `max(Vz,0)` in `energy = max(Vz,0)`. The code I used is as following
`cvx_begin variable objective variables Z1(1,N) Vz(1,N-1) f(K,N) f_u(K,N) expression Ec expression energy energy = max(Vz,0); Ec = deta_t*G*sum(energy); minimize ( objective ) subject to deta_t.*P1.*sum(sum(assignment1))+deta_t*sum(sum(smallk*pow_p(f,3)))<= objective; theta_k <= (180/pi)*v_lb; f >= 0; f <= f_kmax; f_u >= 0; sum(f_u,1) <= ones(1,N)* f_umax; sum(f,2)+sum(f_u(:,2:N),2) >= input_data; for n = 2: N sum(assignment1(:,1:n-1).*r_lb(:,1:n-1),2) >= sum(f_u(:,2:n),2); end r_lb >= 0; for i = 1: N-1 %%（4-1=3 Z1(1,i+1) - Z1(1,i)==Vz(1,i)*deta_t; abs(Vz(1,i)) <= Vzmax; end Z1(1,1) == Z1(1,N); Hmin <= Z1; Z1 <= Hmax; cvx_end`

The results of these two parts are

`energy = 1.0e+06 *[4.2600 4.2600 4.2600 4.2600 4.2600 4.2600 4.2600 4.2600 4.2600 4.2600 ... 4.2600]` A matrix of 39 columns per row

but the

`max(Vz,0) = [0.0000 0.0000 0 0.0000 0.0000 0.0000 0 0 0 0.0000 0 0.0002 0.0001 0.0001 0.0000 0.0000 0 0.0001 0 0 0 0 0 0.0959 0.8115 4.6204 0 0 3.7189 0.0000 0.0000 0.0000 0.0000 0.0000 0 0 0 0.7121 4.6351]` A matrix of 39 columns per row

Thanks again for your help!

I have no idea what any of this is. You should start with a simplified model. get that right. Then build up to the more complicated model you want.

Okay, I’ll use a simple model for testing. Thanks, Mark, have a nice day.