How to change exponentiation

1 次查看(过去 30 天)
Hello,
I want to change exponentiation from ^-5 to ^-6 and too format but will that 2. The command window is dense how can to do that line spacing.
Example the strain tensor is:
I need it accuracy to be like that:
Thanks for the helpers :)
My code:
clc;
clear;
sigma=input('Insert normal stresses[Mpa] and shear stresse[Mpa] of the cauchy stress tensor:');
sigma_xx=sigma(1,1);
tau_xy=sigma(1,2);
tau_xz=sigma(1,3);
tau_yx=sigma(2,1);
sigma_yy=sigma(2,2);
tau_yz=sigma(2,3);
tau_zx=sigma(3,1);
tau_zy=sigma(3,2);
sigma_zz=sigma(3,3);
disp('The matrix is'); disp(sigma);
Metal = input('Insert type of a metal material:','s');
switch Metal
case 'AISI1020'
S_y = 427;
G = 80000;
v = 0.29;
E = 207000;
case 'Alloy6061-T6'
S_y = 276;
G = 26000;
v = 0.33;
E = 69000;
case 'SAE4340'
S_y = 910;
G = 83000;
v = 0.29;
E = 214000;
end
epsilon_x=(1/E)*((sigma_xx)-v*((sigma_yy)+(sigma_zz))) ;
epsilon_y=(1/E)*((sigma_yy)-v*((sigma_zz)+(sigma_xx))) ;
epsilon_z=(1/E)*((sigma_zz)-v*((sigma_xx)+(sigma_yy))) ;
gamma_xy=(tau_xy)/(2*G) ;
gamma_xz=(tau_xz)/(2*G) ;
gamma_yz=(tau_yz)/(2*G) ;
gamma_yx=gamma_xy;
gamma_zx=gamma_xz;
gamma_zy=gamma_yz;
epsilon=zeros(3,3);
epsilon(1,1)=epsilon_x;
epsilon(1,2)=gamma_xy;
epsilon(1,3)=gamma_xz;
epsilon(2,1)=gamma_yx;
epsilon(2,2)=epsilon_y;
epsilon(2,3)=gamma_yz;
epsilon(3,1)=gamma_zx;
epsilon(3,2)=gamma_zy;
epsilon(3,3)=epsilon_z;
disp('The strain tensor is')
fprintf('%g %g %g\n',epsilon)

采纳的回答

Star Strider
Star Strider 2020-11-20
I wrote a littlle utility function for my own use a while back to do this.
Adapt it to do what you want:
expstr = @(x,n) [x(:).*10.^(-n*floor(log10(abs(x(:)))/abs(n))) n*floor(log10(abs(x(:)))/abs(n))];
a=-0.07639297;
Result1 = sprintf('%.7fE%+04d', expstr(a,2))
Result2 = sprintf('%.7fE%+04d', expstr(a,6))
Result3 = sprintf('%.7fE%+04d', expstr(a,-4))
producing:
Result1 =
'-7.6392970E-002'
Result2 =
'-76392.9700000E-006'
Result3 =
'-0.0000076E+004'
.

更多回答(1 个)

Steven Lord
Steven Lord 2020-11-20
Change the display format.
format % default which is "format short"
e = [5.45894e-6, -1.875e-5, 6.25e-6; ...
-1.875e-5, 1.79227e-5, 3.125e-5; ...
6.25e-6, 3.125e-5, -1.32367e-5];
disp(e)
1.0e-04 * 0.0546 -0.1875 0.0625 -0.1875 0.1792 0.3125 0.0625 0.3125 -0.1324
format long
disp(e)
1.0e-04 * 0.054589400000000 -0.187500000000000 0.062500000000000 -0.187500000000000 0.179227000000000 0.312500000000000 0.062500000000000 0.312500000000000 -0.132367000000000
format shorteng
disp(e)
5.4589e-006 -18.7500e-006 6.2500e-006 -18.7500e-006 17.9227e-006 31.2500e-006 6.2500e-006 31.2500e-006 -13.2367e-006

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by