problems about solve exponential function

Hi,
please have a look at a part of my code in the function maxmin0. The general idea is that I use solve to get the solution for a exponential function funcion, and then assign the solution to a variable called pf5, which is the output for maxmin0. The function runs well itself. But when I call this function in another function, it always show a error message . I am doubting it is the way I write the this function is not smart and so there is problem when it is being called...Could you help to check that?
Here is the code
if true
% p1=1-lb2-lb3;
p2=lb2;
p3=lb3;
if (d2(i,3)==d2(i,1))
pf5(2,i)=[0;0];
eu(i)=-Inf;
else
coef1=d1(i,1)+(d1(i,1)-d1(i,3))*d2(i,1)/(d2(i,3)-d2(i,1));
coef2=d1(i,2)+(d1(i,1)-d1(i,3))*d2(i,2)/(d2(i,3)-d2(i,1));
coef3=d1(i,3)+(d1(i,1)-d1(i,3))*d2(i,3)/(d2(i,3)-d2(i,1));
syms x
f5=simplify(p1*coef1*exp(-r*coef1*x)+p2*coef2*exp(-r*coef2*x)+p3*coef3*exp(-r*coef3*x));
y5(i)=solve(f5,x);
pf5(1,i)=double(y5(i));
end
and here is the error message
Warning: Explicit solution could not be found.
> In solve at 169
In maxmin0 at 138
In maxmin at 15
In beta at 18
In C:\Program Files\MATLAB\R2012a\toolbox\shared\optimlib\finDiffEvalAndChkErr.p>finDiffEvalAndChkErr at 26
In C:\Program Files\MATLAB\R2012a\toolbox\shared\optimlib\finitedifferences.p>finitedifferences at 128
In C:\Program Files\MATLAB\R2012a\toolbox\optim\optim\private\computeFinDiffGradAndJac.p>computeFinDiffGradAndJac at 28
In C:\Program Files\MATLAB\R2012a\toolbox\optim\optim\barrier.p>barrier at 135
In fmincon at 841
In main at 6
Error using mupadmex
Error in MuPAD command: Subscripted assignment dimension mismatch
Error in sym/subsasgn (line 1638)
C = mupadmex('symobj::subsasgn',A.s,B.s,inds{:});
Error in maxmin0 (line 138)
y5(i)=solve(f5,x);
Error in maxmin (line 15)
[PF0,eu0]=maxmin0(sub,DD);
Error in beta (line 18)
mu = maxmin(sub,DD);
Error in C:\Program Files\MATLAB\R2012a\toolbox\shared\optimlib\finDiffEvalAndChkErr.p>finDiffEvalAndChkErr (line 26)
Error in C:\Program Files\MATLAB\R2012a\toolbox\shared\optimlib\finitedifferences.p>finitedifferences (line 128)
Error in C:\Program Files\MATLAB\R2012a\toolbox\optim\optim\private\computeFinDiffGradAndJac.p>computeFinDiffGradAndJac (line 28)
Error in C:\Program Files\MATLAB\R2012a\toolbox\optim\optim\barrier.p>barrier (line 135)
Error in fmincon (line 841)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in main (line 6)
[x,fval,exitflag,output,lambda,grad] = fmincon(@beta,[0.2,0.2,0.2,0.01,20,0.1,20,0.1],A,b,[],[],lb,ub,[],options)

4 comentarios

xueqi
xueqi el 13 de Feb. de 2013
Editada: xueqi el 13 de Feb. de 2013
and it is also weird that I dont have this error (but the whole program still doesn't work )showing when I run the program in matlab 2010 but in 2012 there shows this error. So I think it might be the reason that the whole program doesn't work...
Walter Roberson
Walter Roberson el 15 de Feb. de 2013
At the point of the solve(), could you show us what f5 is? I want to check for solutions myself.
xueqi
xueqi el 16 de Feb. de 2013
Hi do you mean the explicit expression for f5? The expression depends on the input of the function, and this error shows when the function in called in an optimization routine. So I cant know the exact input either... PS I have made the imrovement that add in if (isempty(y)==1) PF(i,1)=0; else PF(i,1)=double(y); end But this similar error still show!!!And this time it is 2010 shows this message...
TUHAME STEVEN
TUHAME STEVEN el 28 de Oct. de 2015
it is fine thank you

Iniciar sesión para comentar.

 Respuesta aceptada

Carlos
Carlos el 14 de Feb. de 2013
Editada: Walter Roberson el 14 de Feb. de 2013
When you execute this code in Matlab
>> syms x;
>> f=-10*exp(-x);
>> solve(f,x)
>> isempty(a)
ans =
1
Whereas if you execute this code
>> syms x;
>> f=x^2-4
>> solve(f,x)
>> isempty(a)
ans =
0
You can use the isempty command. If isempty returns true (1), it means your roots array is empty because there are no roots.

4 comentarios

xueqi
xueqi el 15 de Feb. de 2013
Hi, it is a pity I make the change and it still has the same error message. And it is still wired that the error message only exists in matlab 2012 version...Please help understand why... The problem is even there is no such error msg in matlab 2010, the programs still doesnt work...I use multistart for fmincon, and it just keeps going and never stops...I am just trying to find out where is the problem....
yes a=solve(f,x),just to find out if the string is empty (which means matlab is unable to solve because the equation cannot be solved)
xueqi
xueqi el 18 de Feb. de 2013
Editada: xueqi el 18 de Feb. de 2013
Hi, I have add in this bit in my code, it still shows me the same message. Can you think of the reason? Also can you go to my question here http://www.mathworks.com/matlabcentral/answers/63963-problems-about-solve-exponential-function
Carlos
Carlos el 19 de Feb. de 2013
Sorry, I cannot figure out the reason for different behaivours in different versions.

Iniciar sesión para comentar.

Más respuestas (1)

Carlos
Carlos el 13 de Feb. de 2013
Editada: Walter Roberson el 14 de Feb. de 2013
In the warning message displayed by Matlab it says no solution has been found(just as it happens if the function has no roots), and exp(-ax) has no roots, this is what happens when I try the following code in Matlab
>> syms x;
>> f=-10*exp(-x);
>> solve(f,x)
Warning: Explicit solution could not be found.
> In solve at 81
ans =
[ empty sym ]
However if there is no problem with Matlab 2010 this might not be the case, I just wanted you to consider the possibility the function has no roots.

1 comentario

xueqi
xueqi el 13 de Feb. de 2013
Yes I begin to think it may be the problems. So I think it would be better if I modify the code so that pf=0 if there is no solution. Could you offer any advice how to say 'if there is no solution' into matlab lauguage?

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 13 de Feb. de 2013

Comentada:

el 28 de Oct. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by