Converting output results to 00e+00 form

조회 수: 2 (최근 30일)
Shahram
Shahram 2012년 11월 10일
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