Converting output results to 00e+00 form

6 次查看(过去 30 天)
I have this:
iL=vpa(dsolve(eqn1,inits,'t'),4)
iL =
0.00467 - 0.0002202*exp(-133.2*t)*sin(2825.0*t) - 0.00467*exp(-133.2*t)*cos(2825.0*t)
How can I get the results like
iL = 4.67e-3 - 2.202e-4*exp(-1.332e+2t)*....
Thanks

回答(2 个)

Jonathan Epperl
Jonathan Epperl 2012-11-11
编辑:Jonathan Epperl 2012-11-11
So that you can change the output format by issuing
format STYLE
in your case
format shortE
you probably knew. And it won't help you here. The only idea I have is converting to string and doing some regular expression magic. So if iL is your symbolic expression. Then this command will get you a string res_str that contains the symbolic expression with all numbers (with decimals) converted to scientific notation
iL = 0.00467 - 0.0002202*exp(-133.2*t)*sin(2825.0*t)-.00467*exp(-133.2*t)*cos(2825.0*t)
res_str = regexprep(char(vpa(iL)),'([0-9]+\.[0-9]+)','${num2str(str2num($1),''%e'')}')
%res_str =
%4.670000e-03 - 2.202000e-04*exp(-1.332000e+02*t)*sin(2.825000e+03*t)-
%4.670000e-03*exp(-1.332000e+02*t)*cos(2.825000e+03*t)
(The extra vpa() command in regexprep is obviously unnecessary here if you called it on your expression earlier already)
Now if you reconvert to a sym, the numbers will be represented in the normal decimal format again, but that shouldn't be a problem: If you want to do algebra with it, use the sym variable, if you want to display use the string form.
  2 个评论
Shahram
Shahram 2012-11-14
Thanks for your answer, this is a good solution, but I'm looking to get the Matlab to produce these results without playing with characters.
Jonathan Epperl
Jonathan Epperl 2012-11-14
I don't think there's a way, but if you find one, let us know!

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-11-14
When you are going through the MATLAB interface, the only options you have for representation in MuPAD are those shown under "flag" in the documentation for "sym".
I do not have the symbolic toolbox to check against; it could be that by working more directly in MuPAD you could force an exponential notation.

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by