Matrix display wrong value
1 view (last 30 days)
Show older comments
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]
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]
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]'
% 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]'
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 ]
Exx1= B1*lamd1*[ 0 0 0 U1(1) U1(2) U1(3)]'
sig1 = E1 *Exx1
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 Comment
Rik
on 7 Jun 2023
Moved: Rik
on 7 Jun 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.
Accepted Answer
VBBV
on 7 Jun 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)
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)
1 Comment
More Answers (0)
See Also
Categories
Find more on Subclass Definition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!