当前位置: 首页 > 工具软件 > Sym > 使用案例 >

matlab的sym不可用,关于"无法从 sym 转换为 logical"的问题

赵锐
2023-12-01

clear,clcsigma=5;psi=0.94;Y0=0.7;T=1.2;miu1=0.083;miu2=0.088;miu3=0.094;alfa0=0.5;K=1;

Li=linspace(1,3,100);

alfa11=0.042;alfa12=0.049;alfa13=0.056;

alfa21=0.038;alfa22=0.045;alfa23=0.051;

alfa31=0.035;alfa32=0.041;alfa33=0.047;

len=length(Li);

lamdar1=0.3*ones(1,len);lamdar2=0.3*ones(1,len);lamdar3=0.3*ones(1,len);

lamdas1=0*ones(1,len);lamdas2=0*ones(1,len);lamdas3=0*ones(1,len);

lamdat1=0*ones(1,len);lamdat2=0*ones(1,len);lamdat3=0*ones(1,len);

lamdar1old=0*ones(1,len);lamdar2old=0*ones(1,len);lamdar3old=0*ones(1,len);

lamdas1old=1*ones(1,len);lamdas2old=1*ones(1,len);lamdas3old=1*ones(1,len);

lamdat1old=1*ones(1,len);lamdat2old=1*ones(1,len);lamdat3old=1*ones(1,len);

lamdar0=1-lamdar1-lamdar2-lamdar3;

lamdas0=1-lamdas1-lamdas2-lamdas3;

lamdat0=1-lamdat1-lamdat2-lamdat3;

syms gr1vv gr2vv gr3vv gs1vv gs2vv gs3vv gt1vv gt2vv gt3vv

upr1=abs(lamdar1-lamdar0)./lamdar1>0.00001;upr2=abs(lamdar2-lamdar0)./lamdar2>0.00001;upr3=abs(lamdar3-lamdar0)./lamdar3>0.00001;ups1=abs(lamdas1-lamdas0)./lamdas1>0.00001;ups2=abs(lamdas2-lamdas0)./lamdas2>0.00001;ups3=abs(lamdas3-lamdas0)./lamdas3>0.00001;upt1=abs(lamdat1-lamdat0)./lamdat1>0.00001;upt2=abs(lamdat2-lamdat0)./lamdat2>0.00001;upt3=abs(lamdat3-lamdat0)>0.00001;aa=1;

while upr1(aa)||upr2(aa)||upr3(aa)||ups1(aa)||ups2(aa)||ups3(aa)||upt1(aa)||upt2(aa)||upt3(aa)||aa>length(upr1)

lamdar1old=lamdar1;lamdar2old=lamdar2;lamdar3old=lamdar3;

lamdas1old=lamdas1;lamdas2old=lamdas2;lamdas3old=lamdas3;

lamdat1old=lamdat1;lamdat2old=lamdat2;lamdat3old=lamdat3;

lamdar0=1-lamdar1-lamdar2-lamdar3;

lamdas0=1-lamdas1-lamdas2-lamdas3;

lamdat0=1-lamdat1-lamdat2-lamdat3;

omegar1=1*ones(1,len);

omegar2=1*ones(1,len);

omegar3=1*ones(1,len);

omegas1=1*ones(1,len);

omegas2=1*ones(1,len);

omegas3=1*ones(1,len);

omegat1=1*ones(1,len);

omegat2=1*ones(1,len);

omegat3=1*ones(1,len);

omegar1old=0*ones(1,len);

omegar2old=0*ones(1,len);

omegar3old=0*ones(1,len);

omegas1old=0*ones(1,len);

omegas2old=0*ones(1,len);

omegas3old=0*ones(1,len);

omegat1old=0*ones(1,len);

omegat2old=0*ones(1,len);

omegat3old=0*ones(1,len);

omegar0=(1-lamdar1-lamdar2-lamdar3).^(psi-1);

omegas0=(1-lamdas1-lamdas2-lamdas3).^(psi-1);

omegat0=(1-lamdat1-lamdat2-lamdat3).^(psi-1);

valr1=abs(omegar1-omegar1old)./omegar1>0.00001;valr2=abs(omegar2-omegar2old)./omegar2>0.00001;valr3=abs(omegar3-omegar3old)./omegar3>0.00001;vals1=abs(omegas1-omegas1old)./omegas1>0.00001;vals2=abs(omegas2-omegas2old)./omegas2>0.00001;vals3=abs(omegas3-omegas3old)./omegas3>0.00001;valt1=abs(omegat1-omegat1old)./omegat2>0.00001;valt2=abs(omegat2-omegat2old)./omegat2>0.00001;valt3=abs(omegat3-omegat3old)./omegat3>0.00001;ii=1;

while(valr1(ii)&&valr2(ii)&&valr3(ii)&&vals1(ii)&&vals2(ii)&&vals3(ii)&&valt1(ii)&&valt2(ii)&&valt3(ii)||ii>length(valr1))

omegar1old=omegar1;

omegar2old=omegar2;

omegar3old=omegar3;

omegas1old=omegas1;

omegas2old=omegas2;

omegas3old=omegas3;

omegat1old=omegat1;

omegat2old=omegat2;

omegat3old=omegat3;

Yr=(Li.*omegar1.*lamdar1)+(Li.*omegar2.*lamdar2)+(Li.*omegar3.*lamdar3)+(Li.*((lamdar0/K).^psi))./psi;

Ys=(Li.*omegas1.*lamdas1)+(Li.*omegas2.*lamdas2)+(Li.*omegas3.*lamdas3)+(Li.*((lamdas0/K).^psi))./psi;

Yt=(Li.*omegat1.*lamdat1)+(Li.*omegat2.*lamdat2)+(Li.*omegat3.*lamdat3)+(Li.*((lamdat0/K).^psi))./psi;

Er1=miu1.*(Yr-Y0)+(Li.*lamdar1.*omegar1.*alfa11/alfa0)+(Li.*lamdar2.*omegar2.*alfa12./alfa0)+(Li.*lamdar3.*omegar3.*alfa13./alfa0);

Er2=miu1.*(Yr-Y0)+(Li.*lamdar1.*omegar1.*alfa21/alfa0)+(Li.*lamdar2.*omegar2.*alfa22./alfa0)+(Li.*lamdar3.*omegar3.*alfa23./alfa0);

Er3=miu1.*(Yr-Y0)+(Li.*lamdar1.*omegar1.*alfa31/alfa0)+(Li.*lamdar2.*omegar2.*alfa32./alfa0)+(Li.*lamdar3.*omegar3.*alfa33./alfa0);

Es1=miu1.*(Yr-Y0)+(Li.*lamdas1.*omegas1.*alfa11/alfa0)+(Li.*lamdas2.*omegas2.*alfa12./alfa0)+(Li.*lamdas3.*omegas3.*alfa13./alfa0);

Es2=miu1.*(Yr-Y0)+(Li.*lamdas1.*omegas1.*alfa21/alfa0)+(Li.*lamdas2.*omegas2.*alfa22./alfa0)+(Li.*lamdas3.*omegas3.*alfa23./alfa0);

Es3=miu1.*(Yr-Y0)+(Li.*lamdas1.*omegas1.*alfa31/alfa0)+(Li.*lamdas2.*omegas2.*alfa32./alfa0)+(Li.*lamdas3.*omegas3.*alfa33./alfa0);

Et1=miu1.*(Yr-Y0)+(Li.*lamdat1.*omegat1.*alfa11/alfa0)+(Li.*lamdat2.*omegat2.*alfa12./alfa0)+(Li.*lamdat3.*omegat3.*alfa13./alfa0);

Et2=miu1.*(Yr-Y0)+(Li.*lamdat1.*omegat1.*alfa21/alfa0)+(Li.*lamdat2.*omegat2.*alfa22./alfa0)+(Li.*lamdat3.*omegat3.*alfa23./alfa0);

Et3=miu1.*(Yr-Y0)+(Li.*lamdat1.*omegat1.*alfa31/alfa0)+(Li.*lamdat2.*omegat2.*alfa32./alfa0)+(Li.*lamdat3.*omegat3.*alfa33./alfa0);

Ar1=Li.*lamdar1.*((omegar1).^(1-sigma*alfa0));

Ar2=Li.*lamdar2.*((omegar2).^(1-sigma*alfa0));

Ar3=Li.*lamdar3.*((omegar3).^(1-sigma*alfa0));

As1=Li.*lamdas1.*((omegas1).^(1-sigma*alfa0));

As2=Li.*lamdas2.*((omegas2).^(1-sigma*alfa0));

As3=Li.*lamdas3.*((omegas3).^(1-sigma*alfa0));

At1=Li.*lamdat1.*((omegat1).^(1-sigma*alfa0));

At2=Li.*lamdat2.*((omegat2).^(1-sigma*alfa0));

At3=Li.*lamdat3.*((omegat3).^(1-sigma*alfa0));

lnAr1=log(Ar1);lnAr2=log(Ar2);lnAr3=log(Ar3);

lnAs1=log(As1);lnAs2=log(As2);lnAs3=log(As3);

lnAt1=log(At1);lnAt2=log(At2);lnAt3=log(At3);

for vv=1:100

eval(['Ar1',num2str(vv),'=','Ar1(1,vv)']);

eval(['Ar2',num2str(vv),'=','Ar2(1,vv)']);

eval(['Ar3',num2str(vv),'=','Ar3(1,vv)']);

eval(['As1',num2str(vv),'=','As1(1,vv)']);

eval(['As2',num2str(vv),'=','As2(1,vv)']);

eval(['As3',num2str(vv),'=','As3(1,vv)']);

eval(['At1',num2str(vv),'=','At1(1,vv)']);

eval(['At2',num2str(vv),'=','At2(1,vv)']);

eval(['At3',num2str(vv),'=','At3(1,vv)']);

fnr1=(gr1vv.^(1-sigma))-Ar1.*(gr1vv.^(-sigma*alfa11)).*(gr2vv.^(-sigma*alfa21)).*(gr3vv.^(-sigma*alfa31))-As1.*(T.^(1-sigma)).*(gs1vv.^(-sigma*alfa11)).*(gs2vv.^(-sigma*alfa21)).*(gs3vv.^(-sigma*alfa31))-At1.*(T.^(1-sigma)).*(gt1vv.^(-sigma*alfa11)).*(gt2vv.^(-sigma*alfa21)).*(gt3vv.^(-sigma*alfa31))==0;

fnr2=(gr2vv.^(1-sigma))-Ar2.*(gr1vv.^(-sigma*alfa12)).*(gr2vv.^(-sigma*alfa22)).*(gr3vv.^(-sigma*alfa32))-As2.*(T.^(1-sigma)).*(gs1vv.^(-sigma*alfa12)).*(gs2vv.^(-sigma*alfa22)).*(gs3vv.^(-sigma*alfa32))-At2.*(T.^(1-sigma)).*(gt1vv.^(-sigma*alfa12)).*(gt2vv.^(-sigma*alfa22)).*(gt3vv.^(-sigma*alfa32))==0;

fnr3=(gr3vv.^(1-sigma))-Ar3.*(gr1vv.^(-sigma*alfa13)).*(gr2vv.^(-sigma*alfa23)).*(gr3vv.^(-sigma*alfa33))-As2.*(T.^(1-sigma)).*(gs1vv.^(-sigma*alfa13)).*(gs2vv.^(-sigma*alfa23)).*(gs3vv.^(-sigma*alfa33))-At2.*(T.^(1-sigma)).*(gt1vv.^(-sigma*alfa13)).*(gt2vv.^(-sigma*alfa23)).*(gt3vv.^(-sigma*alfa33))==0;

fns1=(gs1vv.^(1-sigma))-Ar1.*(T.^(1-sigma)).*(gr1vv.^(-sigma*alfa11)).*(gr2vv.^(-sigma*alfa21)).*(gr3vv.^(-sigma*alfa31))-As1.*(gs1vv.^(-sigma*alfa11)).*(gs2vv.^(-sigma*alfa21)).*(gs3vv.^(-sigma*alfa31))-At1.*(T.^(1-sigma)).*(gt1vv.^(-sigma*alfa11)).*(gt2vv.^(-sigma*alfa21)).*(gt3vv.^(-sigma*alfa31))==0;

fns2=(gs2vv.^(1-sigma))-Ar2.*(T.^(1-sigma)).*(gr1vv.^(-sigma*alfa12)).*(gr2vv.^(-sigma*alfa22)).*(gr3vv.^(-sigma*alfa32))-As2.*(gs1vv.^(-sigma*alfa12)).*(gs2vv.^(-sigma*alfa22)).*(gs3vv.^(-sigma*alfa32))-At2.*(T.^(1-sigma)).*(gt1vv.^(-sigma*alfa12)).*(gt2vv.^(-sigma*alfa22)).*(gt3vv.^(-sigma*alfa32))==0;

fns3=(gs3vv.^(1-sigma))-Ar3.*(T.^(1-sigma)).*(gr1vv.^(-sigma*alfa13)).*(gr2vv.^(-sigma*alfa23)).*(gr3vv.^(-sigma*alfa33))-As3.*(gs1vv.^(-sigma*alfa13)).*(gs2vv.^(-sigma*alfa23)).*(gs3vv.^(-sigma*alfa33))-At3.*(T.^(1-sigma)).*(gt1vv.^(-sigma*alfa13)).*(gt2vv.^(-sigma*alfa23)).*(gt3vv.^(-sigma*alfa33))==0;

fnt1=(gt1vv.^(1-sigma))-Ar1.*(T.^(1-sigma)).*(gr1vv.^(-sigma*alfa11)).*(gr2vv.^(-sigma*alfa21)).*(gr3vv.^(-sigma*alfa31))-As1.*(T.^(1-sigma)).*(gs1vv.^(-sigma*alfa11)).*(gs2vv.^(-sigma*alfa21)).*(gs3vv.^(-sigma*alfa31))-At1.*(gt1vv.^(-sigma*alfa11)).*(gt2vv.^(-sigma*alfa21)).*(gt3vv.^(-sigma*alfa31))==0;

fnt2=(gt2vv.^(1-sigma))-Ar2.*(T.^(1-sigma)).*(gr1vv.^(-sigma*alfa12)).*(gr2vv.^(-sigma*alfa22)).*(gr3vv.^(-sigma*alfa32))-As2.*(T.^(1-sigma)).*(gs1vv.^(-sigma*alfa12)).*(gs2vv.^(-sigma*alfa22)).*(gs3vv.^(-sigma*alfa32))-At2.*(gt1vv.^(-sigma*alfa12)).*(gt2vv.^(-sigma*alfa22)).*(gt3vv.^(-sigma*alfa32))==0;

fnt3=(gt3vv.^(1-sigma))-Ar3.*(T.^(1-sigma)).*(gr1vv.^(-sigma*alfa13)).*(gr2vv.^(-sigma*alfa23)).*(gr3vv.^(-sigma*alfa33))-As3.*(T.^(1-sigma)).*(gs1vv.^(-sigma*alfa13)).*(gs2vv.^(-sigma*alfa23)).*(gs3vv.^(-sigma*alfa33))-At3.*(gt1vv.^(-sigma*alfa13)).*(gt2vv.^(-sigma*alfa23)).*(gt3vv.^(-sigma*alfa33))==0;

sol=solve([fnr1,fnr2,fnr3,fns1,fns2,fns3,fnt1,fnt2,fnt3],[gr1vv,gr2vv,gr3vv,gs1vv,gs2vv,gs3vv,gt1vv,gt2vv,gt3vv]);

Gr1(1,vv)=vpa(gr1vv);

Gr2(1,vv)=vpa(gr2vv);

Gr3(1,vv)=vpa(gr3vv);

Gs1(1,vv)=vpa(gs1vv);

Gs2(1,vv)=vpa(gs2vv);

Gs3(1,vv)=vpa(gs3vv);

Gt1(1,vv)=vpa(gt1vv);

Gt2(1,vv)=vpa(gt2vv);

Gt3(1,vv)=vpa(gt3vv);

vpa(Gr1);

vpa(Gr2);

vpa(Gr3);

vpa(Gs1);

vpa(Gs2);

vpa(Gs3);

vpa(Gt1);

vpa(Gt2);

vpa(Gt3);

end

MGr1=(Gr1.^alfa11).*(Gr2.^alfa21).*(Gr3.^alfa31);

MGr2=(Gr1.^alfa12).*(Gr2.^alfa22).*(Gr3.^alfa32);

MGr3=(Gr1.^alfa13).*(Gr2.^alfa23).*(Gr3.^alfa33);

MGs1=(Gs1.^alfa11).*(Gs2.^alfa21).*(Gs3.^alfa31);

MGs2=(Gs1.^alfa12).*(Gs2.^alfa22).*(Gs3.^alfa32);

MGs3=(Gs1.^alfa13).*(Gs2.^alfa23).*(Gs3.^alfa33);

MGt1=(Gt1.^alfa11).*(Gt2.^alfa21).*(Gt3.^alfa31);

MGt2=(Gt1.^alfa12).*(Gt2.^alfa22).*(Gt3.^alfa32);

MGt3=(Gt1.^alfa13).*(Gt2.^alfa23).*(Gt3.^alfa33);

omegar1=((((alfa0.*((Er1.*(T./Gr1).^(1-sigma))+(Es1.*(T./Gs1).^(1-sigma))+(Et1.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGr1))).^(1/alfa0);

omegar2=((((alfa0.*((Er2.*(T./Gr1).^(1-sigma))+(Es2.*(T./Gs1).^(1-sigma))+(Et2.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGr2))).^(1/alfa0);

omegar3=((((alfa0.*((Er3.*(T./Gr1).^(1-sigma))+(Es3.*(T./Gs1).^(1-sigma))+(Et3.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGr3))).^(1/alfa0);

omegas1=((((alfa0.*((Er1.*(T./Gr1).^(1-sigma))+(Es1.*(T./Gs1).^(1-sigma))+(Et1.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGs1))).^(1/alfa0);

omegas2=((((alfa0.*((Er2.*(T./Gr1).^(1-sigma))+(Es2.*(T./Gs1).^(1-sigma))+(Et2.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGs2))).^(1/alfa0);

omegas3=((((alfa0.*((Er3.*(T./Gr1).^(1-sigma))+(Es3.*(T./Gs1).^(1-sigma))+(Et3.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGs3))).^(1/alfa0);

omegat1=((((alfa0.*((Er1.*(T./Gr1).^(1-sigma))+(Es1.*(T./Gs1).^(1-sigma))+(Et1.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGt1))).^(1/alfa0);

omegat2=((((alfa0.*((Er2.*(T./Gr1).^(1-sigma))+(Es2.*(T./Gs1).^(1-sigma))+(Et2.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGt2))).^(1/alfa0);

omegat3=((((alfa0.*((Er3.*(T./Gr1).^(1-sigma))+(Es3.*(T./Gs1).^(1-sigma))+(Et3.*(T./Gt1).^(1-sigma)))).^(1/sigma))./(MGt3))).^(1/alfa0);

valr1=(omegar1-omegar1old)./omegar1>0.00001;

valr2=(omegar2-omegar2old)./omegar2>0.00001;

valr3=(omegar3-omegar3old)./omegar3>0.00001;

vals1=(omegas1-omegas1old)./omegas1>0.00001;

vals2=(omegas2-omegas2old)./omegas2>0.00001;

vals3=(omegas3-omegas3old)./omegas3>0.00001;

valt1=(omegat1-omegat1old)./omegat1>0.00001;

valt2=(omegat2-omegat2old)./omegat2>0.00001;

valt3=(omegat3-omegat3old)./omegat3>0.00001;

ii=ii+1;

end

Br1=((alfa0.*(Er1-miu1.*(Yr-Y0)))./(Li.*omegar1));

Br2=((alfa0.*(Er2-miu2.*(Yr-Y0)))./(Li.*omegar2));

Br3=((alfa0.*(Er3-miu3.*(Yr-Y0)))./(Li.*omegar3));

Br=[alfa11,alfa12,alfa13;alfa21,alfa22,alfa23;alfa31,alfa32,alfa33];

br=[Br1;Br2;Br3];

[L,U]=lu(Br);

xr=U\(L\br);

lamdar1=xr(1,:);lamdar2=xr(2,:);lamdar3=xr(3,:);

Bs1=((alfa0.*(Es1-miu1.*(Ys-Y0)))./(Li.*omegas1));

Bs2=((alfa0.*(Es2-miu2.*(Ys-Y0)))./(Li.*omegas2));

Bs3=((alfa0.*(Es3-miu3.*(Ys-Y0)))./(Li.*omegas3));

Bs=[alfa11,alfa12,alfa13;alfa21,alfa22,alfa23;alfa31,alfa32,alfa33];

bs=[Bs1;Bs2;Bs3];

[L,U]=lu(Bs);

xs=U\(L\bs);

lamdas1=xs(1,:);lamdas2=xs(2,:);lamdas3=xs(3,:);

Bt1=((alfa0.*(Et1-miu1.*(Yt-Y0)))./(Li.*omegat1));

Bt2=((alfa0.*(Et2-miu2.*(Yt-Y0)))./(Li.*omegat2));

Bt3=((alfa0.*(Et3-miu3.*(Yt-Y0)))./(Li.*omegat3));

Bt=[alfa11,alfa12,alfa13;alfa21,alfa22,alfa23;alfa31,alfa32,alfa33];

bt=[Bt1;Bt2;Bt3];

[L,U]=lu(Bt);

xt=U\(L\bt);

lamdat1=xt(1,:);lamdat2=xt(2,:);lamdat3=xt(3,:);

upr1=abs(lamdar1-lamdar0)./lamdar1>0.00001;upr2=abs(lamdar2-lamdar0)./lamdar2>0.00001;upr3=abs(lamdar3-lamdar0)./lamdar3>0.00001;ups1=abs(lamdas1-lamdas0)./lamdas1>0.00001;ups2=abs(lamdas2-lamdas0)./lamdas2>0.00001;ups3=abs(lamdas3-lamdas0)./lamdas3>0.00001;upt1=abs(lamdat1-lamdat0)./lamdat1>0.00001;upt2=abs(lamdat2-lamdat0)./lamdat2>0.00001;upt3=abs(lamdat3-lamdat0)>0.00001;aa=1;

aa=aa+1;

end

S1=lamdar1./(lamdar1+lamdas1+lamdat1);

S2=lamdas1./(lamdar1+lamdas1+lamdat1);

S3=lamdat1./(lamdar1+lamdas1+lamdat1);

plot(Li,S1,Li,S2,Li,S3);

 类似资料: