How to get rid of zeros in a matrix?

2 次查看(过去 30 天)
If you run the code you'll notice that aSol is a 4x1 but two of the numbers are zeros and the other two are the same, how can I remove the zeros and make asol equals to a 1x1 number since two of the numbers are the same. Also, is there any way to make a loop to get the values of sol saved separately so i do not have to write asol=sol.a bsol=sol.b ....
k1 = 0.3;
k2 = 0.3;
k3 = 0.4;
k4 = 0.05;
k5 = 0.77;
k6 = 1.373;
k7 = 0.48;
k8 = 0.0017;
k9 = 0.094;
k10 = 3.76;
syms a b c d e f g h i j k m n l s t v w x
eqn1 = k1*w==a;
eqn2 = k2*k==b;
eqn3 = k3*m==c;
eqn4 = k4*n*w==d;
eqn5 = k5*l==e;
eqn6 = k6*s==f;
eqn7 = k7*t*s==g;
eqn8 = k8*v==h;
eqn9 = k9*v==i;
eqn10 = k10*x==j;
eqn11 = a-b==k;
eqn12 = b-c==m;
eqn13 = c-d==n;
eqn14 = d-e==l;
eqn15 = e-g-f==s;
eqn16 = f-g==t;
eqn17 = g-h-i==v;
eqn18 = -a-d+j==w;
eqn19 = a+d-j==x;
sol = solve([eqn1, eqn2, eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9,eqn10,eqn11,eqn12,eqn13,eqn14,eqn15,eqn16,eqn17,eqn18,eqn19], [a,b,c,d,e,f,g,h,i,j,k,m,n,l,s,t,v,w,x]);
aSol = sol.a
bSol = sol.b
cSol = sol.c
  1 个评论
Hiro Yoshino
Hiro Yoshino 2022-10-21
Can you make the question a bit simpler?
Please do not paste all your script but extract your scope you'd like to discuss.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2022-10-21
k1 = 0.3;
k2 = 0.3;
k3 = 0.4;
k4 = 0.05;
k5 = 0.77;
k6 = 1.373;
k7 = 0.48;
k8 = 0.0017;
k9 = 0.094;
k10 = 3.76;
syms a b c d e f g h i j k m n l s t v w x
assume(a ~= 0)
eqn1 = k1*w==a;
eqn2 = k2*k==b;
eqn3 = k3*m==c;
eqn4 = k4*n*w==d;
eqn5 = k5*l==e;
eqn6 = k6*s==f;
eqn7 = k7*t*s==g;
eqn8 = k8*v==h;
eqn9 = k9*v==i;
eqn10 = k10*x==j;
eqn11 = a-b==k;
eqn12 = b-c==m;
eqn13 = c-d==n;
eqn14 = d-e==l;
eqn15 = e-g-f==s;
eqn16 = f-g==t;
eqn17 = g-h-i==v;
eqn18 = -a-d+j==w;
eqn19 = a+d-j==x;
sol = solve([eqn1, eqn2, eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9,eqn10,eqn11,eqn12,eqn13,eqn14,eqn15,eqn16,eqn17,eqn18,eqn19], [a,b,c,d,e,f,g,h,i,j,k,m,n,l,s,t,v,w,x]);
solabc = unique(subs([a, b, c], sol), 'rows')
solabc = 
EXPAND = @(C) C{:};
[aSol, bSol, cSol] = EXPAND(num2cell(solabc))
aSol = 
bSol = 
cSol = 

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Formula Manipulation and Simplification 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by