How can i compress this code into some form of loop so that it is not so bulky?!
1 次查看(过去 30 天)
显示 更早的评论
s=2;
n=sym('n');
f1=n;
f2=n^2;
f3=n^3;
f4=n^4;
fprime1=1;
fprime2=2*n;
fprime3=3*n^2;
fprime4=4*n^3;
c=0.55-0.075*2*n-0.175*2*n;
e=(1/4*c-0.2)/c;
g11=5.5*(1-n^3)*e*c^2*f1^2;
g12=5.5*(1-n^3)*e*c^2*f1*f2;
g13=5.5*(1-n^3)*e*c^2*f1*f3;
g14=5.5*(1-n^3)*e*c^2*f1*f4;
g22=5.5*(1-n^3)*e*c^2*f2^2;
g23=5.5*(1-n^3)*e*c^2*f2*f3;
g24=5.5*(1-n^3)*e*c^2*f2*f4;
g33=5.5*(1-n^3)*e*c^2*f3^2;
g34=5.5*(1-n^3)*e*c^2*f3*f4;
g44=5.5*(1-n^3)*e*c^2*f4^2;
K11=(-s)*int(g11,0,1);
K12=(-s)*int(g12,0,1);
K13=(-s)*int(g13,0,1);
K14=(-s)*int(g14,0,1);
K22=(-s)*int(g22,0,1);
K23=(-s)*int(g23,0,1);
K24=(-s)*int(g24,0,1);
K33=(-s)*int(g33,0,1);
K34=(-s)*int(g34,0,1);
K44=(-s)*int(g44,0,1);
K11=double(K11);
K12=double(K12);
K13=double(K13);
K14=double(K14);
K22=double(K22);
K23=double(K23);
K24=double(K24);
K33=double(K33);
K34=double(K34);
K44=double(K44);
K21=K12;
K31=K13;
K41=K14;
K32=K23;
K42=K24;
K43=K34;
Kij=[K11,K12,K13,K14;K21,K22,K23,K24;K31,K32,K33,K34;K41,K42,K43,K44];
f11=700*(1-0.5*n)*fprime1^2;
f12=700*(1-0.5*n)*fprime1*fprime2;
f13=700*(1-0.5*n)*fprime1*fprime3;
f14=700*(1-0.5*n)*fprime1*fprime4;
f22=700*(1-0.5*n)*fprime2^2;
f23=700*(1-0.5*n)*fprime2*fprime3;
f24=700*(1-0.5*n)*fprime2*fprime4;
f33=700*(1-0.5*n)*fprime3^2;
f34=700*(1-0.5*n)*fprime3*fprime4;
f44=700*(1-0.5*n)*fprime4^2;
E11=(1/s)*int(f11,0,1);
E12=(1/s)*int(f12,0,1);
E13=(1/s)*int(f13,0,1);
E14=(1/s)*int(f14,0,1);
E22=(1/s)*int(f22,0,1);
E23=(1/s)*int(f23,0,1);
E24=(1/s)*int(f24,0,1);
E33=(1/s)*int(f33,0,1);
E34=(1/s)*int(f34,0,1);
E44=(1/s)*int(f44,0,1);
E11=double(E11);
E12=double(E12);
E13=double(E13);
E14=double(E14);
E22=double(E22);
E23=double(E23);
E24=double(E24);
E33=double(E33);
E34=double(E34);
E44=double(E44);
E21=E12;
E31=E13;
E41=E14;
E32=E23;
E42=E24;
E43=E34;
Eij=[E11,E12,E13,E14;E21,E22,E23,E24;E31,E32,E33,E34;E41,E42,E43,E44];
q=eig(Eij,Kij)
0 个评论
回答(1 个)
sixwwwwww
2013-10-22
Dear Joel, you can make this code compact in the following way:
s = 2;
syms n
i = 1:4;
f = n.^i;
fprime = i .* n.^(i - 1);
c = 0.55 - 0.075 * 2 * n - 0.175 * 2 * n;
e = (1 / 4 * c - 0.2) / c;
g = 5.5 * (1 - n^3) * e * c^2 * [f(1)^2, f(1) * f(2), f(1) * f(3), f(1) * f(4), f(2)^2, f(2) * f(3), f(2) * f(4), f(3)^2, f(3)*f(4), f(4)^2];
K = double((-s) * int(g, 0, 1));
Kij = [K(1:4); K(2),K(5:7); K(3), K(6), K(8:9); K(4), K(7), K(9:10)];
F = 700 * (1 - 0.5 * n) * [fprime(1)^2, fprime(1) * fprime(2), fprime(1) * fprime(3), fprime(1) * fprime(4), fprime(2)^2, fprime(2) * fprime(3),...
fprime(2) * fprime(4), fprime(3)^2, fprime(3) * fprime(4), fprime(4)^2];
E = double((1 / s) * int(F, 0, 1));
Eij = [E(1:4); E(2),E(5:7); E(3), E(6), E(8:9); E(4), E(7), E(9:10)];
q = eig(Eij, Kij);
I hope it helps. Good luck!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!