Unable to convert expression into double array.

2 ビュー (過去 30 日間)
Aishwarya Radhakrishnan
Aishwarya Radhakrishnan 2019 年 9 月 1 日
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.
Aishwarya Radhakrishnan
Aishwarya Radhakrishnan 2019 年 9 月 1 日
Thank you for pointing out.

サインインしてコメントする。

回答 (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 Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by