How to solve: Error using symengine 'Unable to convert expression containing symbolic variables into double array.'
Afficher commentaires plus anciens
Hello together,
I'm still quite new to Matlab, but as i try to solve a thermal model for my studies I tried quite a bit to solve on my own without success.
For an explanation:
First I'm having two matrices for local distance to a given radius and the angle respective of a vertical through the center of the circle.
r=2.96; %example radius
lc=14; %example arc of contact
ap=0.12;%example depth of cut
a=3.29e-6;%m^2/s
lambda=12.47;%W/mK
K=512;
L=512;
T_Mi=ones(K,L);
distance=ones(K,L);
rotangle=ones(K,L);
dpi=0.1;
ri=r/dpi;
lci=lc/dpi;
mp_x=-ri+fz/dpi;
mp_y=K/2;
M=[mp_y mp_x];
Q=[1 mp_x];
for i=1:size(distance,1)
for j = 1:size(distance,2)
distance(i,j) = norm([i j]-[mp_y,mp_x],2);
if distance(i,j)<=ri
distance(i,j)=0;
rotangle(i,j)=0;
elseif distance(i,j)>ri
dR=sqrt((mp_x-j)^2+(mp_y-i)^2);
u=M-Q;
v=M-[i j];
rotangle(i,j)=acos(dot(v,u)/(norm(u)*norm(v)));
distance(i,j)=dR-ri;
else
distance(i,j)=0;
end
end
end
And in the following I give symbolic equations, which should by my understanding fill the matrix T_Mi with values. But the error:
'Unable to perform assignment because value of type 'sym' is not convertible to 'double'. Caused by: Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.'
keeps coming, though I tried any variation of assumptions and substitutions.
syms phi R;
vf=fz/dpi*Z_total*N;
vc=2*ri*pi*N/1000;
p00=0.01949;
p10=0.5988;
p01=-0.0001006;
p20=-4.164;
p11=4.871e-05;
p02=-2.923e-08;
h=fz/dpi*sin(phi);
qwp=p00+p10*h+p01*vc+p20*h^2+p11*h*vc+p02*vc^2;
qavg=ap*ri*vpaintegral(qwp,phi,phi_st,phi_ex)*n/lci/ap/dpi*2;
qmax=qavg*((phi_c*sin(phi_c))/(1-cos(phi_c)));
F=(vf/(2*a)*sqrt(((R*cos(phi))+ri*(1-cos(phi))).^2+((R*sin(phi))-ri*sin(phi)).^2));
K_0=bessely(0,F);
G=(qmax*sin(phi))/sin(phi_c)*exp(-(vf*((R*sin(phi))-ri*sin(phi)))/(2*a)).*K_0*ri*cos(phi);
H=vpaintegral(G,phi,phi_st,phi_ex);
T_M=1/pi/lambda*H;
for i=1:size(T_Mi,1)
for j = 1:size(T_Mi,2)
subs(T_M,R,distance(i,j));
T_Mi(i,j)=(T_M); %%Error created in this line
end
end
I hope it's not too much code, and more so that someone can help me solve this.
6 commentaires
for i=1:size(T_Mi,1)
for j = 1:size(T_Mi,2)
T_Mi(i,j) = double(subs(T_M,R,distance(i,j)));
end
end
might work if T_M does not contain the symbolic variable "phi" or other symbolic variables apart from R.
Note that several variables are undefined in the code you supplied
fz=1.0; %added
Z_total = 1.0; %added
N=1.0; %added
phi_st = 1.0; % added
phi_ex = 2.0; % added
n=N; % added
phi_c = 1.0; % added
Niklas M.
le 15 Mar 2022
phi_st and phi_ex are defined as 0 and pi, respectively, so I was hoping it would calculate a real value instead of staying symbolic.
G does not depend on R for that
H=vpaintegral(G,phi,phi_st,phi_ex);
can make sense ?
If G still depends on other symbolic variables apart from phi, you cannot expect a numerical answer. Then you would have to use "int" instead of "vpaintegral". But "int" won't most probably succeed because your integrand is too complex for an analytical antiderivative.
I suggest you do all your computations numerically using "integral" and without symbolic variables.
Niklas M.
le 15 Mar 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Operations on Strings 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!