Converting output results to 00e+00 form
이전 댓글 표시
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
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
2012년 11월 14일
Jonathan Epperl
2012년 11월 14일
I don't think there's a way, but if you find one, let us know!
Walter Roberson
2012년 11월 14일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!