Unable to convert expression into double array.

16 次查看(过去 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 个评论
Stephen23
Stephen23 2019-9-1
Note that the inline documentation states in bold letters at the top of the page:
"inline will be removed in a future release. Use Anonymous Functions instead."
Instead of using obsolete inline, you should use efficient function handles.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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.

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by