Convert sym to double
Afficher commentaires plus anciens
I try to find out the DW (The last line of code I showed below). I used sym x y at the beginning because I need to differentiate W with respect to second order x. After the differentiation, I substitute x and y with real value, X and Y. But when I tried to run the code, there is an error indicated "Unable to perform assignment because value of type 'sym' is not convertible to 'double'." Therefore, I am curious that if I can transfer sym to double or if there is alternative method to find out DW. Thank you very much!!
clc
clear
format long
v=0.3;
E=(209e+3)*10^6;
G=E/(2*(1+v));
q=-0.1*10^6;
h=15*10^(-3);
D=(E*h^3)/(12*(1-v^2));
I=(h^3)/12;
a=600*(10^-3);b=2400*(10^-3);
syms x y
c=13
for f = 1:c
k=[3:2:1+2*c];
mn{f}= 1:2:k(f)
end
for f=1:c
len=length(mn{f});
rfa_m=zeros(1,len);
for i=1:len
m=mn{f}(i)
rfa_m(i)= (m.*pi*b)./(2*a)
end
Am=zeros(1,len);
for i=1:len
m=mn{f}(i)
Am(i)=-2*(rfa_m(i)*tanh(rfa_m(i))+2)./((pi^5)*(m^5)*cosh(rfa_m(i)))
end
Bm=zeros(1,len);
for i=1:len
m=mn{f}(i)
Bm(i)=2./((pi^5)*(m^5)*cosh(rfa_m(i)))
end
W=zeros(1,len);
for i=1:len
m=mn{f}(i)
W(i)=(q/(24*D))*(x^4-2*a*x^3+(a^3)*x)+((q*a^4)/D).*sum((Am(i).*cosh(m(i).*pi*y./a)+Bm(i).*(m(i).*pi*y/a).*sinh(m(i).*pi*y./a)).*sin(m(i).*pi*x./a))
end
for i=1:len
m=mn{f}(i)
DW(i)=diff(W(i),x,2)
end
X=600*(10^-3);
Y=0;
DW=subs(DW,{x,y},{X,Y})
end
1 commentaire
KSSV
le 16 Juin 2022
Your RHS is a syms class, you cannot convert it into double unless you substitute the values of x.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!