Unable to convert expression into double array.
조회 수: 4 (최근 30일)
이전 댓글 표시
My code snippet is as follows:
syms X mu std ;
sym pi;
definite_int = inline('(2*pi*(std^2))^(-0.5)* exp(-((X-mu).^2)/(2*(std^2)))', 'X','mu','std','pi');
inte = vpaintegral(definite_int(x, mu, std, pi),[20 120])
inte = double(vpa(inte))
figure('Name','plot ');
for i = 2:20
height = 20:i:120;
ri = sum(height .* i);
error = ri - inte
plot(error, i);
hold on
end
I am getting the following error:
integration =
[ vpaintegral(exp(-(mu - 60)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 62)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 64)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 66)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 68)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 70)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 72)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 74)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 76)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 78)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120), vpaintegral(exp(-(mu - 80)^2/(2*std^2))/(2*std^2*pi)^(1/2), std, 20, 120)]
Error using symengine
Unable to convert expression into double array.
Error in sym/double (line 692)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in hw1>question4 (line 125)
integration = double(vpa(integration))
How should I solve this error? please help
댓글 수: 2
답변 (1개)
Walter Roberson
2019년 9월 1일
Using double() on the vpaintegral() result can only possibly work if you are using vpaintegral() on a formula that has exactly one unresolved symbolic variable. mu and std are unresolved in your integral as well as X, so you cannot possibly get out a symbolic numeric result from the integral.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!