Prev: Sine Curve Fit to Data
Next: Chemical Markup Language
From: Kittithad Wangveerathananon on 10 Aug 2010 11:15 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.
From: Andy on 10 Aug 2010 11:23 "Kittithad Wangveerathananon" <kittithad(a)startfromyou.com> wrote in message <i3rqe8$f6h$1(a)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?
From: Kittithad Wangveerathananon on 10 Aug 2010 11:25 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i3rqso$e5k$1(a)fred.mathworks.com>... > "Kittithad Wangveerathananon" <kittithad(a)startfromyou.com> wrote in message <i3rqe8$f6h$1(a)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 )
From: Kittithad Wangveerathananon on 10 Aug 2010 11:29 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i3rqso$e5k$1(a)fred.mathworks.com>... > "Kittithad Wangveerathananon" <kittithad(a)startfromyou.com> wrote in message <i3rqe8$f6h$1(a)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.
From: Kittithad Wangveerathananon on 10 Aug 2010 11:32
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) |