Error using symengine. Either base or exponent must be a scalar.

10 visualizzazioni (ultimi 30 giorni)
I got this error when running an iterating program on a distribution function.
ans =
logical
1
ans =
logical
1
Error using symengine
Either base or exponent must be a scalar.
Error in sym/privBinaryOp (line 1030)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in ^ (line 330)
B = privBinaryOp(A, p, 'symobj::mpower');
Error in researcheff (line 13)
y1=(valueadd/w/alpha)^(1/(beta-1));
Error in viterate (line 32)
x1=researcheff(v,I,Im,P,f,Q,w,mb1,mb2);
Error in patentsim (line 88)
[v1,A1,G1,moment1] = viterate(v0,A0,G0,f);
The strange thing is I used isscalar function to check both the base and the exponent, which turns out that they are both scalar (the first two lines are the results for the check). The program goes as follow
function y=researcheff(v,I,Im,P,f,Q,w,mb1,mb2)
global lambda;
global alpha;
global beta;
global theta;
syms mu a w r na nb1 nb2;
va1= (I*subs(v,mu,mu*lambda^a)+(1-I)*(Q+v))*f;
va2= mb1*(Im*(subs(v,mu,mu*lambda^a)-P)+(1-I)*v)*f;
va= va1-va2;
valueadd=int(va,a,[0 1]);
isscalar(valueadd/w/alpha)
isscalar(1/(beta-1))
y1=(valueadd/w/alpha)^(1/(beta-1));
va2= mb2*(Im*(subs(v,mu,mu*lambda^a)-P)+(1-I)*v)*f;
va= va1-va2;
valueadd=int(va,a,[0 1]);
y2=(valueadd*mu^theta/w/alpha)^(1/(beta-1));
y= piecewise(mu>=1, y1, (0<mu)&(mu<1), y2, 0);
end
I don't know if it helps but to clarify the variables a litte, v,I,Im,P are some functions on the 7 variables after syms; f is a distribution function; Q and w are supposed to be two scalars; mb1 and mb2 are two matching probability functions concerning na, nb1 and nb2.
  5 Commenti
Shunhao Huang
Shunhao Huang il 17 Giu 2020
w is a 1x1 symbolic variable which will be solved by an equation concerning this researcheff function. Alpha is a parameter. I'm optimizing a function of those parameters. Here va1 and va2 are supposed to be symbolic functions of mu, a, w, r, na, nb1 and nb2. So does this valueadd. The variable calling this researcheff function goes somewhat as follow
syms M(mu,a,w,r,na,nb1,nb2);
M(mu,a,w,r,na,nb1,nb2)=na^tau*(eta1*nb1+eta2*nb2)^(1-tau);
ma1=M/na*eta1*nb1/(eta1*nb1+eta2*nb2);
ma2=M/na*eta2*nb2/(eta1*nb1+eta2*nb2);
mb1=M/nb1*eta1*nb1/(eta1*nb1+eta2*nb2);
mb2=M/nb2*eta1*nb1/(eta1*nb1+eta2*nb2);
syms P(mu,a,w,r,na,nb1,nb2);
P(mu,a,w,r,na,nb1,nb2)=saleprice(v,A);
syms Im(mu,a,w,r,na,nb1,nb2);
Im(mu,a,w,r,na,nb1,nb2)=purchastrategy(v,P);
syms Q(mu,a,w,r,na,nb1,nb2);
Q(mu,a,w,r,na,nb1,nb2)=patentprice(Im,P,G,A,f,ma1,ma2);
syms I(mu,a,w,r,na,nb1,nb2);
I(mu,a,w,r,na,nb1,nb2)=keepstratege(v,Q);
syms x1(mu,a,w,r,na,nb1,nb2);
x1(mu,a,w,r,na,nb1,nb2)=researcheff(v,I,Im,P,f,Q,w,mb1,mb2);
Shunhao Huang
Shunhao Huang il 17 Giu 2020
I just found a way to avoid the error. I used the following expression to compute y1 and y2, and the error just disappeared:
y1 = exp((1/(beta-1))*log(valueadd/w/alpha));
I guess maybe matlab didn't interpret that ^ as a exponential function in the symbolic case. Not sure if that makes sense.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by