Error in assigning value to the output variable while solving non-linear equations

1 visualización (últimos 30 días)
While running the following code I am getting this error. I need to show min positive real value out of all solutions for the particular variable. May I please get this error fixed or get some advice how it can be done.
Unable to perform assignment because the left and right sides have a different number of elements.
Error in SpeciationCal (line 38) m(i)=min(S.a)
syms a b c
x3=[ 0.038813753 0.109515494 0.258253623 0.250365943 0.266695352 0.254064153 0.355464596 0.367390937 0.367899743];
x1=[ 0.75197909 0.647030256 0.315659359 0.381316826 0.324185571 0.385450182 0.198472313 0.161364552 0.181784492];
x2=[ 0.209207157 0.243454249 0.426087018 0.368317231 0.409119077 0.360485665 0.446063091 0.47124451 0.450315765];
T=[384.2 392.1 396.4 392 406.1 405 409.6 416.2 416.4 417.1];
roundn = @(x,n) round(x.*10.^n)./10.^n;
x1=roundn(x1,5)
x2=roundn(x2,5)
x3=roundn(x3,5)
N=length(x1);
K1=zeros(N,1);K2=zeros(N,1);K3=zeros(N,1);m=zeros(N,1);n=zeros(N,1);o=zeros(N,1);
for i=1:N
K1(i)=exp((-936.28)+((40216.27)/T(i))+(151.983*(log(T(i))))+(-0.1675*(T(i))))
K2(i)=exp((1044.78)+(-45171.42/T(i))+(-165.20*log(T(i))+(0.1511*(T(i)))))
K3(i)=exp((-228.838)+(12587.48/T(i))+(40.68593*log(T(i)))+(-0.09838*(T(i))))
eqns=[((a*(a-b-3*b))/((x1(i)-a-c+3*b)^4*(x2(i)-a-c)))==K1,((b*3*b)/(a-b-3*b)*(x3(i)-b))==K2,((c*c)/((x1(i)-a-c+3*b)*(x2(i)-a-c)))==K3]
S=vpasolve(eqns,[a,b,c])
warning('off', 'symbolic:numeric:NumericalInstability')
S.a(S.a<0)=[];
S.b(S.b<0)=[];
S.c(S.c<0)=[];
idxa= abs(imag(S.a)) < eps;
idxb = abs(imag(S.b)) < eps;
idxc = abs(imag(S.c)) < eps;
S.a = S.a(idxa);
S.b = S.b(idxb);
S.c = S.c(idxc);
m(i)=min(S.a)
n(i)=min(S.b)
o(i)=min(S.c)
end

Respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by