Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Easy question

Subject: Easy question

From: Kittithad Wangveerathananon

Date: 10 Aug, 2010 15:15:20

Message: 1 of 8

i just have a quick and easy problem. I use the function solve in matlab and it return the numerical value that is not yet completely computedm such as 5-4*(3210*7), something like that. I kept this value into a variable, says A. The I have the commandif ( A <=0 )...endand it shows the error about lt....Do I have to compute A first, and what is the matlab function that can do the job for me.Thanks in advance.

Subject: Easy question

From: Andy

Date: 10 Aug, 2010 15:23:04

Message: 2 of 8

"Kittithad Wangveerathananon" <kittithad@startfromyou.com> wrote in message <i3rqe8$f6h$1@fred.mathworks.com>...
> i just have a quick and easy problem. I use the function solve in matlab and it return the numerical value that is not yet completely computedm such as 5-4*(3210*7), something like that. I kept this value into a variable, says A. The I have the commandif ( A <=0 )...endand it shows the error about lt....Do I have to compute A first, and what is the matlab function that can do the job for me.Thanks in advance.

What is the error shown? Is solve returning a complex value, perhaps?

Subject: Easy question

From: Kittithad Wangveerathananon

Date: 10 Aug, 2010 15:25:20

Message: 3 of 8

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i3rqso$e5k$1@fred.mathworks.com>...
> "Kittithad Wangveerathananon" <kittithad@startfromyou.com> wrote in message <i3rqe8$f6h$1@fred.mathworks.com>...
> > i just have a quick and easy problem. I use the function solve in matlab and it return the numerical value that is not yet completely computedm such as 5-4*(3210*7), something like that. I kept this value into a variable, says A. The I have the commandif ( A <=0 )...endand it shows the error about lt....Do I have to compute A first, and what is the matlab function that can do the job for me.Thanks in advance.
>
> What is the error shown? Is solve returning a complex value, perhaps?

Here are the error

??? Error using ==> sym.sym>notimplemented
at 2514
Function 'le' is not implemented for MuPAD
symbolic objects.

Error in ==> sym.sym>sym.le at 825
            notimplemented('le');

Error in ==> sss at 114
    if ( chk <= 0 )
 

Subject: Easy question

From: Kittithad Wangveerathananon

Date: 10 Aug, 2010 15:29:04

Message: 4 of 8

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i3rqso$e5k$1@fred.mathworks.com>...
> "Kittithad Wangveerathananon" <kittithad@startfromyou.com> wrote in message <i3rqe8$f6h$1@fred.mathworks.com>...
> > i just have a quick and easy problem. I use the function solve in matlab and it return the numerical value that is not yet completely computedm such as 5-4*(3210*7), something like that. I kept this value into a variable, says A. The I have the commandif ( A <=0 )...endand it shows the error about lt....Do I have to compute A first, and what is the matlab function that can do the job for me.Thanks in advance.
>
> What is the error shown? Is solve returning a complex value, perhaps?

for some parameters the solve returns the real number.
for some parameters the solve returns the complex, which i use the function imag(A) to check and cut the complex answer out.

Subject: Easy question

From: Kittithad Wangveerathananon

Date: 10 Aug, 2010 15:32:05

Message: 5 of 8

Here are my code, the problem located in at the end in the for loop.Thanks in advance. Appreciate every help.

clear al;
syms phi mew

%Define parameters
aL=0.1;
aLr=0;
aH=1;
aHr=1;
nL=0.1;
nH=1;
d0=1;
d=d0*aL*nL;
dg=d;
Ez=1/d;
Ezg=1/dg;
tax=0.3;
gamma=0.5;
N0H=0.5;
N0L=1-N0H;
g=(nH-nL)/gamma;
N1H=N0H;
N1L=1-N1H;

%Compute endo vars
w3L=(1/2*(1-tax))*((1-tax)*aL*nL+mew);
w2H=(1/2*(1-tax))*((1-tax)*aHr*nH+mew);
w3H=(1/2*(1-tax))*((1-tax)*aH*nH+mew);

j=Ezg*(phi-mew);
s3L=Ez*((1-tax)*w3L-mew);
s2H=Ez*((1-tax)*w2H-mew);
s3H=Ez*((1-tax)*w3H-mew);

%number of low
NLJS=N1L*j*s3H;
NLJQ=N1L*j*(1-s3H);
NLQS=N1L*(1-j)*s3L;
NLQQ=N1L*(1-j)*(1-s3L);
%number of high
NHSS=N1H*s2H*s3H;
NHSQ=N1H*s2H*(1-s3H);
NHQS=N1H*(1-s2H)*s3H;
NHQQ=N1H*(1-s2H)*(1-s3H);

%spending of low
SLJS=phi+g;
SLJQ=phi+g+mew;
SLQS=mew;
SLQQ=mew+mew;
%spending of high
SHSS=0;
SHSQ=mew;
SHQS=mew;
SHQQ=mew+mew;

%rev of low
RLJS=tax*w3H;
RLJQ=0;
RLQS=tax*w3L;
RLQQ=0;
%rev of high
RHSS=tax*w2H+tax*w3H;
RHSQ=tax*w2H;
RHQS=tax*w3H;
RHQQ=0;

TS=(NLJS*SLJS+NLJQ*SLJQ+NLQS*SLQS+NLQQ*SLQQ)+(NHSS*SHSS+NHSQ*SHSQ+NHQS*SHQS+NHQQ*SHQQ);
TR=(NLJS*RLJS+NLJQ*RLJQ+NLQS*RLQS+NLQQ*RLQQ)+(NHSS*RHSS+NHSQ*RHSQ+NHQS*RHQS+NHQQ*RHQQ);

%firm's profitax from low
FLJS=(aH*nH-w3H);
FLJQ=0;
FLQS=(aL*nL-w3L);
FLQQ=0;
%firm's profitax from high
FHSS=(aHr*nH-w2H)+(aH*nH-w3H);
FHSQ=(aHr*nH-w2H);
FHQS=(aH*nH-w3H);
FHQQ=0;

w=(NLJS*FLJS+NLJQ*FLJQ+NLQS*FLQS+NLQQ*FLQQ)+(NHSS*FHSS+NHSQ*FHSQ+NHQS*FHQS+NHQQ*FHQQ);

%payoff of low
PLJS=w+(phi-Ezg)+((1-tax)*w3H-Ez);
PLJQ=w+(phi-Ezg)+mew;
PLQS=w+mew+((1-tax)*w3L-Ez);
PLQQ=w+mew+mew;
%payoff of high
PHSS=w+((1-tax)*w2H-Ez)+((1-tax)*w3H-Ez);
PHSQ=w+((1-tax)*w2H-Ez)+mew;
PHQS=w+mew+((1-tax)*w3H-Ez);
PHQQ=w+mew+mew;

swf = ((NLJS*PLJS+NLJQ*PLJQ+NLQS*PLQS+NLQQ*PLQQ)+(NHSS*PHSS+NHSQ*PHSQ+NHQS*PHQS+NHQQ*PHQQ));


%begin plot
phii=0:1:100;
TSsubmewplot=0:1:100;
TRsubmewplot=0:1:100;
swfplot=0:1:100;

for i=0:1:100
    mewi=((1-tax)*d/100)*i;
    TSsubmew=subs(TS,mew,mewi);
    TRsubmew=subs(TR,mew,mewi);
    A=solve(TSsubmew-TRsubmew)
    %chk real
    if (imag(A(2)) ~= 0)
        i=100;
    end;
    %chk phi>mew
    chk=A(2)-mewi;
    if ( chk <= 0 )
        i=100;
    end;
    phii(i+1)=A(2);
    TSsubmewplot(i+1)=subs(TSsubmew,phi,A(2));
    TRsubmewplot(i+1)=subs(TRsubmew,phi,A(2));
    swfplot(i+1)=subs(swf,{mew,phi},{mewi,A(2)});
end;

mewi=0:(1-tax)*d/100:(1-tax)*d;

plot(mewi, phii);
title('Constraint')
xlabel('0 \leq \mu \leq (1- \tau)\delta')
ylabel('\phi')

hold on

inequalcon=phii-mewi-dg;
plot(mewi, inequalcon,'Color','red');

%s=plot(mewi, swfplot);set(s,'Color','yellow','LineWidth',2)

plot(mewi, TSsubmewplot,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
p=plot(mewi, TRsubmewplot);set(p,'Color','red','LineWidth',2)

Subject: Easy question

From: Andy

Date: 10 Aug, 2010 15:35:06

Message: 6 of 8

Well, the error message is clear. Your expression is a symbolic expression, and it doesn't make sense to ask if one symbol is less than another. You need to convert your symbols to doubles before comparing them.

Subject: Easy question

From: Kittithad Wangveerathananon

Date: 10 Aug, 2010 15:54:04

Message: 7 of 8

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i3rrja$sr7$1@fred.mathworks.com>...
> Well, the error message is clear. Your expression is a symbolic expression, and it doesn't make sense to ask if one symbol is less than another. You need to convert your symbols to doubles before comparing them.

Wow, I never know about the function double before. Where does its name come from? I'm confues that it is all numbers, though still with operators included, but no symbols in the expression. Why it is regarded as a symbolic?

Anyway, it works when applying double(), thanks for the tip.
Your help is highly appreciated.

Subject: Easy question

From: Steven_Lord

Date: 10 Aug, 2010 17:26:18

Message: 8 of 8



"Kittithad Wangveerathananon" <kittithad@startfromyou.com> wrote in message
news:i3rsms$a7p$1@fred.mathworks.com...
> "Andy " <myfakeemailaddress@gmail.com> wrote in message
> <i3rrja$sr7$1@fred.mathworks.com>...
>> Well, the error message is clear. Your expression is a symbolic
>> expression, and it doesn't make sense to ask if one symbol is less than
>> another. You need to convert your symbols to doubles before comparing
>> them.
>
> Wow, I never know about the function double before. Where does its name
> come from? I'm confues that it is all numbers, though still with operators
> included, but no symbols in the expression. Why it is regarded as a
> symbolic?

Because that's what SOLVE returns. You can have a sym object that contains
no symbolic variables at all, and that's perfectly valid.

two = sym(2);

This is useful for many reasons, one of which is computing large values
without losing precision due to an intermediate result being stored in
double.

twoTo1500 = two^1500
twoTo1500Double = sym(2^1500)

The former performs the calculation symbolically, while the latter performs
the calculation numerically (which overflows to Inf) and converts that Inf
result into a symbolic object.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us