How to stop result being rounded - Symbolic mathematics
1 view (last 30 days)
Show older comments
Christine Zakzewski
on 11 Jan 2022
Commented: Christine Zakzewski
on 12 Jan 2022
Thank you so much for any assistance you can provide.
I am trying to find the time (t > 0) where a function is a maximum, and the integral of the function (0 < t < inf) using symbolic mathematics. Doing this same problem by hand, or using Wolfram-Alpha or using Maple, I get a solution of t = -0.000903 (which we disregard) and t = 0.00168. The value of the integral is 0.00297. With MATLAB, I get a solution of t = -9.3e-04 (which we disregard) and t = 0.00170. The value of the integral is 0.0030. I understand that the MATLAB solutions are merely a rounded version of the other answers, but I cannot seem to change the way the results are displayed to the command window to obtain the final solutions I expect of t = 0.00168 and the integral of 0.00297.
After reading through other forums, I have tried to use the vpa command (see below) and I have tried to alter the way the result is displayed on the command windown using fprintf.
syms t
%Describe the voltage and current functions
v=(10000*t+5)*exp(-400*t);
i=(40*t+0.05)*exp(-400*t);
%Obtain power
p=i*v;
%Obtain the derivative of the power and the time(s) when the derivative is zero
deriv_p=diff(p);
t_when_deriv_p_is_zero=solve(deriv_p == 0, t)
%Attempt to increase the number of digits displayed using vpa
t_when_deriv_p_is_zero=vpa(solve(deriv_p==0),6)
%Obtain only values of time when t>0
%Attempt to increase the number of digits displayed using vpa
t_of_max_p_1=vpa(t_when_deriv_p_is_zero(t_when_deriv_p_is_zero>0),6)
t_of_max_p=t_when_deriv_p_is_zero(t_when_deriv_p_is_zero>0)
%Attempt to increase the number of digits displayed using fprintf
fprintf('%1.5f\n', t_of_max_p_1)
fprintf('%1.5f\n', t_of_max_p)
%Obtain the total energy through integration of the power
%Attempt to increase the number of digits using vpa and fprintf
w_total=vpa(int(p,t,0,inf),6)
w_total=int(p,t,0,inf)
fprintf('%1.5f', w_total)
Thank you for helping me understand MATLAB a little better!!
1 Comment
Accepted Answer
Walter Roberson
on 11 Jan 2022
No problems here.
syms t positive
%Describe the voltage and current functions
v=(10000*t+5)*exp(-400*t);
i=(40*t+0.05)*exp(-400*t);
%Obtain power
p=i*v;
%Obtain the derivative of the power and the time(s) when the derivative is zero
deriv_p=diff(p);
t_when_deriv_p_is_zero=solve(deriv_p == 0, t)
%Attempt to increase the number of digits displayed using vpa
t_when_deriv_p_is_zero=vpa(solve(deriv_p==0),6)
%Obtain only values of time when t>0
%Attempt to increase the number of digits displayed using vpa
t_of_max_p_1=vpa(t_when_deriv_p_is_zero(t_when_deriv_p_is_zero>0),6)
t_of_max_p=t_when_deriv_p_is_zero(t_when_deriv_p_is_zero>0)
%Attempt to increase the number of digits displayed using fprintf
fprintf('%1.5f\n', t_of_max_p_1)
fprintf('%1.5f\n', t_of_max_p)
%Obtain the total energy through integration of the power
%Attempt to increase the number of digits using vpa and fprintf
w_total=vpa(int(p,t,0,inf),6)
w_total=int(p,t,0,inf)
fprintf('%1.5f', w_total)
11 Comments
More Answers (0)
See Also
Categories
Find more on Number Theory 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!