How to fix symbolic errors
1 回表示 (過去 30 日間)
古いコメントを表示
I have the following function defined that will be used in a main script:
function ke = Ke2Diso(E, nu, Xe, Ye)
E_matrix = E/(1-nu^2)*[1 nu 0;nu 1 0;0 0 (1-nu)/2];
syms zeta eta ;
N1 = ((1-zeta)*(1+eta))/4;
N2 = ((1+zeta)*(1+eta))/4;
N3 = ((1-zeta)*(1-eta))/4;
N4 = ((1+zeta)*(1-eta))/4;
N = [N1 N2 N3 N4];
dxdzeta = 0;
dxdeta = 0 ;
dydzeta = 0;
dydeta = 0;
for i = 1:4
dxdzeta =dxdzeta+ Xe(i)*diff(N(i),zeta);
dxdeta =dxdeta+ Xe(i)*diff(N(i),eta);
dydzeta =dydzeta+ Ye(i)*diff(N(i),zeta);
dydeta =dydeta+ Ye(i)*diff(N(i),eta);
end
J = [dxdzeta dydzeta;dxdeta dydeta];
B_xy = zeros(2,4)
for i =1:4
B_xy(1,i) = diff(N(i),zeta);
B_xy(2,i) = diff(N(i),eta);
end
dNdx_dNdy = inv(J)* B_xy
%2 by 4 matrix
B_e = [dNdx_dNdy(1,1) 0 dNdx_dNdy(1,2) 0 dNdx_dNdy(1,3) 0 dNdx_dNdy(1,4) 0;...
0 dNdx_dNdy(2,1) 0 dNdx_dNdy(2,2) 0 dNdx_dNdy(2,3) 0 dNdx_dNdy(2,4) ;...
dNdx_dNdy(2,1) dNdx_dNdy(1,1) dNdx_dNdy(2,2) dNdx_dNdy(1,2) dNdx_dNdy(2,3) dNdx_dNdy(1,3) dNdx_dNdy(2,4) dNdx_dNdy(1,4)];
%Gauss quadrature
B_e_new = subs(B_e)
%B_e_new = subs(B_e,[zeta,eta],[1/sqrt(3),1/sqrt(3)]) + subs(B_e,[zeta,eta],[1/sqrt(3),-1/sqrt(3)])+...
% subs(B_e,[zeta,eta],[-1/sqrt(3),1/sqrt(3)])+subs(B_e,[zeta,eta],[-1/sqrt(3),-1/sqrt(3)])
B = B_e_new(1/sqrt(3),1/sqrt(3))+B_e_new(1/sqrt(3),-1/sqrt(3))+B_e_new(-1/sqrt(3),-1/sqrt(3))+B_e_new(-1/sqrt(3),1/sqrt(3))
E_matrix_new = subs(E_matrix)
J_new = subs(J,[zeta,eta],[1/sqrt(3),1/sqrt(3)])+subs(J,[zeta,eta],[-1/sqrt(3),1/sqrt(3)])+subs(J,[zeta,eta],[-1/sqrt(3),-1/sqrt(3)])+subs(J,[zeta,eta],[1/sqrt(3),-1/sqrt(3)])
ke = det(J_new)*(transpose(B)*E_matrix_new*B)
This script has the following error:
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.
Error in Ke2Diso (line 31)
B_xy(1,i) = diff(N(i),zeta);
Error in K_assembly (line 15)
ke = Ke2Diso(E, nu, Xe, Ye); % obtain element stiffness matrix
Error in Main2DElastic (line 24)
K = K_assembly(ne, nnodes, X, Y, E, nu, nodemap);
Caused by:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
I'm pretty confused about how to use subs properly. Can someone help me troubleshoot it?
0 件のコメント
回答 (1 件)
Star Strider
2021 年 11 月 18 日
The problem is in ‘line 31’ and I suspect the reason is that ‘B_xy’ is initialised as a double array.
I have no idea what the arguments should be, so see if —
B_xy = sym(zeros(2,4))
whos B_xy
will produce the desired result. It appears to work in this isolated example.
.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!