필터 지우기
필터 지우기

Error: DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA

조회 수: 24 (최근 30일)
The code gives following error. Could anybody help to overcome the error.
Error using symengine; DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA. Error in sym/double Xstr = mupadmex('symobj::double', S.s, 0);
N=10
syms x
for a = 1:N;
theta = (2*a-1)*pi/2;
b0 = 1/cosh(theta);
al(a) = theta + (-1)^(a+1)*b0 - b0*b0 + b0^3*((1/3)*(-1)^3*a + 2*(-1)^a+1);
beta(a) = (cosh(al(a)) + cos(al(a))) / (sinh(al(a)) + sin(al(a))) ;
mode_bending(a) = (cosh(al(a).*x) - cos(al(a).*x) - beta(a).*(sinh(al(a).*x) - sin(al(a).*x)));
end
G1 = sym(zeros(N, N));
G2 = sym(zeros(N, N));
for j=1:N
for k=1:N
theta = (2*k-1)*pi/2;
b0 = 1/cosh(theta);
a = theta + (-1)^(k+1)*b0 - b0*b0 + b0^3*((1/3)*(-1)^3*a + 2*(-1)^a+1);
b = (cosh(a) + cos(a)) / (sinh(a) + sin(a)) ;
mode = (cosh(a*x) - cos(a*x) - b*(sinh(a*x) - sin(a*x)));
mode_dot = diff(mode,x);
mode_ddot = diff(mode,x,2);
fun = mode_dot^2;
fun_int = int(fun,0,x)
fun_dint = int(fun_int,1,x)
N2 = diff(mode_dot*fun_dint,x)
f2 = mode_bending(j)* N2
G2(j,k) = double(int(f2,0,1))
end
end

답변 (2개)

Marco Morganti
Marco Morganti 2017년 1월 5일
Hello Lokesh,
double() cannot be used to convert symbolic expressions. You can instead use vpa() (Variable-Precision Arithmetic). I therefore suggest changing:
G2(j,k) = double(int(f2,0,1));
with:
G2(j,k) = vpa(int(f2,0,1));
You can also change the precision of vpa() by adding a second Argument to specify the amount of significant Digits. I hope this helps:)

Walter Roberson
Walter Roberson 2017년 1월 5일
double can be used to convert symbolic expressions that can be resolved to a numeric value. However, not all numeric int() converge so int() cannot always be converted to double.
Also, when you double() an int() then that is evaluated at 16 digits which might not be enough to find convergence but using more digits might be enough. Because of this sometimes it helps to use
double(vpa(int(f2, 0,1))
If you have a new enough version of MATLAB you might be able to use
double(vpaintegral(f2, 0,1))

제품

Community Treasure Hunt

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

Start Hunting!

Translated by