- X_IJ: Function definition doesn’t exist leading to ambiguous definitions of ‘xij’ and ‘seq’ vectors. Although, we shall assume them to be a sample vector data later, wherever needed.
- bar_fix: Function isn’t defined leading to invalid assignment to variables ‘a_talt’, ’ref_bar_fix’.
- Heuristic: Function definition doesn’t exist, affecting the data in ‘a_opt’, ‘ref_heuristic’.
Input arguments must be convertible to floating-point numbers
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
T=1;
N=10;
K=1000;
bar_W=20;
d=zeros(T,N,K);
mu=zeros(N,1);
for n=1:N
mu(n)=30+(60-30)*rand();
end
sigma=zeros(N,1);
for n=1:N
sigma(n)=mu(n)*0.3*rand();
end
for i=1:N
d(T,i,:)=normrnd(mu(i),sigma(i), K,1);
end
[xij,seq]=X_IJ(T,N,bar_W,mu,sigma);
[a_talt,ref_bar_fix]=bar_fix(T,N,K,d,bar_W,xij);
for i=1:N-1
a_talt_total(i)=a_talt_total(i)+a_talt(i);
end
[a_opt,ref_heuristic]=heuristic(T,N,K,d,bar_W,xij);
for i=1:N-1
a_opt_total(i)=a_opt_total(i)+a_opt(i);
end
a_halt=zeros(N-1,1);
for i=1:N-1
syms a_halt_copy
tk=0;
for k=1:K
if i==1
tk=tk+max(-(d(T,seq(i),k)-a_halt_copy),0);
else
tk=tk+max(-(bar_W+d(T,seq(i),k)-a_halt_copy),0);
end
end
a_halt_copy=solve(a_halt_copy-mu(seq(i))-sum(sum(sum(tk)))/K==0,a_halt_copy);
a_halt(i)=a_halt_copy;
end
Hi everyone, im getting this error:
Error sym/privBinaryOp (line 1032)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error sym/max (line 78)
C = privBinaryOp(X, Y, 'symobj::zipWithImplicitExpansion', 'symobj::maxComplex');
Error Gap (line 78)
tk=tk+max(-(d(T,seq(i),k)-a_halt_copy),0);
The only error is related to 'a_halt_copy'. Other part is ok. I really want to konw when I use 'max()' , how i can solve the function :
a_halt_copy-mu(seq(i))-sum(sum(sum(tk)))/K==0
I am a newer and learning knowledge about matlab. I beg for a help. This question has been bothering me for a long time. Thank you very much.
0 commentaires
Réponses (1)
Rahul
le 23 Sep 2024
Hi,
I understand that you’re trying to evaluate and solve symbolic expressions involving some variables, while applying “max” function in these expressions, although there are some unknown states in your provided code snippet:
While solving the final expression in the first loop, for ‘a_halt_copy’ variable gives an indeterminate solution or an empty symbolic variable, which observed using the given code:
T=1;
N=10;
K=1000;
bar_W=20;
d=zeros(T,N,K);
% Assuming seq to be a ones vector
seq = ones(1, N - 1);
a_halt=zeros(N-1,1);
for i=1:N-1
syms a_halt_copy
tk=0;
for k=1:K
if i==1
tk=tk+max(-(d(T,seq(i),k)-a_halt_copy),0);
else
tk=tk+max(-(bar_W+d(T,seq(i),k)-a_halt_copy),0);
end
end
% Display symbolic expression
tk
exp = a_halt_copy-mu(seq(i))-sum(sum(sum(tk)))/k;
% Plot given expression over a_halt_copy in [60, 90]
fplot(exp, [60 90])
eqn = exp==0;
a_halt_copy=solve(eqn,a_halt_copy)
a_halt(i)=a_halt_copy;
end
This happens due to the equation having no explicit solution since the equation doesn’t exactly converge to 0, which leads to an empty symbolic variable being assigned to a vector element of ‘a_halt’. This can be observed by plotting LHS of equation using “fplot” (ran in R2024a):
Moreover, the usage of “sum” function in the given code, doesn’t provide any functionality since ‘tk’ is already a symbolic expression that can’t be summed.
Instead, you can try using “vpasolve” function to calculate solution with variable arithmetic precision as mentioned in this MATLAB answer:
For more information regarding usage of “solve” or “vpasolve” functions in MATLAB, refer to the documentation links mentioned below:
0 commentaires
Voir également
Catégories
En savoir plus sur Particle & Nuclear Physics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!