Category: Matlab
Category Archives: Matlab
how to solve this error ?
In this code, MATLAB gives me the following issue: For the solving function, how can I correct this error?
Error using sym/vpasolve:
Unable to find variables in equations.
Error in ni_water_simulationburgemanforchatgbt (line 99):
`solutions = vpasolve(eq, epsilon_mg, min(epsi, epsh), max(epsi, epsh));`
clear all
lambda = 500*10^-3:10*10^-3:2500*10^-3; % in microns
A1= 1.4182;
B1= 0.021304;
n_pc=sqrt(1+(A1.*lambda.^2)./(lambda.^2-B1));
wp= 15.92; % eV
f0 = 0.096;
Gamma0 = 0.048; % eV
f1 = 0.100;
Gamma1 = 4.511; % eV
omega1 = 0.174; % eV
f2 = 0.135;
Gamma2 = 1.334; % eV
omega2 = 0.582; % eV
f3 = 0.106;
Gamma3 = 2.178; % eV
omega3 = 1.597; % eV
f4 = 0.729;
Gamma4 = 6.292; % eV
omega4 = 6.089; % eV
OmegaP = sqrt(f0) * wp; % eV
eV = 4.13566733e-1 * 2.99792458 ./ lambda;
epsilon = 1 – OmegaP^2 ./ (eV .* (eV + 1i * Gamma0));
epsilon = epsilon + f1 * wp^2 ./ ((omega1^2 – eV.^2) – 1i * eV * Gamma1);
epsilon = epsilon + f2 * wp^2 ./ ((omega2^2 – eV.^2) – 1i * eV * Gamma2);
epsilon = epsilon + f3 * wp^2 ./ ((omega3^2 – eV.^2) – 1i * eV * Gamma3);
epsilon = epsilon + f4 * wp^2 ./ ((omega4^2 – eV.^2) – 1i * eV * Gamma4);
n = real(sqrt(epsilon));
k = imag(sqrt(epsilon));
nMetal = n+1i.*k;
%NWATER
NWATER = 0.0738.*lambda.^6 – 0.6168.*lambda.^5 + 2.0263.*lambda.^4 – 3.3315.*lambda.^3 + 2.8708.*lambda.^2 – 1.2367.*lambda + 1.5411;
nAir=1+0.05792105./(238.0185-(lambda.^(-2)))+0.00167917./(57.362-(lambda.^(-2)));
% permetivity
epsMetal = nMetal.^2;
epsWATER=NWATER.^2;
%parmenter for each axes
%1 specific volume
ni=n_pc;
nt=NWATER;
%angels
thetaI =0; % incidence angle
thetaI = thetaI/180*pi;
beta=20;
beta = beta/180*pi;
fi=0;
fi=fi/180*pi;
%%%%%
a=20*10.^-9;
b=5*10.^-9;
d=2*a*cos(beta);
fi=0.3;
fh=1-fi;
Rpp = [];
Rsp = [];
Rps = [];
Rss = [];
Tpp = [];
Tsp = [];
Tps = [];
Tss = [];
% epsilon for compost materals SHAPE Factor
e= sqrt(1-(b/a)^2);
la=((1-e^.2)/e^2)*((log((1+e)/(1-e)))/2*e^2 -1);
lb=0.5*(1-la);
% Symbolic variable for epsilon_mg
syms epsilon_mg
%%%%%%%%
for i=1:size(lambda,2)
%snel law §
thetaT=asin(ni(i)*sin(thetaI)/nt(i));
k0=2*pi/(lambda(i)*10^-6);
VX=ni(i)*sin(thetaI);
epsi=epsMetal(i);
epsh=epsWATER(i);
% Bruggeman mixing formula
eq = fi * (epsi – epsilon_mg) / (epsilon_mg + la * (epsi – epsilon_mg)) +(1 – fi) * (epsh – epsilon_mg) / (epsilon_mg + lb * (epsh – epsilon_mg)) == 0;
% Solve equation with positive imaginary part
solutions = vpasolve(eq, epsilon_mg, [min(epsi, epsh), max(epsi, epsh)]);
positive_imaginary = solutions(imag(solutions) > 0);
if ~isempty(positive_imaginary)
epsilon_mg = positive_imaginary(1);
else
error(‘No solution with positive imaginary part found at index %d’, i);
end
eps1=epsilon_mg;
eps2=epsilon_mg;
eps3=epsilon_mg;
exx=eps2 +(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) -eps2).*cos(fi).*cos(fi);
exy=0.5.*(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) – eps2).*sin(2.*fi);
exz=0.5.*(eps3-eps1).*sin(2.*beta).*cos(fi);
eyy=eps2 +(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) – eps2).*sin(fi).*sin(fi);
eyz=0.5.*(eps3-eps1).*sin(2.*beta).*sin(fi);
ezz=eps1 +(eps3 -eps1).*cos(beta).*cos(beta);
eyx=exy;
ezx=exz;
ezy=eyz;
del = [-VX.*ezx./ezz 1-(VX.*VX)./ezz -VX.*ezy./ezz 0; exx-(exz.*ezx)./ezz -VX.*exz./ezz exy-exz.*ezy./ezz 0; 0 0 0 1; eyx-(eyz.*ezx)./ezz -VX.*eyz./ezz eyy-(VX.*VX)-(eyz.*ezy)./ezz 0];
P=exp(1)^(1i.*k0.*d.*del);
a1 = ni(i).*(nt(i).*P(1,2)-cos(thetaT).*P(2,2))+cos(thetaI).*(nt(i).*P(1,1)-cos(thetaT).*P(2,1));
a2 = ni(i).*(nt(i).*P(1,2)-cos(thetaT)*P(2,2))-cos(thetaI).*(nt(i).*P(1,1)-cos(thetaT).*P(2,1));
a3 = (nt(i).*P(1,3)-cos(thetaT).*P(2,3))+ni(i).*cos(thetaI).*(nt(i).*P(1,4)-cos(thetaT).*P(2,4));
a4 = (nt(i).*P(1,3)-cos(thetaT).*P(2,3))-ni(i).*cos(thetaI).*(nt(i).*P(1,4)-cos(thetaT).*P(2,4));
a5 = ni(i).*(nt(i).*cos(thetaT).*P(3,2 )-P(4,2)) +cos(thetaI).*(nt(i).*cos(thetaT).*P(3,1)-P(4,1));
a6 = ni(i).*(nt(i).*cos(thetaT).*P(3,2) -P(4,2))-cos(thetaI).*(nt(i).*cos(thetaT).*P(3,1)-P(4,1));
a7 = (nt(i).*cos(thetaT).*P(3,3)-P(4,3))+ni(i).*cos(thetaI).*(nt(i).*P(3,4).*cos(thetaT)-P(4,4));
a8 = (nt(i).*cos(thetaT).*P(3,3)-P(4,3))-ni(i).*cos(thetaI).*(nt(i).*P(3,4).*cos(thetaT)-P(4,4));
b1 = (ni(i).*P(2,2)+cos(thetaI).*P(2,1))./nt(i);
b2 = (ni(i).*P(2,2)-cos(thetaI).*P(2,1))./nt(i);
b3 = (P(2,3)-ni(i).*cos(thetaI).*P(2,4))./nt(i);
b4 = (P(2,3)+ni(i).*cos(thetaI).*P(2,4))./nt(i);
b5 = ni(i).*P(3,2)+cos(thetaI).*P(3,1);
b6 = ni(i).*P(3,2)-cos(thetaI).*P(3,1);
b7 = P(3,3)-ni(i).*cos(thetaI).*P(3,4);
b8 = P(3,3)+ni(i).*cos(thetaI).*P(3,4);
rpp=(a1.*a8-a4.*a5)./(a4.*a6-a2.*a8);
rps=(a3.*a8-a4.*a7)./(a4.*a6-a2.*a8);
rsp=(a2.*a5-a1.*a6)./(a4.*a6-a2.*a8);
rss=(a2.*a7-a6.*a3)./(a4.*a6-a2.*a8);
tpp=b1+b2.*rpp+b3.*rsp;
tps=b4+b2.*rps+b3.*rss;
tsp=b5+b6.*rpp+b7.*rsp;
tss=b8+b6.*rps+b7.*rss;
Rpp = [Rpp (abs(rpp))^2];
Rsp = [Rsp (abs(rsp))^2];
Rps = [Rps (abs(rps))^2];
Rss = [Rss (abs(rss))^2];
Tpp = [Tpp (nt(i) .* cos(thetaI) ./ ni(i) .* cos(real(thetaT))).*(abs(tpp )^2)];
Tss = [Tss (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tss )^2)];
Tsp = [Tsp (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tsp )^2)];
Tps = [Tps (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tps )^2)];
T=(Tpp+Tsp+Tps+Tss)/2;
R=(Rpp+Rsp+Rps+Rss)/2;
A=1-R-T;
end
figure(1)
hold on
plot(lambda*10^3,A*100,’LineWidth’, 3)
hold on
xlabel(‘Wavelength (nm)’,’fontsize’,16)
hold on
ylabel(‘Absorbtion’,’fontsize’, 16)
figure(2)
hold on
plot(lambda*10^3,T*100,’LineWidth’, 3)
hold on
xlabel(‘Wavelength (nm)’,’fontsize’,16)
hold on
ylabel(‘Transmission’,’fontsize’, 16)In this code, MATLAB gives me the following issue: For the solving function, how can I correct this error?
Error using sym/vpasolve:
Unable to find variables in equations.
Error in ni_water_simulationburgemanforchatgbt (line 99):
`solutions = vpasolve(eq, epsilon_mg, min(epsi, epsh), max(epsi, epsh));`
clear all
lambda = 500*10^-3:10*10^-3:2500*10^-3; % in microns
A1= 1.4182;
B1= 0.021304;
n_pc=sqrt(1+(A1.*lambda.^2)./(lambda.^2-B1));
wp= 15.92; % eV
f0 = 0.096;
Gamma0 = 0.048; % eV
f1 = 0.100;
Gamma1 = 4.511; % eV
omega1 = 0.174; % eV
f2 = 0.135;
Gamma2 = 1.334; % eV
omega2 = 0.582; % eV
f3 = 0.106;
Gamma3 = 2.178; % eV
omega3 = 1.597; % eV
f4 = 0.729;
Gamma4 = 6.292; % eV
omega4 = 6.089; % eV
OmegaP = sqrt(f0) * wp; % eV
eV = 4.13566733e-1 * 2.99792458 ./ lambda;
epsilon = 1 – OmegaP^2 ./ (eV .* (eV + 1i * Gamma0));
epsilon = epsilon + f1 * wp^2 ./ ((omega1^2 – eV.^2) – 1i * eV * Gamma1);
epsilon = epsilon + f2 * wp^2 ./ ((omega2^2 – eV.^2) – 1i * eV * Gamma2);
epsilon = epsilon + f3 * wp^2 ./ ((omega3^2 – eV.^2) – 1i * eV * Gamma3);
epsilon = epsilon + f4 * wp^2 ./ ((omega4^2 – eV.^2) – 1i * eV * Gamma4);
n = real(sqrt(epsilon));
k = imag(sqrt(epsilon));
nMetal = n+1i.*k;
%NWATER
NWATER = 0.0738.*lambda.^6 – 0.6168.*lambda.^5 + 2.0263.*lambda.^4 – 3.3315.*lambda.^3 + 2.8708.*lambda.^2 – 1.2367.*lambda + 1.5411;
nAir=1+0.05792105./(238.0185-(lambda.^(-2)))+0.00167917./(57.362-(lambda.^(-2)));
% permetivity
epsMetal = nMetal.^2;
epsWATER=NWATER.^2;
%parmenter for each axes
%1 specific volume
ni=n_pc;
nt=NWATER;
%angels
thetaI =0; % incidence angle
thetaI = thetaI/180*pi;
beta=20;
beta = beta/180*pi;
fi=0;
fi=fi/180*pi;
%%%%%
a=20*10.^-9;
b=5*10.^-9;
d=2*a*cos(beta);
fi=0.3;
fh=1-fi;
Rpp = [];
Rsp = [];
Rps = [];
Rss = [];
Tpp = [];
Tsp = [];
Tps = [];
Tss = [];
% epsilon for compost materals SHAPE Factor
e= sqrt(1-(b/a)^2);
la=((1-e^.2)/e^2)*((log((1+e)/(1-e)))/2*e^2 -1);
lb=0.5*(1-la);
% Symbolic variable for epsilon_mg
syms epsilon_mg
%%%%%%%%
for i=1:size(lambda,2)
%snel law §
thetaT=asin(ni(i)*sin(thetaI)/nt(i));
k0=2*pi/(lambda(i)*10^-6);
VX=ni(i)*sin(thetaI);
epsi=epsMetal(i);
epsh=epsWATER(i);
% Bruggeman mixing formula
eq = fi * (epsi – epsilon_mg) / (epsilon_mg + la * (epsi – epsilon_mg)) +(1 – fi) * (epsh – epsilon_mg) / (epsilon_mg + lb * (epsh – epsilon_mg)) == 0;
% Solve equation with positive imaginary part
solutions = vpasolve(eq, epsilon_mg, [min(epsi, epsh), max(epsi, epsh)]);
positive_imaginary = solutions(imag(solutions) > 0);
if ~isempty(positive_imaginary)
epsilon_mg = positive_imaginary(1);
else
error(‘No solution with positive imaginary part found at index %d’, i);
end
eps1=epsilon_mg;
eps2=epsilon_mg;
eps3=epsilon_mg;
exx=eps2 +(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) -eps2).*cos(fi).*cos(fi);
exy=0.5.*(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) – eps2).*sin(2.*fi);
exz=0.5.*(eps3-eps1).*sin(2.*beta).*cos(fi);
eyy=eps2 +(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) – eps2).*sin(fi).*sin(fi);
eyz=0.5.*(eps3-eps1).*sin(2.*beta).*sin(fi);
ezz=eps1 +(eps3 -eps1).*cos(beta).*cos(beta);
eyx=exy;
ezx=exz;
ezy=eyz;
del = [-VX.*ezx./ezz 1-(VX.*VX)./ezz -VX.*ezy./ezz 0; exx-(exz.*ezx)./ezz -VX.*exz./ezz exy-exz.*ezy./ezz 0; 0 0 0 1; eyx-(eyz.*ezx)./ezz -VX.*eyz./ezz eyy-(VX.*VX)-(eyz.*ezy)./ezz 0];
P=exp(1)^(1i.*k0.*d.*del);
a1 = ni(i).*(nt(i).*P(1,2)-cos(thetaT).*P(2,2))+cos(thetaI).*(nt(i).*P(1,1)-cos(thetaT).*P(2,1));
a2 = ni(i).*(nt(i).*P(1,2)-cos(thetaT)*P(2,2))-cos(thetaI).*(nt(i).*P(1,1)-cos(thetaT).*P(2,1));
a3 = (nt(i).*P(1,3)-cos(thetaT).*P(2,3))+ni(i).*cos(thetaI).*(nt(i).*P(1,4)-cos(thetaT).*P(2,4));
a4 = (nt(i).*P(1,3)-cos(thetaT).*P(2,3))-ni(i).*cos(thetaI).*(nt(i).*P(1,4)-cos(thetaT).*P(2,4));
a5 = ni(i).*(nt(i).*cos(thetaT).*P(3,2 )-P(4,2)) +cos(thetaI).*(nt(i).*cos(thetaT).*P(3,1)-P(4,1));
a6 = ni(i).*(nt(i).*cos(thetaT).*P(3,2) -P(4,2))-cos(thetaI).*(nt(i).*cos(thetaT).*P(3,1)-P(4,1));
a7 = (nt(i).*cos(thetaT).*P(3,3)-P(4,3))+ni(i).*cos(thetaI).*(nt(i).*P(3,4).*cos(thetaT)-P(4,4));
a8 = (nt(i).*cos(thetaT).*P(3,3)-P(4,3))-ni(i).*cos(thetaI).*(nt(i).*P(3,4).*cos(thetaT)-P(4,4));
b1 = (ni(i).*P(2,2)+cos(thetaI).*P(2,1))./nt(i);
b2 = (ni(i).*P(2,2)-cos(thetaI).*P(2,1))./nt(i);
b3 = (P(2,3)-ni(i).*cos(thetaI).*P(2,4))./nt(i);
b4 = (P(2,3)+ni(i).*cos(thetaI).*P(2,4))./nt(i);
b5 = ni(i).*P(3,2)+cos(thetaI).*P(3,1);
b6 = ni(i).*P(3,2)-cos(thetaI).*P(3,1);
b7 = P(3,3)-ni(i).*cos(thetaI).*P(3,4);
b8 = P(3,3)+ni(i).*cos(thetaI).*P(3,4);
rpp=(a1.*a8-a4.*a5)./(a4.*a6-a2.*a8);
rps=(a3.*a8-a4.*a7)./(a4.*a6-a2.*a8);
rsp=(a2.*a5-a1.*a6)./(a4.*a6-a2.*a8);
rss=(a2.*a7-a6.*a3)./(a4.*a6-a2.*a8);
tpp=b1+b2.*rpp+b3.*rsp;
tps=b4+b2.*rps+b3.*rss;
tsp=b5+b6.*rpp+b7.*rsp;
tss=b8+b6.*rps+b7.*rss;
Rpp = [Rpp (abs(rpp))^2];
Rsp = [Rsp (abs(rsp))^2];
Rps = [Rps (abs(rps))^2];
Rss = [Rss (abs(rss))^2];
Tpp = [Tpp (nt(i) .* cos(thetaI) ./ ni(i) .* cos(real(thetaT))).*(abs(tpp )^2)];
Tss = [Tss (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tss )^2)];
Tsp = [Tsp (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tsp )^2)];
Tps = [Tps (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tps )^2)];
T=(Tpp+Tsp+Tps+Tss)/2;
R=(Rpp+Rsp+Rps+Rss)/2;
A=1-R-T;
end
figure(1)
hold on
plot(lambda*10^3,A*100,’LineWidth’, 3)
hold on
xlabel(‘Wavelength (nm)’,’fontsize’,16)
hold on
ylabel(‘Absorbtion’,’fontsize’, 16)
figure(2)
hold on
plot(lambda*10^3,T*100,’LineWidth’, 3)
hold on
xlabel(‘Wavelength (nm)’,’fontsize’,16)
hold on
ylabel(‘Transmission’,’fontsize’, 16) In this code, MATLAB gives me the following issue: For the solving function, how can I correct this error?
Error using sym/vpasolve:
Unable to find variables in equations.
Error in ni_water_simulationburgemanforchatgbt (line 99):
`solutions = vpasolve(eq, epsilon_mg, min(epsi, epsh), max(epsi, epsh));`
clear all
lambda = 500*10^-3:10*10^-3:2500*10^-3; % in microns
A1= 1.4182;
B1= 0.021304;
n_pc=sqrt(1+(A1.*lambda.^2)./(lambda.^2-B1));
wp= 15.92; % eV
f0 = 0.096;
Gamma0 = 0.048; % eV
f1 = 0.100;
Gamma1 = 4.511; % eV
omega1 = 0.174; % eV
f2 = 0.135;
Gamma2 = 1.334; % eV
omega2 = 0.582; % eV
f3 = 0.106;
Gamma3 = 2.178; % eV
omega3 = 1.597; % eV
f4 = 0.729;
Gamma4 = 6.292; % eV
omega4 = 6.089; % eV
OmegaP = sqrt(f0) * wp; % eV
eV = 4.13566733e-1 * 2.99792458 ./ lambda;
epsilon = 1 – OmegaP^2 ./ (eV .* (eV + 1i * Gamma0));
epsilon = epsilon + f1 * wp^2 ./ ((omega1^2 – eV.^2) – 1i * eV * Gamma1);
epsilon = epsilon + f2 * wp^2 ./ ((omega2^2 – eV.^2) – 1i * eV * Gamma2);
epsilon = epsilon + f3 * wp^2 ./ ((omega3^2 – eV.^2) – 1i * eV * Gamma3);
epsilon = epsilon + f4 * wp^2 ./ ((omega4^2 – eV.^2) – 1i * eV * Gamma4);
n = real(sqrt(epsilon));
k = imag(sqrt(epsilon));
nMetal = n+1i.*k;
%NWATER
NWATER = 0.0738.*lambda.^6 – 0.6168.*lambda.^5 + 2.0263.*lambda.^4 – 3.3315.*lambda.^3 + 2.8708.*lambda.^2 – 1.2367.*lambda + 1.5411;
nAir=1+0.05792105./(238.0185-(lambda.^(-2)))+0.00167917./(57.362-(lambda.^(-2)));
% permetivity
epsMetal = nMetal.^2;
epsWATER=NWATER.^2;
%parmenter for each axes
%1 specific volume
ni=n_pc;
nt=NWATER;
%angels
thetaI =0; % incidence angle
thetaI = thetaI/180*pi;
beta=20;
beta = beta/180*pi;
fi=0;
fi=fi/180*pi;
%%%%%
a=20*10.^-9;
b=5*10.^-9;
d=2*a*cos(beta);
fi=0.3;
fh=1-fi;
Rpp = [];
Rsp = [];
Rps = [];
Rss = [];
Tpp = [];
Tsp = [];
Tps = [];
Tss = [];
% epsilon for compost materals SHAPE Factor
e= sqrt(1-(b/a)^2);
la=((1-e^.2)/e^2)*((log((1+e)/(1-e)))/2*e^2 -1);
lb=0.5*(1-la);
% Symbolic variable for epsilon_mg
syms epsilon_mg
%%%%%%%%
for i=1:size(lambda,2)
%snel law §
thetaT=asin(ni(i)*sin(thetaI)/nt(i));
k0=2*pi/(lambda(i)*10^-6);
VX=ni(i)*sin(thetaI);
epsi=epsMetal(i);
epsh=epsWATER(i);
% Bruggeman mixing formula
eq = fi * (epsi – epsilon_mg) / (epsilon_mg + la * (epsi – epsilon_mg)) +(1 – fi) * (epsh – epsilon_mg) / (epsilon_mg + lb * (epsh – epsilon_mg)) == 0;
% Solve equation with positive imaginary part
solutions = vpasolve(eq, epsilon_mg, [min(epsi, epsh), max(epsi, epsh)]);
positive_imaginary = solutions(imag(solutions) > 0);
if ~isempty(positive_imaginary)
epsilon_mg = positive_imaginary(1);
else
error(‘No solution with positive imaginary part found at index %d’, i);
end
eps1=epsilon_mg;
eps2=epsilon_mg;
eps3=epsilon_mg;
exx=eps2 +(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) -eps2).*cos(fi).*cos(fi);
exy=0.5.*(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) – eps2).*sin(2.*fi);
exz=0.5.*(eps3-eps1).*sin(2.*beta).*cos(fi);
eyy=eps2 +(eps1.*cos(beta).*cos(beta) +eps3.*sin(beta).*sin(beta) – eps2).*sin(fi).*sin(fi);
eyz=0.5.*(eps3-eps1).*sin(2.*beta).*sin(fi);
ezz=eps1 +(eps3 -eps1).*cos(beta).*cos(beta);
eyx=exy;
ezx=exz;
ezy=eyz;
del = [-VX.*ezx./ezz 1-(VX.*VX)./ezz -VX.*ezy./ezz 0; exx-(exz.*ezx)./ezz -VX.*exz./ezz exy-exz.*ezy./ezz 0; 0 0 0 1; eyx-(eyz.*ezx)./ezz -VX.*eyz./ezz eyy-(VX.*VX)-(eyz.*ezy)./ezz 0];
P=exp(1)^(1i.*k0.*d.*del);
a1 = ni(i).*(nt(i).*P(1,2)-cos(thetaT).*P(2,2))+cos(thetaI).*(nt(i).*P(1,1)-cos(thetaT).*P(2,1));
a2 = ni(i).*(nt(i).*P(1,2)-cos(thetaT)*P(2,2))-cos(thetaI).*(nt(i).*P(1,1)-cos(thetaT).*P(2,1));
a3 = (nt(i).*P(1,3)-cos(thetaT).*P(2,3))+ni(i).*cos(thetaI).*(nt(i).*P(1,4)-cos(thetaT).*P(2,4));
a4 = (nt(i).*P(1,3)-cos(thetaT).*P(2,3))-ni(i).*cos(thetaI).*(nt(i).*P(1,4)-cos(thetaT).*P(2,4));
a5 = ni(i).*(nt(i).*cos(thetaT).*P(3,2 )-P(4,2)) +cos(thetaI).*(nt(i).*cos(thetaT).*P(3,1)-P(4,1));
a6 = ni(i).*(nt(i).*cos(thetaT).*P(3,2) -P(4,2))-cos(thetaI).*(nt(i).*cos(thetaT).*P(3,1)-P(4,1));
a7 = (nt(i).*cos(thetaT).*P(3,3)-P(4,3))+ni(i).*cos(thetaI).*(nt(i).*P(3,4).*cos(thetaT)-P(4,4));
a8 = (nt(i).*cos(thetaT).*P(3,3)-P(4,3))-ni(i).*cos(thetaI).*(nt(i).*P(3,4).*cos(thetaT)-P(4,4));
b1 = (ni(i).*P(2,2)+cos(thetaI).*P(2,1))./nt(i);
b2 = (ni(i).*P(2,2)-cos(thetaI).*P(2,1))./nt(i);
b3 = (P(2,3)-ni(i).*cos(thetaI).*P(2,4))./nt(i);
b4 = (P(2,3)+ni(i).*cos(thetaI).*P(2,4))./nt(i);
b5 = ni(i).*P(3,2)+cos(thetaI).*P(3,1);
b6 = ni(i).*P(3,2)-cos(thetaI).*P(3,1);
b7 = P(3,3)-ni(i).*cos(thetaI).*P(3,4);
b8 = P(3,3)+ni(i).*cos(thetaI).*P(3,4);
rpp=(a1.*a8-a4.*a5)./(a4.*a6-a2.*a8);
rps=(a3.*a8-a4.*a7)./(a4.*a6-a2.*a8);
rsp=(a2.*a5-a1.*a6)./(a4.*a6-a2.*a8);
rss=(a2.*a7-a6.*a3)./(a4.*a6-a2.*a8);
tpp=b1+b2.*rpp+b3.*rsp;
tps=b4+b2.*rps+b3.*rss;
tsp=b5+b6.*rpp+b7.*rsp;
tss=b8+b6.*rps+b7.*rss;
Rpp = [Rpp (abs(rpp))^2];
Rsp = [Rsp (abs(rsp))^2];
Rps = [Rps (abs(rps))^2];
Rss = [Rss (abs(rss))^2];
Tpp = [Tpp (nt(i) .* cos(thetaI) ./ ni(i) .* cos(real(thetaT))).*(abs(tpp )^2)];
Tss = [Tss (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tss )^2)];
Tsp = [Tsp (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tsp )^2)];
Tps = [Tps (nt(i) .* cos(real(thetaT)) ./ ni(i) .* cos(thetaI)).*(abs(tps )^2)];
T=(Tpp+Tsp+Tps+Tss)/2;
R=(Rpp+Rsp+Rps+Rss)/2;
A=1-R-T;
end
figure(1)
hold on
plot(lambda*10^3,A*100,’LineWidth’, 3)
hold on
xlabel(‘Wavelength (nm)’,’fontsize’,16)
hold on
ylabel(‘Absorbtion’,’fontsize’, 16)
figure(2)
hold on
plot(lambda*10^3,T*100,’LineWidth’, 3)
hold on
xlabel(‘Wavelength (nm)’,’fontsize’,16)
hold on
ylabel(‘Transmission’,’fontsize’, 16) solve function, matalb code, sav, vpasolve MATLAB Answers — New Questions
Accidental deletion of project, how to contact file exchange admin
I accidentally deleted a file exchange project, when I try to reupload I am told this is not possible and to contact an admin.
How do I contact the admin? Can the deletion be undone? thanksI accidentally deleted a file exchange project, when I try to reupload I am told this is not possible and to contact an admin.
How do I contact the admin? Can the deletion be undone? thanks I accidentally deleted a file exchange project, when I try to reupload I am told this is not possible and to contact an admin.
How do I contact the admin? Can the deletion be undone? thanks fileexchange MATLAB Answers — New Questions
How do I change the user for MATLAB Coder?
I wantat to change the user for MATLAB coder. THe remove/reassign did not work. It locks up once I select the green assign buttonI wantat to change the user for MATLAB coder. THe remove/reassign did not work. It locks up once I select the green assign button I wantat to change the user for MATLAB coder. THe remove/reassign did not work. It locks up once I select the green assign button change user, matlab coder MATLAB Answers — New Questions
how to find curve fiitng equation through custom equation
Question:
I have measured data for the discharging state of charge (SOC) and inverter power of a Redox Flow Battery (RFB). From this data, I need to determine the auxiliary power loss of the battery. I’m trying to find an equation for this non-linear relationship using curve fitting or other methods.
I want to create a model where the equation is in the form of f(X)+f(Y) where X represents SOC and Y represents inverter power. The key requirement is that X and Y should be treated as independent variables, meaning they should not be combined into one term in the equation.
I have tried some equations where X and Y are separate in the equation, but I am getting a low R-squared value (around 0.6). However, when I combine Xand Y together in one equation, the R-squared value improves to 0.9, which is better.
Now, I need to apply piecewise linearization to the model with X and Ytogether. How can I proceed with this approach and still maintain the independent nature of X and Y in the equation for the fitting process? Any advice or guidance would be much appreciated!Question:
I have measured data for the discharging state of charge (SOC) and inverter power of a Redox Flow Battery (RFB). From this data, I need to determine the auxiliary power loss of the battery. I’m trying to find an equation for this non-linear relationship using curve fitting or other methods.
I want to create a model where the equation is in the form of f(X)+f(Y) where X represents SOC and Y represents inverter power. The key requirement is that X and Y should be treated as independent variables, meaning they should not be combined into one term in the equation.
I have tried some equations where X and Y are separate in the equation, but I am getting a low R-squared value (around 0.6). However, when I combine Xand Y together in one equation, the R-squared value improves to 0.9, which is better.
Now, I need to apply piecewise linearization to the model with X and Ytogether. How can I proceed with this approach and still maintain the independent nature of X and Y in the equation for the fitting process? Any advice or guidance would be much appreciated! Question:
I have measured data for the discharging state of charge (SOC) and inverter power of a Redox Flow Battery (RFB). From this data, I need to determine the auxiliary power loss of the battery. I’m trying to find an equation for this non-linear relationship using curve fitting or other methods.
I want to create a model where the equation is in the form of f(X)+f(Y) where X represents SOC and Y represents inverter power. The key requirement is that X and Y should be treated as independent variables, meaning they should not be combined into one term in the equation.
I have tried some equations where X and Y are separate in the equation, but I am getting a low R-squared value (around 0.6). However, when I combine Xand Y together in one equation, the R-squared value improves to 0.9, which is better.
Now, I need to apply piecewise linearization to the model with X and Ytogether. How can I proceed with this approach and still maintain the independent nature of X and Y in the equation for the fitting process? Any advice or guidance would be much appreciated! redox flow battery, soc, inverter power, auxiliary, curve fitting, nonlinear MATLAB Answers — New Questions
Geoaxes zoom not working after adding ButtonDownFcn.
I have an app built in AppDesigner with a map plotted in geoaxes. I need to zoom in and out but I also need to do some action when I click on the map. The problem is that:
zoom works perfectly when no buttondownfcn is added
f = uifigure;
gx = geoaxes();
geoscatter(gx,10,10)
zoom does not work at all when buttondownfcn is added.
f = uifigure;
gx = geoaxes(f);
geoscatter(gx,10,10)
gx.ButtonDownFcn = ‘disp(”hello”)’;
I need to use both functionalities. What should I do?I have an app built in AppDesigner with a map plotted in geoaxes. I need to zoom in and out but I also need to do some action when I click on the map. The problem is that:
zoom works perfectly when no buttondownfcn is added
f = uifigure;
gx = geoaxes();
geoscatter(gx,10,10)
zoom does not work at all when buttondownfcn is added.
f = uifigure;
gx = geoaxes(f);
geoscatter(gx,10,10)
gx.ButtonDownFcn = ‘disp(”hello”)’;
I need to use both functionalities. What should I do? I have an app built in AppDesigner with a map plotted in geoaxes. I need to zoom in and out but I also need to do some action when I click on the map. The problem is that:
zoom works perfectly when no buttondownfcn is added
f = uifigure;
gx = geoaxes();
geoscatter(gx,10,10)
zoom does not work at all when buttondownfcn is added.
f = uifigure;
gx = geoaxes(f);
geoscatter(gx,10,10)
gx.ButtonDownFcn = ‘disp(”hello”)’;
I need to use both functionalities. What should I do? matlab, appdesigner, geoaxes, zoom MATLAB Answers — New Questions
Are namespaces packages?
The R2024a release notes say "The MATLAB language feature known as a package is now called a namespace."
The R2024b release notes say "A package is a collection of MATLAB code, related files, and a package definition file that defines the package identity and dependencies."
So I wanted to check: is the package referred to in the R2024b notes a new kind of thing, different to a namespace, or is the terminology change from R2024a being ignored?The R2024a release notes say "The MATLAB language feature known as a package is now called a namespace."
The R2024b release notes say "A package is a collection of MATLAB code, related files, and a package definition file that defines the package identity and dependencies."
So I wanted to check: is the package referred to in the R2024b notes a new kind of thing, different to a namespace, or is the terminology change from R2024a being ignored? The R2024a release notes say "The MATLAB language feature known as a package is now called a namespace."
The R2024b release notes say "A package is a collection of MATLAB code, related files, and a package definition file that defines the package identity and dependencies."
So I wanted to check: is the package referred to in the R2024b notes a new kind of thing, different to a namespace, or is the terminology change from R2024a being ignored? package, namespace MATLAB Answers — New Questions
Error in executing freqz command on LINUX server
I am trying to execute the command
[H,w] = freqz(b,a);
on the server machine of my university and it throws the following error: Bundle#165 start failed: libXcomposite.so.1: cannot open shared object file: No such file or directory.
I understand the error is due to the graphics. Could someone help me to solve this error? I do not need graphics, but just the FRF H and frequency vector w. I used the command matlab -nodisplay, but it doesn’t help.I am trying to execute the command
[H,w] = freqz(b,a);
on the server machine of my university and it throws the following error: Bundle#165 start failed: libXcomposite.so.1: cannot open shared object file: No such file or directory.
I understand the error is due to the graphics. Could someone help me to solve this error? I do not need graphics, but just the FRF H and frequency vector w. I used the command matlab -nodisplay, but it doesn’t help. I am trying to execute the command
[H,w] = freqz(b,a);
on the server machine of my university and it throws the following error: Bundle#165 start failed: libXcomposite.so.1: cannot open shared object file: No such file or directory.
I understand the error is due to the graphics. Could someone help me to solve this error? I do not need graphics, but just the FRF H and frequency vector w. I used the command matlab -nodisplay, but it doesn’t help. frequency, signal processing, linux, graphics, error MATLAB Answers — New Questions
Matlab Live Editor: “Unable to open this file in the current system configuration.”
I am running Matlab 2022b on NixOS – an unsupported-officially Linux distribution. I get this error since a few months ago when I try to open a matlab file:
Scrolling down that message shows the text:
And opening that "Requirements" link doesn’t work – brings me to an empty web page:
I got this error message also with version 2021b. I don’t use Matlab frequently enough to mark the day it stopped working, but I assume it was due to a system update. The list of system dependencies I have installed in Matlab’s environment is available here:
https://gitlab.com/doronbehar/nix-matlab/blob/1802c05f3c4187c344d9e4de1f9546dfc9ad017a/common.nix#L8-56I am running Matlab 2022b on NixOS – an unsupported-officially Linux distribution. I get this error since a few months ago when I try to open a matlab file:
Scrolling down that message shows the text:
And opening that "Requirements" link doesn’t work – brings me to an empty web page:
I got this error message also with version 2021b. I don’t use Matlab frequently enough to mark the day it stopped working, but I assume it was due to a system update. The list of system dependencies I have installed in Matlab’s environment is available here:
https://gitlab.com/doronbehar/nix-matlab/blob/1802c05f3c4187c344d9e4de1f9546dfc9ad017a/common.nix#L8-56 I am running Matlab 2022b on NixOS – an unsupported-officially Linux distribution. I get this error since a few months ago when I try to open a matlab file:
Scrolling down that message shows the text:
And opening that "Requirements" link doesn’t work – brings me to an empty web page:
I got this error message also with version 2021b. I don’t use Matlab frequently enough to mark the day it stopped working, but I assume it was due to a system update. The list of system dependencies I have installed in Matlab’s environment is available here:
https://gitlab.com/doronbehar/nix-matlab/blob/1802c05f3c4187c344d9e4de1f9546dfc9ad017a/common.nix#L8-56 installation, gui, matlab MATLAB Answers — New Questions
Why do I receive the error “You are not licensed to use R20XXy?” when I try to launch MATLAB?
Why I do receive the following error message when trying to launch MATLAB?
You are not licensed to use R20XXy.
For help, contact your license administrator or MathWorks Support.Why I do receive the following error message when trying to launch MATLAB?
You are not licensed to use R20XXy.
For help, contact your license administrator or MathWorks Support. Why I do receive the following error message when trying to launch MATLAB?
You are not licensed to use R20XXy.
For help, contact your license administrator or MathWorks Support. MATLAB Answers — New Questions
Enable a subsystem from Simulink stateflow ?
Hello ,
I am a newbie to Simulink . I am trying to run a activate/enable a subsystem when certain conditions are met in Simulink Stateflow . I know I have to add enable signal to the subsystem I intend to activate and this would be input to the subsystem I am trying to activate.
But my question is how do I set this enable signal to true in my state flow . Since its a input variable I cannot assign its value in another subsystem or is there a better way to do it .
I might be completely off since I am barely getting statrted . Any help appreciated .
ThanksHello ,
I am a newbie to Simulink . I am trying to run a activate/enable a subsystem when certain conditions are met in Simulink Stateflow . I know I have to add enable signal to the subsystem I intend to activate and this would be input to the subsystem I am trying to activate.
But my question is how do I set this enable signal to true in my state flow . Since its a input variable I cannot assign its value in another subsystem or is there a better way to do it .
I might be completely off since I am barely getting statrted . Any help appreciated .
Thanks Hello ,
I am a newbie to Simulink . I am trying to run a activate/enable a subsystem when certain conditions are met in Simulink Stateflow . I know I have to add enable signal to the subsystem I intend to activate and this would be input to the subsystem I am trying to activate.
But my question is how do I set this enable signal to true in my state flow . Since its a input variable I cannot assign its value in another subsystem or is there a better way to do it .
I might be completely off since I am barely getting statrted . Any help appreciated .
Thanks simulink, stateflow, enabled MATLAB Answers — New Questions
Why do I receive an error 354 when activating my license?
When activating MATLAB, I receive the following error:
ERROR: Error 354 – No more machine transfers available.
How do I bypass this error so that I can activate my MATLAB?When activating MATLAB, I receive the following error:
ERROR: Error 354 – No more machine transfers available.
How do I bypass this error so that I can activate my MATLAB? When activating MATLAB, I receive the following error:
ERROR: Error 354 – No more machine transfers available.
How do I bypass this error so that I can activate my MATLAB? MATLAB Answers — New Questions
spectrogram x-axis match with data
Hello, I am plotting a spectrogram from an earthquake signal, but the time length of the signal (~250 seconds) does not match the time length displayed in the spectrogram (~100 seconds). Could you help me understand why this discrepancy occurs and how to fix it? Thank you!Hello, I am plotting a spectrogram from an earthquake signal, but the time length of the signal (~250 seconds) does not match the time length displayed in the spectrogram (~100 seconds). Could you help me understand why this discrepancy occurs and how to fix it? Thank you! Hello, I am plotting a spectrogram from an earthquake signal, but the time length of the signal (~250 seconds) does not match the time length displayed in the spectrogram (~100 seconds). Could you help me understand why this discrepancy occurs and how to fix it? Thank you! spectrogram x-axis match MATLAB Answers — New Questions
What is the correct syntax to assign simulated data to my variables?
Dears,
I am running a MS-DSGE model using RISE toolbox. I want to add a fiscal shock and examine its effect on output, price…
%fiscal shock
shock_type = {‘eps_G’};
%here is my variable list of a cell array of character variables and not a struct.
var_list={‘log_y’,’C’,’pi_ann’,’B_nominal’,’B’,’sp’,’i_ann’,’r_real_ann’,’P’};
% EXOGENOUS SWITCHING
myirfs1=irf(m1,’irf_periods’,24,’irf_shock_sign’,1);
% following the suggestion by @VBBV, I use the following sintaxes to access elements of struct
myirfs1 = struct()
myirfs1.eps_CP = struct();
myirfs1.eps_G = struct();
myirfs1.eps_T = struct();
myirfs1.eps_a = struct();
myirfs1.eps_nu = struct();
myirfs1.eps_z = struct();
var_aux = {‘log_y’,’C’,’pi_ann’,’B_nominal’,’B’,’sp’,’i_ann’,’r_real_ann’,’P’};
var_aux3 = {‘eps_G_log_y’,’eps_G_C’,’eps_G_pi_ann’,’eps_G_B_nominal’,’eps_G_B’,’eps_G_sp’,’eps_G_i_ann’,’eps_G_r_real_ann’,’eps_G_P’};
fieldnames(myirfs1)
myirfs1.eps_G.var = var_aux3 % assign the data array to the struct variable
irf_fisc = struct();
for i = 1:numel(var_aux)
irf_fisc.var_aux{i} = [0,myirfs1.eps_G.var{i}]’;
end
irf_fisc.var_aux(1)
irf_fisc
% what is the write syntax to assign value (simulated data) to the struct?
myirfs1.eps_G.logy = data(:,1)/10; %Is the suggested code. but where is the data variable located? should I create it data = randn(TMax, N); or it is already simulated?Dears,
I am running a MS-DSGE model using RISE toolbox. I want to add a fiscal shock and examine its effect on output, price…
%fiscal shock
shock_type = {‘eps_G’};
%here is my variable list of a cell array of character variables and not a struct.
var_list={‘log_y’,’C’,’pi_ann’,’B_nominal’,’B’,’sp’,’i_ann’,’r_real_ann’,’P’};
% EXOGENOUS SWITCHING
myirfs1=irf(m1,’irf_periods’,24,’irf_shock_sign’,1);
% following the suggestion by @VBBV, I use the following sintaxes to access elements of struct
myirfs1 = struct()
myirfs1.eps_CP = struct();
myirfs1.eps_G = struct();
myirfs1.eps_T = struct();
myirfs1.eps_a = struct();
myirfs1.eps_nu = struct();
myirfs1.eps_z = struct();
var_aux = {‘log_y’,’C’,’pi_ann’,’B_nominal’,’B’,’sp’,’i_ann’,’r_real_ann’,’P’};
var_aux3 = {‘eps_G_log_y’,’eps_G_C’,’eps_G_pi_ann’,’eps_G_B_nominal’,’eps_G_B’,’eps_G_sp’,’eps_G_i_ann’,’eps_G_r_real_ann’,’eps_G_P’};
fieldnames(myirfs1)
myirfs1.eps_G.var = var_aux3 % assign the data array to the struct variable
irf_fisc = struct();
for i = 1:numel(var_aux)
irf_fisc.var_aux{i} = [0,myirfs1.eps_G.var{i}]’;
end
irf_fisc.var_aux(1)
irf_fisc
% what is the write syntax to assign value (simulated data) to the struct?
myirfs1.eps_G.logy = data(:,1)/10; %Is the suggested code. but where is the data variable located? should I create it data = randn(TMax, N); or it is already simulated? Dears,
I am running a MS-DSGE model using RISE toolbox. I want to add a fiscal shock and examine its effect on output, price…
%fiscal shock
shock_type = {‘eps_G’};
%here is my variable list of a cell array of character variables and not a struct.
var_list={‘log_y’,’C’,’pi_ann’,’B_nominal’,’B’,’sp’,’i_ann’,’r_real_ann’,’P’};
% EXOGENOUS SWITCHING
myirfs1=irf(m1,’irf_periods’,24,’irf_shock_sign’,1);
% following the suggestion by @VBBV, I use the following sintaxes to access elements of struct
myirfs1 = struct()
myirfs1.eps_CP = struct();
myirfs1.eps_G = struct();
myirfs1.eps_T = struct();
myirfs1.eps_a = struct();
myirfs1.eps_nu = struct();
myirfs1.eps_z = struct();
var_aux = {‘log_y’,’C’,’pi_ann’,’B_nominal’,’B’,’sp’,’i_ann’,’r_real_ann’,’P’};
var_aux3 = {‘eps_G_log_y’,’eps_G_C’,’eps_G_pi_ann’,’eps_G_B_nominal’,’eps_G_B’,’eps_G_sp’,’eps_G_i_ann’,’eps_G_r_real_ann’,’eps_G_P’};
fieldnames(myirfs1)
myirfs1.eps_G.var = var_aux3 % assign the data array to the struct variable
irf_fisc = struct();
for i = 1:numel(var_aux)
irf_fisc.var_aux{i} = [0,myirfs1.eps_G.var{i}]’;
end
irf_fisc.var_aux(1)
irf_fisc
% what is the write syntax to assign value (simulated data) to the struct?
myirfs1.eps_G.logy = data(:,1)/10; %Is the suggested code. but where is the data variable located? should I create it data = randn(TMax, N); or it is already simulated? dsge coding MATLAB Answers — New Questions
rescaleing subfigures within figure
Dear all
I have the attached figure. There, I implied a ratio of the height and the width for the original figure; after removing the label in subfigure(3,1,1) and subfigure(3,1,2), I moved the subfigure(3,1,2) and subfigure(3,1,3) abit up, to avoid the space between the three subfigures. But now the original ratio between the height and the width is not given anymore. I thought of rescaling the subfigures within the figure without changing the size of the figure. But unfortunately, I did not find a command for this. Did I miss a possible command, or is there a workaround?
I hope my issue is clear. Thank you for the help.
Best JakobDear all
I have the attached figure. There, I implied a ratio of the height and the width for the original figure; after removing the label in subfigure(3,1,1) and subfigure(3,1,2), I moved the subfigure(3,1,2) and subfigure(3,1,3) abit up, to avoid the space between the three subfigures. But now the original ratio between the height and the width is not given anymore. I thought of rescaling the subfigures within the figure without changing the size of the figure. But unfortunately, I did not find a command for this. Did I miss a possible command, or is there a workaround?
I hope my issue is clear. Thank you for the help.
Best Jakob Dear all
I have the attached figure. There, I implied a ratio of the height and the width for the original figure; after removing the label in subfigure(3,1,1) and subfigure(3,1,2), I moved the subfigure(3,1,2) and subfigure(3,1,3) abit up, to avoid the space between the three subfigures. But now the original ratio between the height and the width is not given anymore. I thought of rescaling the subfigures within the figure without changing the size of the figure. But unfortunately, I did not find a command for this. Did I miss a possible command, or is there a workaround?
I hope my issue is clear. Thank you for the help.
Best Jakob figure MATLAB Answers — New Questions
How to test custom class with unit test class
Since, I’am very new to the topic of MatLab unit tests, I struggle with testing a custom MatLab class using a unit test class in a separate file.
Like I know from other programming languages, I would like to write a unit test (in a separate class) for a custom MatLab class. However, I do not see how to create an instance of / how to use my custom class within the test class.
Therefore, I would have the following questions, where I hope you can help me:
How do I properly create an instance of my custom class within the test class?
When I place my test class file in a sub-directory "tests/", how do I include the file of the my custom class?
Can you recommend a proper folder structure? Concrete, is it appropriate to place test classes in a sub-folder tests/
Thank you very much!
PS: Up to now – as minimal example – I have a file with a custom class MyMath.m:
classdef MyMath
methods
function obj = MyMath()
end
function outputArg = add(~, a1, a2)
outputArg = a1+a2;
end
end
end
and a file with the test class MyMath_Test.m
classdef MyMath_Test < matlab.unittest.TestCase
methods(TestClassSetup)
% Shared setup for the entire test class
my_math = MyMath();
end
methods(TestMethodSetup)
% Setup for each test
end
methods(Test)
% Test methods
function unimplementedTest(testCase)
res = my_math.add(4,5);
testCase.verifyEqual(res, 9)
end
end
end
Running Tests via Matlab GUI Buttons, results in the error:
>> runtests("MyMath_Test")
Running MyMath_Test
================================================================================
Error occurred while setting up or tearing down MyMath_Test.
As a result, all MyMath_Test tests failed and did not run to completion.
———
Error ID:
———
‘MATLAB:TooManyInputs’
————–
Error Details:
————–
Error using MyMath_Test/MyMath
Too many input arguments.
================================================================================Since, I’am very new to the topic of MatLab unit tests, I struggle with testing a custom MatLab class using a unit test class in a separate file.
Like I know from other programming languages, I would like to write a unit test (in a separate class) for a custom MatLab class. However, I do not see how to create an instance of / how to use my custom class within the test class.
Therefore, I would have the following questions, where I hope you can help me:
How do I properly create an instance of my custom class within the test class?
When I place my test class file in a sub-directory "tests/", how do I include the file of the my custom class?
Can you recommend a proper folder structure? Concrete, is it appropriate to place test classes in a sub-folder tests/
Thank you very much!
PS: Up to now – as minimal example – I have a file with a custom class MyMath.m:
classdef MyMath
methods
function obj = MyMath()
end
function outputArg = add(~, a1, a2)
outputArg = a1+a2;
end
end
end
and a file with the test class MyMath_Test.m
classdef MyMath_Test < matlab.unittest.TestCase
methods(TestClassSetup)
% Shared setup for the entire test class
my_math = MyMath();
end
methods(TestMethodSetup)
% Setup for each test
end
methods(Test)
% Test methods
function unimplementedTest(testCase)
res = my_math.add(4,5);
testCase.verifyEqual(res, 9)
end
end
end
Running Tests via Matlab GUI Buttons, results in the error:
>> runtests("MyMath_Test")
Running MyMath_Test
================================================================================
Error occurred while setting up or tearing down MyMath_Test.
As a result, all MyMath_Test tests failed and did not run to completion.
———
Error ID:
———
‘MATLAB:TooManyInputs’
————–
Error Details:
————–
Error using MyMath_Test/MyMath
Too many input arguments.
================================================================================ Since, I’am very new to the topic of MatLab unit tests, I struggle with testing a custom MatLab class using a unit test class in a separate file.
Like I know from other programming languages, I would like to write a unit test (in a separate class) for a custom MatLab class. However, I do not see how to create an instance of / how to use my custom class within the test class.
Therefore, I would have the following questions, where I hope you can help me:
How do I properly create an instance of my custom class within the test class?
When I place my test class file in a sub-directory "tests/", how do I include the file of the my custom class?
Can you recommend a proper folder structure? Concrete, is it appropriate to place test classes in a sub-folder tests/
Thank you very much!
PS: Up to now – as minimal example – I have a file with a custom class MyMath.m:
classdef MyMath
methods
function obj = MyMath()
end
function outputArg = add(~, a1, a2)
outputArg = a1+a2;
end
end
end
and a file with the test class MyMath_Test.m
classdef MyMath_Test < matlab.unittest.TestCase
methods(TestClassSetup)
% Shared setup for the entire test class
my_math = MyMath();
end
methods(TestMethodSetup)
% Setup for each test
end
methods(Test)
% Test methods
function unimplementedTest(testCase)
res = my_math.add(4,5);
testCase.verifyEqual(res, 9)
end
end
end
Running Tests via Matlab GUI Buttons, results in the error:
>> runtests("MyMath_Test")
Running MyMath_Test
================================================================================
Error occurred while setting up or tearing down MyMath_Test.
As a result, all MyMath_Test tests failed and did not run to completion.
———
Error ID:
———
‘MATLAB:TooManyInputs’
————–
Error Details:
————–
Error using MyMath_Test/MyMath
Too many input arguments.
================================================================================ unit test, object oriented test MATLAB Answers — New Questions
Automatically disable subsystem and manually re-enabled
I need to create the "Enabled Subsystem" which is automatically switch off (disabled) after time expire off and after it is able to restart (Enabled) by writing to the enable.Value from matlab command line (set_param) manually … So basically I am able to fire/enable the single "sine" manually.
Initially I’ve created this
where I use "Set Variable Enable to 0 and stop Generator" with "Parameter Writer" pointing to Enable.Value
Any idea how to go about Algebraic loop or other way to achieve described behavior?I need to create the "Enabled Subsystem" which is automatically switch off (disabled) after time expire off and after it is able to restart (Enabled) by writing to the enable.Value from matlab command line (set_param) manually … So basically I am able to fire/enable the single "sine" manually.
Initially I’ve created this
where I use "Set Variable Enable to 0 and stop Generator" with "Parameter Writer" pointing to Enable.Value
Any idea how to go about Algebraic loop or other way to achieve described behavior? I need to create the "Enabled Subsystem" which is automatically switch off (disabled) after time expire off and after it is able to restart (Enabled) by writing to the enable.Value from matlab command line (set_param) manually … So basically I am able to fire/enable the single "sine" manually.
Initially I’ve created this
where I use "Set Variable Enable to 0 and stop Generator" with "Parameter Writer" pointing to Enable.Value
Any idea how to go about Algebraic loop or other way to achieve described behavior? automatically disabled system and manually enabled MATLAB Answers — New Questions
follow the trend depend on the maximum value
Hello all professional,
@Stephen23 @Harald @Paul @ Adam Danz
please i need urgent help.
i have data for oil level, h_Tank_mm, and related time, time_s
the oil level decrease over the time from maximum to the minimum. when it reach to the minimum value, the technicien refill the tank and start again from maximum. some time there are some peaks or some high drope because the leak.
i need a matlab script that follow the maximum value of the trend like in the figure. if there a high drop in the maximum value, the trend should not effected and stay as no leak.
I want to keep following the trend in order to detect the leakage.Hello all professional,
@Stephen23 @Harald @Paul @ Adam Danz
please i need urgent help.
i have data for oil level, h_Tank_mm, and related time, time_s
the oil level decrease over the time from maximum to the minimum. when it reach to the minimum value, the technicien refill the tank and start again from maximum. some time there are some peaks or some high drope because the leak.
i need a matlab script that follow the maximum value of the trend like in the figure. if there a high drop in the maximum value, the trend should not effected and stay as no leak.
I want to keep following the trend in order to detect the leakage. Hello all professional,
@Stephen23 @Harald @Paul @ Adam Danz
please i need urgent help.
i have data for oil level, h_Tank_mm, and related time, time_s
the oil level decrease over the time from maximum to the minimum. when it reach to the minimum value, the technicien refill the tank and start again from maximum. some time there are some peaks or some high drope because the leak.
i need a matlab script that follow the maximum value of the trend like in the figure. if there a high drop in the maximum value, the trend should not effected and stay as no leak.
I want to keep following the trend in order to detect the leakage. stephen23, harald MATLAB Answers — New Questions
Multiobjective optimization with polygon boundary
I have a fixed designed space. I have the k values of conhull. How do I implement this boundary for the multiobjective optimization problem?I have a fixed designed space. I have the k values of conhull. How do I implement this boundary for the multiobjective optimization problem? I have a fixed designed space. I have the k values of conhull. How do I implement this boundary for the multiobjective optimization problem? multiobj MATLAB Answers — New Questions
Error when change battery parallel and/or series cells in battery module assembly
I’m using the example model charge discharge module assembly with coolant control (openExample(‘simscapebattery/chargeDischargeModuleAssemblyWithCoolantControlExample’). But I change the size of the battery module (for example: number of parallel cells from 4 to 6, and number of series assemblies still on 3) in the CoolantControlCreateLib.mlx.
Then I run ChargeDischargeModuleAssemblyWithCoolantControlExample.mlx but appears an error saying:
Error compiling Simscape network for model coolantControl.
Caused by:
Error using coolantControlLib.ParallelAssemblies.ParallelAssemblyType1> (line 55)
[‘coolantControl/ModuleAssembly/Module1’]: Length of Current (positive in) must be equal to Batteries in Parallel.
Line 55 is:
assert(length(batteryCurrent) == P);
In ParallelAssemblyType1.ssc, P is the parallel cells. Equal to 6.
I don’t understand why length of batterycurrent is not 6.
I checked almost everything and I don’t know what is the cause of the error. thanks!I’m using the example model charge discharge module assembly with coolant control (openExample(‘simscapebattery/chargeDischargeModuleAssemblyWithCoolantControlExample’). But I change the size of the battery module (for example: number of parallel cells from 4 to 6, and number of series assemblies still on 3) in the CoolantControlCreateLib.mlx.
Then I run ChargeDischargeModuleAssemblyWithCoolantControlExample.mlx but appears an error saying:
Error compiling Simscape network for model coolantControl.
Caused by:
Error using coolantControlLib.ParallelAssemblies.ParallelAssemblyType1> (line 55)
[‘coolantControl/ModuleAssembly/Module1’]: Length of Current (positive in) must be equal to Batteries in Parallel.
Line 55 is:
assert(length(batteryCurrent) == P);
In ParallelAssemblyType1.ssc, P is the parallel cells. Equal to 6.
I don’t understand why length of batterycurrent is not 6.
I checked almost everything and I don’t know what is the cause of the error. thanks! I’m using the example model charge discharge module assembly with coolant control (openExample(‘simscapebattery/chargeDischargeModuleAssemblyWithCoolantControlExample’). But I change the size of the battery module (for example: number of parallel cells from 4 to 6, and number of series assemblies still on 3) in the CoolantControlCreateLib.mlx.
Then I run ChargeDischargeModuleAssemblyWithCoolantControlExample.mlx but appears an error saying:
Error compiling Simscape network for model coolantControl.
Caused by:
Error using coolantControlLib.ParallelAssemblies.ParallelAssemblyType1> (line 55)
[‘coolantControl/ModuleAssembly/Module1’]: Length of Current (positive in) must be equal to Batteries in Parallel.
Line 55 is:
assert(length(batteryCurrent) == P);
In ParallelAssemblyType1.ssc, P is the parallel cells. Equal to 6.
I don’t understand why length of batterycurrent is not 6.
I checked almost everything and I don’t know what is the cause of the error. thanks! simscape, battery, simulink MATLAB Answers — New Questions
fitting with custom equation
Hi I am havng troble in fitting the data with costoum eqaution: I/y = x/a + (1-x)/b. with and b are the fitting parametrs. x and y values are as given below.
y = [1.6E5 2.5E5 4.1E5 8E5 1E6 2E6 7E6 2E7]
x = [17 20 27 59 62 81 89 95]
Thank you in advance for your support!Hi I am havng troble in fitting the data with costoum eqaution: I/y = x/a + (1-x)/b. with and b are the fitting parametrs. x and y values are as given below.
y = [1.6E5 2.5E5 4.1E5 8E5 1E6 2E6 7E6 2E7]
x = [17 20 27 59 62 81 89 95]
Thank you in advance for your support! Hi I am havng troble in fitting the data with costoum eqaution: I/y = x/a + (1-x)/b. with and b are the fitting parametrs. x and y values are as given below.
y = [1.6E5 2.5E5 4.1E5 8E5 1E6 2E6 7E6 2E7]
x = [17 20 27 59 62 81 89 95]
Thank you in advance for your support! curve fitting, custom equation MATLAB Answers — New Questions