Getting Subscripted assignment dimension mismatch. !!! Help Please

Hello, so my code look like this
Code Start:
%Parameters
ci = 2;
ca = 40;
cr = 1.9;
n_pre = 60;
x_pre = 3;
N = 100;
syms x ;
%Parameter to be optimized
n = 1:N ;
for i = 1 : length(n)
c = Optimal_C_Given_n_NE (ci,ca,cr,n(i),n_pre,x_pre);
%E[TC]
ETC(i) = symsum( PMF_x_n(n(i),x,n_pre,x_pre)*(ci*N+cr*(EV_U_Given_X(x,N,n(i),n_pre,x_pre)+x)),x,0,c) +...
symsum( PMF_x_n(n(i),x,n_pre,x_pre)*(ci*n+cr*x+ca*EV_U_Given_X(x,N,n(i),n_pre,x_pre)),x,0,c);
end
% code end
and i am getting this error:
"
Subscripted assignment dimension mismatch.
Error in sym/privsubsasgn (line 1107)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 944)
C = privsubsasgn(L,R,inds{:});
Error in Output (line 18)
ETC(i) = symsum( PMF_x_n(n(i),x,n_pre,x_pre)*(ci*N+cr*(EV_U_Given_X(x,N,n(i),n_pre,x_pre)+x)),x,0,c) +... "

5 Commenti

Can you also share the function Optimal_C_Given_n_NE ?
Thank you, i am trying to see how ETC change for each value of n
please find attached the matlab code.
I have not finished the code yet, but the rest is easy if i figure this one out
There is a problem in the PMF_x_n function. You try to make calculations between different variables where x is a symbolic variable and the rest of the inputs are numeric variables double type. Consider this.
Calculations between symbolic and numeric is not necessarily a problem.

Accedi per commentare.

 Risposta accettata

In
ETC(i) = symsum( PMF_x_n(n(i),x,n_pre,x_pre)*(ci*N+cr*(EV_U_Given_X(x,N,n(i),n_pre,x_pre)+x)),x,0,c) +...
symsum( PMF_x_n(n(i),x,n_pre,x_pre)*(ci*n+cr*x+ca*EV_U_Given_X(x,N,n(i),n_pre,x_pre)),x,0,c);
Your second symsum includes ci*n in the expression. n is a vector of length 100, so that second symsum is producing a vector of length 100. You are trying to store that 100 values into the single ETC(i)
If you use n(i) instead of n(i) there, then the code runs.
The output values increase rapidly from i = 42, making it difficult to see the plot. plotting log(ETC) is more interesting -- though from entry 78 onward the output is 0 so that would not show on a log plot.

1 Commento

thank you very much man, i am really embarrassed that the error turned to be a typo mistake. if you are really interested, i am reproducing a work of a really old paper on the economics of inspection with error for my master program.
thanks again

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by