Unable to convert expression into double array

조회 수: 7 (최근 30일)
Tommaso Attili
Tommaso Attili 2019년 2월 7일
답변: Bo Zhang 2020년 11월 18일
When I run my code, I keep getting this error: "The following error occurred converting from sym to double: Unable to convert expression into double array."
r=50;
d=50;
a=12.61;
syms x
syms y
J=(besselj(0,x*y*a/d))*((1-y^2)^0.5)*y;
B1=int(J, y, [0 1]);
E1=zeros(1,301);
t=0:0.1:30;
for i=1:301
B=B1*besselj(0,x*r/d)*((x*tanh(x))^0.5)*sin((((9.81/d*t(i)^2)*x)*tanh(x))^0.5)*x;
E1(i)=vpaintegral(B, x, [0 2000])
end

채택된 답변

Areej Varamban Kallan
Areej Varamban Kallan 2019년 2월 7일
편집: Areej Varamban Kallan 2019년 2월 7일
Hi Tommaso,
The variable E1 is defined to be a 'double' array outside the foor loop. The variable B is of symbolic type. In the for loop you are attempting to assign each element of a 'double' array to a symbolic object, which is not correct. Redefine E1 as:
E1 = sym(zeros(1,301));
  댓글 수: 1
Tommaso Attili
Tommaso Attili 2019년 2월 7일
Hi Areej,
Thanks for you help. I'll modify my code. Then to plot E1 versus t is it right:
f=double(E1)
plot(t,f)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bo Zhang
Bo Zhang 2020년 11월 18일
thanks

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by