MATLAB: For loop outputs into matrices

for loopmatrix

I know the code is messy, but my question is for the output of mij, kij, and cij. When I run the code, all three will output like matrices. Is there a way I can set them as matrices, and the take the eig(kij,mij)?
N = 2;
L = 2;
E = 0.25;
x = sym('x');
rho = 10;
EI = 3000000;
xe = 0.7*L;
k = 300000;
M = 3*rho*L;
c = 0.2*sqrt(k*M);
for q = 1:N
for r = 1:N
mu(q) = ((2*q-1)*pi)/2;
alph(q) = (cosh(mu(q))+cos(mu(q)))/(sinh(mu(q))+sin(mu(q)));
beta(q) = mu(q)/L;
mu(r) = ((2*r-1)*pi)/2;
alph(r) = (cosh(mu(r))+cos(mu(r)))/(sinh(mu(r))+sin(mu(r)));
beta(r) = mu(r)/L;
mij(q,r) = vpa(rho*int(((1-(E*x)/L)*(cosh(beta(q)*x)-cos(beta(q)*x)-alph(q)*(sinh(beta(q)*x)-sin(beta(q)*x)))*(cosh(beta(r)*x)-cos(beta(r)*x)-alph(r)*(sinh(beta(r)*x)-sin(beta(r)*x)))),0,L)+M*(cosh(beta(q)*xe)-cos(beta(q)*xe)-alph(q)*(sinh(beta(q)*xe)-sin(beta(q)*xe)))*(cosh(beta(r)*xe)-cos(beta(r)*xe)-alph(r)*(sinh(beta(r)*xe)-sin(beta(r)*xe))),5)
kij(q,r) = vpa(((EI)*((beta(q))^2)*((beta(r))^2)*int((cosh(beta(q)*x)+cos(beta(q)*x)-alph(q)*(sinh(beta(q)*x)+sin(beta(q)*x)))*(cosh(beta(r)*x)+cos(beta(r)*x)-alph(r)*(sinh(beta(r)*x)+sin(beta(r)*x))),0,L)+k*(cosh(beta(q)*xe)-cos(beta(q)*xe)-alph(q)*(sinh(beta(q)*xe)-sin(beta(q)*xe)))*(cosh(beta(r)*xe)-cos(beta(r)*xe)-alph(r)*(sinh(beta(r)*xe)-sin(beta(r)*xe)))),5);
cij(q,r) = vpa(-c*(cosh(beta(q)*L)-cos(beta(q)*L)-alph(q)*(sinh(beta(q)*L)-sin(beta(q)*L)))*(cosh(beta(r)*L)-cos(beta(r)*L)-alph(r)*(sinh(beta(r)*L)-sin(beta(r)*L)))-(-c*(cosh(beta(q)*0)-cos(beta(q)*0)-alph(q)*(sinh(beta(q)*0)-sin(beta(q)*0)))*(cosh(beta(r)*0)-cos(beta(r)*0)-alph(r)*(sinh(beta(r)*0)-sin(beta(r)*0)))),5);
end
end
[V,D] = eig(kij,mij)

Best Answer

Hi all, my question may not have been too clear, but I found the solution I needed, in case anyone else ever has the same issue.
It turns out that my answers were being output as symbolic matrices. So all I had to do was use the double() command. That turned the answers into a useable matrix that I could take the eigenvalues of!