The last line is wrong. The system reminds that "Input function must return 'double' or 'single' values. Found 'sym'." How can I obtain the constant matrix K after integral ?

%%%%%I would like to obtain the constant matrix K
clc
clear
h=0.03;
E=1*10^9;
miu=0.3;
df1=[1;0;0];
df2=[0;1;0];
e1=[1;0;0];
e2=[0;1;0];
e3=[0;0;1];
D=(E/(1-miu*miu))*[1,miu,0;miu,1,0;0,0,(1-miu)/2];
syms xta eta
Bm=zeros(3,3,'sym');
Bb=zeros(3,3,'sym');
K=zeros(3,3,'sym');
M=@(xta)(xta>=0&xta<0.5).*(((0.5-xta)./0.5).*((0.5-xta)./0.5)); %% Define a piecewise function
DM=@(xta)(xta>=0&xta<0.5).*(8.*xta-4); %% Define the differential equation of first order
DDM=@(xta)(xta>=0&xta<0.5).*(8); %% Define the differential equation of second order
N=@(eta)(eta>=0&eta<0.5).*(((0.5-eta)./0.5).*((0.5-eta)./0.5)); %% Define another piecewise function
DN=@(eta)(eta>=0&eta<0.5).*(8.*eta-4); %% Define the differential equation of first order
DDN=@(eta)(eta>=0&eta<0.5).*(8); %% Define the differential equation of second order
f1=@(xta,eta)DM(xta).*N(eta); %%%product a new piecewise function based on previous piecewise functions
f2=@(xta,eta)M(xta).*DN(eta); %%%product a new piecewise function based on previous piecewise functions
%%%%%Caculte the matrix Bm
Bm=[(f1(xta,eta))*df1'*e1,(f1(xta,eta))*df1'*e2,(f1(xta,eta))*df1'*e3;
(f2(xta,eta))*df2'*e1,(f2(xta,eta))*df2'*e2,(f2(xta,eta))*df2'*e3;
((f2(xta,eta))*df1'+(f1(xta,eta))*df2')*e1,((f2(xta,eta))*df1'+(f1(xta,eta))*df2')*e2,((f2(xta,eta))*df1'+(f1(xta,eta))*df2')*e3];
%%%%%%%%%%%%%%%%%
%%%%%Caculte the matrix Bb
T=[0;0;1];
g1=@(xta,eta)DDM(xta).*N(eta);
g2=@(xta,eta)M(xta).*DDN(eta);
g3=@(xta,eta)DM(xta).*DN(eta);
Bb=-[(g1(xta,eta))*T'*e1,(g1(xta,eta))*T'*e2,(g1(xta,eta))*T'*e3;
(g2(xta,eta))*T'*e1,(g2(xta,eta))*T'*e2,(g2(xta,eta))*T'*e3;
2*(g3(xta,eta))*T'*e1,2*(g3(xta,eta))*T'*e2,2*(g3(xta,eta))*T'*e3];
%%%%%%%%%%%%%%%%%
K0=(h.*Bm'*D.*Bm+(h*h*h/12)*Bb'*D.*Bb);
K=integral2(@(xta,eta)K0,0,1,0,1) %%%calculte the intergration of K0
%%% In theory,the matrix K should be a constant matrix after the integraion

 Accepted Answer

So many problems. Had to restructure the code completely.
value = zeros(3,3);
for i=1:3
for j=1:3
value(i,j) = integral2(@(x,y)fun(x,y,i,j),0,1,0,1);
end
end
value
function values = fun(XTA,ETA,I,J)
for i=1:size(XTA,1)
for j=1:size(XTA,2)
xta=XTA(i,j);
eta=ETA(i,j);
h=0.03;
E=1*10^9;
miu=0.3;
df1=[1;0;0];
df2=[0;1;0];
e1=[1;0;0];
e2=[0;1;0];
e3=[0;0;1];
D=(E/(1-miu*miu))*[1,miu,0;miu,1,0;0,0,(1-miu)/2];
M=(xta>=0&xta<0.5).*(((0.5-xta)./0.5).*((0.5-xta)./0.5)); %% Define a piecewise function
DM=(xta>=0&xta<0.5).*(8.*xta-4); %% Define the differential equation of first order
DDM=(xta>=0&xta<0.5).*(8); %% Define the differential equation of second order
N=(eta>=0&eta<0.5).*(((0.5-eta)./0.5).*((0.5-eta)./0.5)); %% Define another piecewise function
DN=(eta>=0&eta<0.5).*(8.*eta-4); %% Define the differential equation of first order
DDN=(eta>=0&eta<0.5).*(8); %% Define the differential equation of second order
f1=DM.*N; %%%product a new piecewise function based on previous piecewise functions
f2=M.*DN; %%%product a new piecewise function based on previous piecewise functions
%%%%%Caculte the matrix Bm
Bm=[(f1)*df1'*e1,(f1)*df1'*e2,(f1)*df1'*e3;
(f2)*df2'*e1,(f2)*df2'*e2,(f2)*df2'*e3;
((f2)*df1'+(f1)*df2')*e1,((f2)*df1'+(f1)*df2')*e2,((f2)*df1'+(f1)*df2')*e3];
%%%%%%%%%%%%%%%%%
%%%%%Caculte the matrix Bb
T=[0;0;1];
g1=DDM.*N;
g2=M.*DDN;
g3=DM.*DN;
Bb=-[(g1)*T'*e1,(g1)*T'*e2,(g1)*T'*e3;
(g2)*T'*e1,(g2)*T'*e2,(g2)*T'*e3;
2*(g3)*T'*e1,2*(g3)*T'*e2,2*(g3)*T'*e3];
%%%%%%%%%%%%%%%%%
K0=(h.*Bm'*D.*Bm+(h*h*h/12)*Bb'*D.*Bb);
values(i,j) = K0(I,J);
end
end
end

More Answers (0)

Categories

Products

Release

R2020b

Asked:

on 15 Apr 2022

Commented:

on 15 Apr 2022

Community Treasure Hunt

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

Start Hunting!