How to convert symbolic output to numeric value in Symbolic Math Toolbox?
Show older comments
Dear MATLAB users,
I tried to calculate following problem using Symbolic Math Toolbox.



Unfortunately, I have faced some problems using Symbolic Math Toolbox.
My code is as follows.
My problem is when i run this code, when the mu is small number, the P0, Pmu an Pc is calculated as numerical value.
But, starts from some points, the results are shown like 'round((513*vpasum(Inf/gamma(n + 181), n, 0, Inf))/2500)'.
When i tried to convert this kind of output to numerical value, it fails.
Therefore, is there any way to convert this kind of output to numerical value?
Thanks in advance!
syms n mu P0 Pmu Pc obj sigma lambda k
lambda=20
sigma=0.1
for mu=1:40
an=symprod(lambda/(mu+(k*sigma)),k,1,n);
P0=1/(1+symsum(an,n,1,Inf));
Pmu=mu*P0_record*vpa(symsum(((lambda^n)*gamma(1+(mu/sigma)))/((sigma^n)*(mu+n*sigma)*gamma(1+n+(mu/sigma))),n,0,Inf));
Pc=(1-P0)*(mu/(mu+sigma));
obj=Pmu*Pc;
P0_record(mu)=round(P0,4);
Pmu_record(mu)=round(Pmu,4);
Pc_record(mu)=round(Pc,4);
obj_record(mu)=round(obj,4);
end
Accepted Answer
More Answers (2)
KSSV
on 7 Feb 2023
0 votes
Amal Raj
on 7 Feb 2023
Hi,
You can use the vpa function to convert the symbolic expression to a numerical value with a specified number of digits.
Then go on with the calculation.
P0=1/(1+symsum(an,n,1,Inf));
Pmu=mu*P0_record*vpa(symsum(((lambda^n)*gamma(1+(mu/sigma)))/((sigma^n)*(mu+n*sigma)*gamma(1+n+(mu/sigma))),n,0,Inf));
Pc=(1-P0)*(mu/(mu+sigma));
% 32 significat digits
P0=vpa(1/(1+symsum(an,n,1,Inf)),32);
Pmu=vpa(mu*P0_record*vpa(symsum(((lambda^n)*gamma(1+(mu/sigma)))/((sigma^n)*(mu+n*sigma)*gamma(1+n+(mu/sigma))),n,0,Inf)),32);
Pc=vpa((1-P0)*(mu/(mu+sigma)),32);
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






