Matrix display wrong value

1 vue (au cours des 30 derniers jours)
Young Lee
Young Lee le 7 Juin 2023
Déplacé(e) : Rik le 7 Juin 2023
clear all
clc
% This is Tutorial Q1 Very important make sure the parameters are correct
L1=1000;
L2=2000;
b1=10;
h1=10;
b2=20;
h2=20;
A1=b1*h1;
A2=b2*h2;
E1=70e3;
E2=205e3;
c1=cos(deg2rad(0));
s1=sin(deg2rad(0));
c2=cos(deg2rad(-90));
s2=sin(deg2rad(-90));
I1=b1*h1^3/12;
I2=b2*h2^3/12;
k1 = [ A1*E1/L1 0 0 -A1*E1/L1 0 0; ...
0 12*E1*I1/L1^3 6*E1*I1/L1^2 0 -12*E1*I1/L1^3 6*E1*I1/L1^2; ...
0 6*E1*I1/L1^2 4*E1*I1/L1 0 -6*E1*I1/L1^2 2*E1*I1/L1; ...
-A1*E1/L1 0 0 A1*E1/L1 0 0; ...
0 -12*E1*I1/L1^3 -6*E1*I1/L1^2 0 (12*E1*I1)/L1^3 -6*E1*I1/L1^2; ...
0 6*E1*I1/L1^2 2*E1*I1/L1 0 -6*E1*I1/L1^2 4*E1*I1/L1]
k1 = 6×6
1.0e+05 * 0.0700 0 0 -0.0700 0 0 0 0.0000 0.0035 0 -0.0000 0.0035 0 0.0035 2.3333 0 -0.0035 1.1667 -0.0700 0 0 0.0700 0 0 0 -0.0000 -0.0035 0 0.0000 -0.0035 0 0.0035 1.1667 0 -0.0035 2.3333
k2 = [ A2*E2/L2 0 0 -A2*E2/L2 0 0; ...
0 12*E2*I2/L2^3 6*E2*I2/L2^2 0 -12*E2*I2/L2^3 6*E2*I2/L2^2; ...
0 6*E2*I2/L2^2 4*E2*I2/L2 0 -6*E2*I2/L2^2 2*E2*I2/L2; ...
-A2*E2/L2 0 0 A2*E2/L2 0 0; ...
0 -12*E2*I2/L2^3 -6*E2*I2/L2^2 0 12*E2*I2/L2^3 -6*E2*I2/L2^2; ...
0 6*E2*I2/L2^2 2*E2*I2/L2 0 -6*E2*I2/L2^2 4*E2*I2/L2]
k2 = 6×6
1.0e+06 * 0.0410 0 0 -0.0410 0 0 0 0.0000 0.0041 0 -0.0000 0.0041 0 0.0041 5.4667 0 -0.0041 2.7333 -0.0410 0 0 0.0410 0 0 0 -0.0000 -0.0041 0 0.0000 -0.0041 0 0.0041 2.7333 0 -0.0041 5.4667
lamd1 = [c1 s1 0 0 0 0; ...
-s1 c1 0 0 0 0; ...
0 0 1 0 0 0; ...
0 0 0 c1 s1 0; ...
0 0 0 -s1 c1 0; ...
0 0 0 0 0 1];
lamd2 = [c2 s2 0 0 0 0; ...
-s2 c2 0 0 0 0; ...
0 0 1 0 0 0; ...
0 0 0 c2 s2 0; ...
0 0 0 -s2 c2 0; ...
0 0 0 0 0 1];
K1 = lamd1'*k1*lamd1; % 1 1 1 2 2 2
K2 = lamd2'*k2*lamd2;% 2 2 2 3 3 3
Kg=zeros(9,9);
Kg(1:6,1:6) = K1;
Kg(4:9,4:9) = Kg(4:9,4:9)+K2;
Kgm = Kg;
% Loading condition[ r1x r1y r1th 2000 3000 -500 r3x r3y r3th]
%
F = [ 0 0 0 2000 3000 -500 0 0 0]'
F = 9×1
0 0 0 2000 3000 -500 0 0 0
% boundary conditions F [u1 v1 th1 u2 v2 th2 u3 v3 th3 ]
% u1 v1 th1 u3 v3 th3 = 0
%Modify Kg
Kg = Kg(4:6,4:6);
Fg = [2000 3000 -500]'
Fg = 3×1
2000 3000 -500
U1 = Kg\Fg; % u2 v2 th2
y1 = 5*10^-3;
x1 = 0;
B1 = [-1/L1 -y1*(12*x1-6*L1)/L1^3 -y1*(6*x1-4*L1)/L1^2 1/L1 y1*(12*x1-6*L1)/L1^3 ...
-y1*(6*x1-2*L1)/L1^2 ]
B1 = 1×6
1.0e-03 * -1.0000 0.0000 0.0200 1.0000 -0.0000 0.0100
Exx1= B1*lamd1*[ 0 0 0 U1(1) U1(2) U1(3)]'
Exx1 = 2.8571e-04
sig1 = E1 *Exx1
sig1 = 19.9998
Need help on why matrix is displaying 0 on some arrays when it is not , for example on the attached screen shot, Kg(2,2) is 0,7 but matlab displays as 0
  1 commentaire
Rik
Rik le 7 Juin 2023
Déplacé(e) : Rik le 7 Juin 2023
As you can see, there is a scaling factor at the start of the result. There you can see that you need to multiply each element by 1e5, meaning that 0.7 is rounded to 0e5 in the display.
If you want more control over how values are shown, you show read the documentation for the format function. It that is not enough, you will need to use fprintf.

Connectez-vous pour commenter.

Réponse acceptée

VBBV
VBBV le 7 Juin 2023
L1=1000;
L2=2000;
b1=10;
h1=10;
b2=20;
h2=20;
A1=b1*h1;
A2=b2*h2;
E1=70e3;
E2=205e3;
c1=cos(deg2rad(0));
s1=sin(deg2rad(0));
c2=cos(deg2rad(-90));
s2=sin(deg2rad(-90));
I1=b1*h1^3/12;
I2=b2*h2^3/12;
k1 = vpa([ A1*E1/L1 0 0 -A1*E1/L1 0 0; ...
0 12*E1*I1/L1^3 6*E1*I1/L1^2 0 -12*E1*I1/L1^3 6*E1*I1/L1^2; ...
0 6*E1*I1/L1^2 4*E1*I1/L1 0 -6*E1*I1/L1^2 2*E1*I1/L1; ...
-A1*E1/L1 0 0 A1*E1/L1 0 0; ...
0 -12*E1*I1/L1^3 -6*E1*I1/L1^2 0 (12*E1*I1)/L1^3 -6*E1*I1/L1^2; ...
0 6*E1*I1/L1^2 2*E1*I1/L1 0 -6*E1*I1/L1^2 4*E1*I1/L1],4)
k1 = 
k2 = vpa([ A2*E2/L2 0 0 -A2*E2/L2 0 0; ...
0 12*E2*I2/L2^3 6*E2*I2/L2^2 0 -12*E2*I2/L2^3 6*E2*I2/L2^2; ...
0 6*E2*I2/L2^2 4*E2*I2/L2 0 -6*E2*I2/L2^2 2*E2*I2/L2; ...
-A2*E2/L2 0 0 A2*E2/L2 0 0; ...
0 -12*E2*I2/L2^3 -6*E2*I2/L2^2 0 12*E2*I2/L2^3 -6*E2*I2/L2^2; ...
0 6*E2*I2/L2^2 2*E2*I2/L2 0 -6*E2*I2/L2^2 4*E2*I2/L2],4)
k2 = 
  1 commentaire
VBBV
VBBV le 7 Juin 2023
Use vpa with desired decimal places for those matrices

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Subclass Definition dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by