MATLAB: Sym/max error Input arguments must be convertible to floating-point numbers

floatingpointnumbersmax

Hello, I have this matlab code and it does not work. I recieve "Sym/max error Input arguments must be convertible to floating-point numbers". Also i get an error at this line "IQmax=max(max(IQcalc));" why? What should I do? Thank you!
clear all;
close all;
clc;
syms Vg Vo D L1 L2 C1 Co R VC1 VCo IL1 IL2 Po
R=Vo^2/Po;
VL1on=VC1 ;
VL1off=Vg-VCo;
VL2on=Vg-VC1 ;
VL2off=-VC1;
IC1on=IL2-IL1 ;
IC1off=IL2;
ICoon=-VCo/R ;
ICooff=IL1-VCo/R;
Eq1=D*VL1on+(1-D)*VL1off;
Eq2=D*VL2on+(1-D)*VL2off;
Eq3=D*IC1on+(1-D)*IC1off;
Eq4=D*ICoon+(1-D)*ICooff;
solutia=solve(Eq1,Eq2,Eq3,Eq4,VC1,VCo,IL1,IL2);
VC1=simplify(solutia.VC1);
VCo=simplify(solutia.VCo);
IL1=simplify(solutia.IL1);
IL2=simplify(solutia.IL2);
IQ=simplify(D*(IL1));
IQrms=simplify(sqrt(D)*(IL1));
ID1=simplify(D*IL1);
ID1rms=simplify(sqrt(D)*IL1);
ID2=simplify((1-D)*IL2);
ID2rms=simplify((sqrt(1-D)*IL2));
ID3=simplify((1-D)*IL1);
ID3rms=simplify(sqrt(1-D)*IL1);
VD1=simplify(Vg);
VD3=simplify(Vg*D.^2./(1-D));
VQ=simplify(Vg);
VD2=simplify(Vg);
IQ=simplify(eval(IQ));
IQrms=simplify(eval(IQrms));
ID2=simplify(eval(ID2));
ID2rms=simplify(eval(ID2rms));
ID1=simplify(eval(ID1));
ID1rms=simplify(eval(ID1rms));
ID3=simplify(eval(ID3));
ID3rms=simplify(eval(ID3rms));
VQ=simplify(eval(VQ));
VD1=simplify(eval(VD1));
VD2=simplify(eval(VD2));
VD3=simplify(eval(VD3));
Vgmin=18; Vgmax=24; Vo=28; Pomin=12; Pomax=20; fs=80e3;
Rmin=Vo^2/Pomax,
Rmax=Vo^2/Pomin,
D=(sqrt(Vo^2+2*Vo*Vg-3*Vg)+Vg-Vo)/(2*Vg);
Dmax=(sqrt(Vo^2+2*Vo*Vgmin-3*Vgmin)+Vgmin-Vo)/(2*Vgmin),
Dmin=(sqrt(Vo^2+2*Vo*Vgmax-3*Vgmax)+Vgmax-Vo)/(2*Vgmax),
Vgcalc=Vgmin:0.1:Vgmax; Pocalc=Pomin:0.1:Pomax;
for i=1:length(Vgcalc)
for j=1:length(Pocalc)
Vg=Vgcalc(i); Po=Pocalc(j);
IQcalc(i,j)=eval(IQ);
IQrmscalc(i,j)=eval(IQrms);
VQcalc(i,j)=eval(VQ);
ID2calc(i,j)=eval(ID2);
ID2rmscalc(i,j)=eval(ID2rms);
VD2calc(i,j)=eval(VD2);
ID1calc(i,j)=eval(ID1);
ID1rmscalc(i,j)=eval(ID1rms);
VD1calc(i,j)=eval(VD1);
ID3calc(i,j)=eval(ID3);
ID3rmscalc(i,j)=eval(ID3rms);
VD3calc(i,j)=eval(VD3);
end
end
IQmax=max(max(IQcalc));
mesh(Pocalc,Vgcalc,IQcalc);
xlabel('Po'); ylabel('Vg');zlabel('IQ');
figure;
IQrmsmax=max(max(IQrmscalc)), mesh(Pocalc,Vgcalc,IQrmscalc); xlabel('Po');
ylabel('Vg'); zlabel('IQrms');
figure; VQmax=max(max(VQcalc)), mesh(Pocalc,Vgcalc,VQcalc); xlabel('Po'); ylabel('Vg');
zlabel('VQ');
ID1max=max(max(ID1calc)), mesh(Pocalc,Vgcalc,ID1calc); xlabel('Po'); ylabel('Vg');
zlabel('ID1');
figure; ID1rmsmax=max(max(ID1rmscalc)), mesh(Pocalc,Vgcalc,ID1rmscalc); xlabel('Po');
ylabel('Vg'); zlabel('ID1rms');
figure; VD1max=max(max(VD1calc)), mesh(Pocalc,Vgcalc,VD1calc); xlabel('Po');
ylabel('Vg'); zlabel('VD1');
ID2max=max(max(ID2calc)), mesh(Pocalc,Vgcalc,ID2calc); xlabel('Po'); ylabel('Vg');
zlabel('ID2');
figure; ID2rmsmax=max(max(ID2rmscalc)), mesh(Pocalc,Vgcalc,ID2rmscalc); xlabel('Po');
ylabel('Vg'); zlabel('ID2rms');
figure; VD2max=max(max(VD2calc)), mesh(Pocalc,Vgcalc,VD2calc); xlabel('Po');
ylabel('Vg'); zlabel('VD2');
ID3max=max(max(ID3calc)), mesh(Pocalc,Vgcalc,ID3calc); xlabel('Po'); ylabel('Vg');
zlabel('ID3');
figure; ID3rmsmax=max(max(ID3rmscalc)), mesh(Pocalc,Vgcalc,ID3rmscalc); xlabel('Po');
ylabel('Vg'); zlabel('ID3rms');
figure; VD3max=max(max(VD3calc)), mesh(Pocalc,Vgcalc,VD3calc); xlabel('Po');
ylabel('Vg'); zlabel('VD3');
IQmax=max(max(IQcalc)),
IQrmsmax=max(max(IQrmscalc)),
VQmax=max(max(VQcalc)),
ID2max=max(max(ID2calc)),
ID2rmsmax=max(max(ID2rmscalc)),
VD2max=max(max(VD2calc)),
ID1max=max(max(ID1calc)),
ID1rmsmax=max(max(ID1rmscalc)),
VD1max=max(max(VD1calc)),
ID3max=max(max(ID3calc)),
ID3rmsmax=max(max(ID3rmscalc)),
VD3max=max(max(VD3calc))

Best Answer

syms Vg Vo D L1 L2 C1 Co R VC1 VCo IL1 IL2 Po
so Vg is a symbol
VL1off=Vg-VCo;
VL1off is in terms of Vg
Eq1=D*VL1on+(1-D)*VL1off;
Eq1 is in terms of VL1off which is in terms of Vg, so Eq1 is in terms of Vg
solutia=solve(Eq1,Eq2,Eq3,Eq4,VC1,VCo,IL1,IL2);
That is 4 equations, solved for the 4 unknowns VC1,VCo,IL1,IL2 . The equations are in terms of Vg, so at least one of the variables that results is going to be in terms of Vg. In particular, solutia.IL1 ends up being in terms of Vg.
IL1=simplify(solutia.IL1);
so that is still in terms of Vg
IQ=simplify(D*(IL1));
and IQ is in terms of Vg
IQcalc(i,j)=eval(IQ);
Vg is assigned a value before that point, but when you eval(IQ), one of the variables substituted in is in terms of Vg, and eval() does not do a repeated pass to determine whether there are further replacements available in variables brought in. So IQcalc ends up in terms of Vg.
IQmax=max(max(IQcalc));
IQcalc is in terms of Vg. You cannot compare two symbolic expressions that involve a symbolic variable -- you do not know the value of the symbolic variable so you do not know its sign and so on. In some cases under the assumption of real numbers it is possible to prove that one symbolic expression is always greater than another, but max() does not have that capability.
mesh(Pocalc,Vgcalc,IQcalc);
Even if you could manage to prove that one particular symbolic entry in IQcalc was greater than all of the others, you certainly cannot surf() an array involving symbolic variables.
Note that using
IQcalc(i,j) = subs(IQ);
is not enough, due to the substitution of the variable that contains Vg inside it. However,
IQcalc(i,j) = subs(subs(IQ));
You need the same kind of change on other lines.