check - me.ua.edu

HW 3
Problem 1
First write the system of equations in matrix form:
 m1 
k
0   x1 
 −2k
 
 
 k

−2k k   x2  =
− g m2 

m 
 0
−k   x3 
k
 3
Now put into Matlab
% script file for HW 3-1
g=9.81;
% m/s^2
m1=2;
% kg
m2=3;
% kg
m3=2.5; % kg
k=10;
% N/m
A = zeros(3,3);
% make some space for the matrix
A(1,1) =-2*k;
A(1,2)=k;
A(2,1)=k;
A(2,2)=-2*k;
A(2,3)=k;
A(3,2)=k;
A(3,3)=-k;
% A = [ -2*k k 0; k -2*k k; 0 k -k ];
disp 'the A matrix:'
disp(A)
% define the RHS
b = -g*[ m1 m2 m3 ]';
disp 'The RHS:'
disp(b)
% solve the system of equations
x = A \ b;
disp 'the solution is:'
disp(x)
Output
>> hw3_1
the A matrix:
-20
10
10
-20
0
10
0
10
-10
The RHS:
-19.6200
-29.4300
-24.5250
the solution is:
7.3575
12.7530
15.2055
Problem 3
First write in matrix form
cos60
 − cos30 0
 − sin 30 0 − sin60

 cos30 1
0

0
 sin 30 0

0 −1 − cos60

0 0
sin60

0
0
1
0
0
0
0
0
0
1
0
0
0   F1  
0
F  

0   2  +1000 
0   F3  
0

  = 
0  H 2  
0
0   V2  
0

  
1   V3  
0
Then put into Matlab
% script file for HW 3-3
cos30 = cos(30*pi/180); % note cos() accepts radians
cos60 = cos(60*pi/180);
sin30 = sin(30*pi/180);
sin60 = sin(60*pi/180);
% put variables in the order F1, F2, F3, H2, V2, V3
% build the coefficient matrix
A = zeros(6,6);
A = [ -cos30
0
cos60 0
0
0;
... % ... is continuation
-sin30
0
-sin60 0
0
0;
...
cos30
1
0 1
0
0;
...
sin30
0
0 0
1
0;
...
0 -1
-cos60 0
0
0;
...
0
0
sin60 0
0
1; ];
disp 'The coefficient matrix:'
disp(A)
% build the RHS
b = [ 0 1000 0
0
0
0]';
disp 'The load vector (RHS):'
disp(b)
x = A \ b;
disp 'The solution:'
disp(x)
fprintf(' F1 = %8.2f \n',x(1))
fprintf(' F2 = %8.2f \n',x(2))
fprintf(' F3 = %8.2f \n',x(3))
fprintf(' H2 = %8.2f \n',x(4))
fprintf(' V2 = %8.2f \n',x(5))
fprintf(' V3 = %8.2f \n',x(6))
Output on next page
Output
>> hw3_3
The coefficient matrix:
-0.8660
0 0.5000
0
0
0
-0.5000
0 -0.8660
0
0
0
0.8660 1.0000
0 1.0000
0
0
0.5000
0
0
0 1.0000
0
0 -1.0000 -0.5000
0
0
0
0
0 0.8660
0
0 1.0000
The load vector (RHS):
0
1000
0
0
0
0
The solution:
-500.0000
433.0127
-866.0254
0
250.0000
750.0000
F1 = -500.00
F2 = 433.01
F3 = -866.03
H2 = 0.00
V2 = 250.00
V3 = 750.00
>>