Example

advertisement
Graph Plotting:
Graph Plotting Example 7:
From a vibration measurement on a machine, the damping ratio and undamped vibration frequency
are calculated as 0.36 and 24 Hz, respectively. Vibration magnitude is 1.2 and phase angle is -42o. Write
the MATLAB code to plot the graph of the vibration signal.
z  cos  
Given:

0
  0  0.36 * 150.796  54.3
z=0.36
  20  0 2  0 1  2
ω0=24*2*π (rad/s)
A=1.2
Φ=-42*π/180 (rad)=-0.73 rad
  150.796 * 1  0.362  140.7 rad / s
y(t)  1.2e54.3t cos(140.7t  0.73)
ω
ω0=150.796 rad/s
α
2 2 * 3.1415
T0 

 0.0416 s
0
150.796
-σ
t 
T 0.0416
T0 0.0416
 0.1155 s

 0.002 s ts  0 
20
20
z
0.36
Graph Plotting:
clc;clear
t=0:0.002:0.1155;
yt=1.2*exp(-54.3*t).*cos(140.7*t+0.73);
plot(t,yt)
xlabel(‘Time (s)');
ylabel(‘Displacement (mm)');
1
0.8
(mm)
Displacement
y
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
0
0.02
0.04
0.06
Zaman (s)
Time (s)
0.08
0.1
0.12
Roots of a polynomial:
3 t 4  5 t2  6 t  20  0
with Matlab
>> p=[3 0 5 6 -20]
>> roots(p)
Find the roots of the polynomial.
60
50
ans =
-1.5495
0.1829 + 1.8977i
0.1829 - 1.8977i
1.1838
>>ezplot('3*t^4+5*t^2+6*t-20',-2,2)
40
30
3 t4+5 t2+6 t-20
20
10
0
-10
-20
-2
-1.5495
-1.5
-1
1.1838
-0.5
0
t
0.5
1
1.5
2
Solution of nonlinear equations:
Newton-Raphson Example:
The time-dependent locations of two cars denoted by A and B
are given as
s A  t3  4t
sB  t2  3
At which time t, two cars meet?
f  t 3  t2  4 t  3
f

f
f   3t  2t  4
2
, x n1  x n  
50
40
30
Yol (m)
s A  sB
20
10
A
0
B
-10
0
0.5
1
1.5
2
Zaman (s)
2.5
3
3.5
4
Solutions of system of nonlinear equations:
Newton-Raphson Example:
clc;clear
t=solve('t^3-t^2-4*t+3=0');
vpa(t,6)
Using roots command in MATLAB
a=[ 1 -1 -4 3]; roots(a)
ANSWER
t=0.713 s
t=2.198 s
50
40
30
Yol (m)
clc, clear
x=1;xe=0.001*x;
niter=20;
%---------------------------------------------for n=1:niter
%---------------------------------------------f=x^3-x^2-4*x+3;
df=3*x^2-2*x-4;
%---------------------------------------------x1=x
x=x1-f/df
if abs(x-x1)<xe
kerr=0;break
end
end
kerr,x
Alternative Solutions with MATLAB
20
10
A
0
B
-10
0
0.5
1
1.5
2
Zaman (s)
2.5
3
3.5
4
Solution of system of nonlinear equations:
sin(2x)  y 3  3x  1
x2  y  1  y2
How do you find x and y values, which satisfy the
equations?
f  f
f1  sin(2x)  y 3  3x  1
f2  x 2  y 2  y  1
f1
f
 2 cos(2x)  3 , 1  3y 2
x
y
f2
f
 2x , 2  2y  1
x
y
with Matlab:
 f1
 x
 f
 2
 x
f1 
y  1   f1 

f2  2   f2 
y 
clc, clear
x=[1 1]; xe=[0.01 0.01];
niter1= 5; niter2=50;
fe=transpose(abs(fe));kerr=1;
for n=1:niter2
x
%-----Error equations-----------------------a(1,1)=2*cos(2*x(1))-3;a(1,2)=3*x(2)^2;
a(2,1)=2*x(1);a(2,2)=2*x(2)+1;
b(1)=-(sin(2*x(1))+x(2)^3-3*x(1)+1);
b(2)=-(x(1)^2+x(2)^2+x(2)-1);
%------------------------------------------------------bb=transpose(b);eps=inv(a)*bb;x=x+transpose(eps);
if n>niter1
if abs(eps)<xe
kerr=0; break
else
display ('Roots are not found')
end
end
end
>>[x,y]=solve('sin(2*x)+y^3=3*x-1','x^2+y=1-y^2')
x=0.6786, y=0.3885
x=0.6786
y=0.3885
Solution of system of nonlinear equations:
3(a2  1)  2 b2  11
How do you calculate a and b, which satisfy given equations by computer?
2 a  (b  1)  16
3
2
f1  3(a2  1)  2 b2  11
f2  2 a3  (b  1)2  16
f1
f1
 3(2a)  6a,
 4b
a
b
f2
f
 6a2 , 2  2(b  1)
a
b
f   f
x n 1  x n  
 f1
 a
 f
 2
 a
f1 
b  1    f1 
f2  2   f2 

b 
clc, clear
x=[1 1]; xe=[0.01 0.01];
niter1= 5; niter2=50;
fe=transpose(abs(fe));kerr=1;
for n=1:niter2
x
%-----Error equations-----------------------a(1,1)=6*x(1);a(1,2)=4*x(2);
a(2,1)=6*x(1)^2;a(2,2)=2*(x(2)-1);
b(1)=-(3*(x(1)^2-1)+2*x(2)^2-11);
b(2)=-(2*x(1)^3+(x(2)-1)^2-16);
%------------------------------------------------------bb=transpose(b);eps=inv(a)*bb;x=x+transpose(eps);
if n>niter1
if abs(eps)<xe
kerr=0; break
else
display ('Roots are not found')
end
With Matlab
Matlab gives all possible solutions
end
end
>>[a,b]=solve('3*(a^2-1)+2*b^2=11','2*a^3+(b-1)^2=16')
a  1.611
b  1.761
Lagrange Interpolation:
Example:
The temperature (T) of a medical cement increases continuously as the solidification time
(t) increases. The change in the cement temperature was measured at specific instants and
the measured temperature values are given in the table. Find the cement temperature at
t=36 (sec).
T(t) 
T(t) 
(t  15)(t  55)
(t  5)(t  55)
(t  5)(t  15)
* 30 
* 43 
* 68
(5  15)(5  55)
(15  5)(15  55)
(55  5)(55  15)
(36  15)(36  55)
(36  5)(36  55)
(36  5)(36  15)
* 30 
* 43 
* 68  61.51o C
(5  15)(5  55)
(15  5)(15  55)
(55  5)(55  15)
Lagrange Interpolation:
Example:
The buckling tests were performed in order to find the critical buckling loads of a clamped-pinned steel
beams having different thicknesses. The critical buckling loads obtained from the experiments are given
in the table. Find the critical buckling load Pcr (N) of a steel beam with 0.8 mm thickness.
Pcr
0.8 mm
Pcr (t) 
Thickness (t)
(mm)
Buckling
Load Pcr (N)
0.5
30
0.6
35
0.65
37
0.73
46
0.9
58
(t  0.6)(t  0.65)(t  0.73)(t  0.9)
(t  0.5)(t  0.65)(t  0.73)(t  0.9)
(t  0.5)(t  0.6)(t  0.73)(t  0.9)
* 30 
* 35 
* 37
(0.5  0.6)(0.5  0.65)(0.5  0.73)(0.5  0.9)
(0.6  0.5)(0.6  0.65)(0.6  0.73)(0.6  0.9)
(0.65  0.5)(0.65  0.6)(0.65  0.73)(0.65  0.9)
(t  0.5)(t  0.6)(t  0.65)(t  0.9)
(t  0.5)(t  0.6)(t  0.65)(t  0.73)
* 46 
* 58
(0.73  0.5)(0.73  0.6)(0.73  0.65)(0.73  0.9)
(0.9  0.5)(0.9  0.6)(0.9  0.65)(0.9  0.73)
Pcr (0.8)  9.134  56.538  103.600  101.810  7.164  52.779 N
Lagrange Interpolation:
Pcr
0.8 mm
Thickness (t)
(mm)
Buckling
Load Pcr (N)
0.5
30
0.6
35
0.65
37
0.73
46
0.9
58
1. Lagrange Interpolation with Matlab
clc;clear
t=[0.5 0.6 0.65 0.73 0.9];
P=[30 35 37 46 58];
interp1(t,P,0.8,'spline')
2. Lagrange Interpolation with Matlab
clc;clear
v=load ('c:\saha\data.txt')
interp1(v(:,1),v(:,2),8,'spline')
data.txt
0.5,30
0.6,35
0.65,37
0.73,46
0.9,58
Lagrange Interpolation:
The pressure values of a fluid flowing in a pipe are given in the table for different locations . Find
the pressure value for 5 m.
a) Lagrange interpolation (manually)
a) with computer
Location (m)
3
8
10
Pressure (atm)
7
6.2
6
a) with Lagrange interpolation
p(x) 
(x  8)(x  10)
(x  3)(x  10)
(x  3)(x  8)
*7 
* 6.2 
*6
(3  8)(3  10)
(8  3)(8  10)
(10  3)(10  8)
p(5) 
(5  8)(5  10)
(5  3)(5  10)
(5  3)(5  8)
*7 
* 6.2 
*6
(3  8)(3  10)
(8  3)(8  10)
(10  3)(10  8)
p( x )  6.6286 (atm )
b) For computer solution, the MATLAB code is given as
clc;clear
x=[3 8 10];
P=[7 6.2 6];
interp1(x,P,5,'spline')
Lagrange Interpolation:
The x and y coordinates of three points on the screen, which were clicked by a CAD user are given in
the figure. Find the y value of the curve obtained from these points at x=50.
x
y
25
-10
40
20
70
5
b) How do you find the answer manually?
y(x) 
a)How do you find the answer with
computer?
clc;clear
x=[25 40 70];
y=[-10 20 5];
interp1(x,y,50,'spline')
Result: 26.111
(x  40)(x  70)
(x  25)(x  70)
(x  25)(x  40)
(10) 
(20) 
(5)
(25  40)(25  70)
(40  25)(40  70)
(70  25)(70  40)
y(50)  2.96296  22.222  0.9259  26.1108
Simpson’s Rule:
Example: Calculate the volume of the 3 meter long beam whose cross section is given in the
figure.
1.2
x 1
k
x
y(x)
x 1
y
x2  4
Area 

0
x 4
2
dx
n6
x 
Area 
1.2  0
 0.2
6
0
0
0.5
1
0.2
0.597
2
0.4
0.6864
3
0.6
0.7663
4
0.8
0.8356
5
1.0
0.8944
6
1.2
0.9432
0.2
0.5  4* 0.597  2* 0.6864  4* 0.7663  2* 0.8356  4* 0.8944  0.9432
3
Area  0.9012 m 2
Volume  Area  Length  0.9012  3  2.7036 m3
Solution with Matlab:
>>syms x; area=int((x+1)/(sqrt(x^2+4)),0,1.2);vpa(area,5)
Area=0.9012
Simpson’s Rule:
Calculate the integral with;
1

a) Trapezoidal rule
b) Simpson’s rule
 cos() d  ?
0.5
c) Using MATLAB, take n=4.
a) Trapezoidal rule: Divide into for equal sections between 0.5 and 1.
f 
f
ITR  h  0  f1  f2  f3  4 
2
2
k
θ
f
0
0.5
0.6205
1
0.625
0.6411
2
0.75
0.6337
3
0.875
0.5996
4
1
0.5403
0.5403 
 0.6205
ITR  0.125 
 0.6411  0.6337  0.5996 
2 
 2
ITR  0.3072
h
1  0.5
 0.125
4
Simpson’s Rule:
b) Simpson’s rule:
IS 
h
f0  4 f1  2f2  4 f3  f4 
3
IS 
0.125
0.6205  4 * 0.6411  2 * 0.6337  4 * 0.5996  0.5403
3
IS  0.3085
using Matlab
>>syms tet
>>I=int(sqrt(tet)*cos(tet),0.5,1);vpa(I,5)
I=0.30796
Lagrange Interpolation + Simpson’s Rule:
Example:
For a steel plate weighing 10 N and has a thickness 3 mm,
the the coordinates of some points shown in the figure
were measured (in cm) by a Coordinate Measuring
Machine (CMM). How do you calculate the intensity of
the steel by fitting a curve, which passes through these
points. ?

m (kg)
V (cm3 )
a) Manual calculation:
The volume of the part is calculated by using its surface area and 0.3 cm thickness value. The simpson’s rule
is used for area calculation. The x axis must be divided in equal segments in this method. Since the points
are not equally spaced on the x axis, the necessary y values should be calculated at suitable x values.
x
y
0
5
2.5
7.8
3.7
9.3
4
10
If we divide the interval 0-4 into four equal sections using the increment ∆x=1 , we can
obtain the y values for x=1, x=2 and x=3.
y
(x  2.5)(x  3.7)(x  4)
(x  0)(x  3.7)(x  4)
*5
* 7.8
(0  2.5)(0  3.7)(0  4)
(2.5  0)(2.5  3.7)(2.5  4)
(x  0)(x  2.5)(x  4)
(x  0)(x  2.5)(x  3.7)

* 9.3 
* 10
(3.7  0)(3.7  2.5)(3.7  4)
(4  0)(4  2.5)(4  3.7)
Lagrange Interpolation + Simpson’s Rule:
(1  2.5)(1  3.7)(1  4)
(1  0)(1  3.7)(1  4)
*5
* 7.8
(0  2.5)(0  3.7)(0  4)
(2.5  0)(2.5  3.7)(2.5  4)
(1  0)(1  2.5)(1  4)
(1  0)(1  2.5)(1  3.7)

* 9.3 
* 10
(3.7  0)(3.7  2.5)(3.7  4)
(4  0)(4  2.5)(4  3.7)
y(1) 
y(1)  6.763
(2  2.5)(2  3.7)(2  4)
(2  0)(2  3.7)(2  4)
*5
* 7.8
(0  2.5)(0  3.7)(0  4)
(2.5  0)(2.5  3.7)(2.5  4)
(2  0)(2  2.5)(2  4)
(2  0)(2  2.5)(2  3.7)

* 9.3 
* 10
(3.7  0)(3.7  2.5)(3.7  4)
(4  0)(4  2.5)(4  3.7)
y(2)  7.4969
(3  2.5)(3  3.7)(3  4)
(3  0)(3  3.7)(3  4)
*5
* 7.8
(0  2.5)(0  3.7)(0  4)
(2.5  0)(2.5  3.7)(2.5  4)
(3  0)(3  2.5)(3  4)
(3  0)(3  2.5)(3  3.7)

* 9.3 
* 10
(3.7  0)(3.7  2.5)(3.7  4)
(4  0)(4  2.5)(4  3.7)
y(3)  8.2323
y(2) 
y(3) 
x
y
0
5
1
6.763
2
7.4969
3
8.2323
4
10
Lagrange Interpolation + Simpson’s Rule:
h
40
A  I  f0  4 f1  2f2  4 f3  f4 
h
1
4
3
1
A  I  5  4 * 6.763  2 * 7.4969  4 * 8.2323  10
3
A  29.9917 cm2 V  A * t  29.9917 * 0.2  5.9983 cm3
m
10
 1.0193 kg
9.81

m 1.0193
kg

 0.16994 3
V 5.9983
cm
b) With computer:
For calculation with computer, MATLAB code is arranged to find the y values for x=1, x=2 and x=3 and
the code Lagr.I is run.
clc;clear
x=[0 2.5 3.7 4];
y=[5 7.8 9.3 10];
interp1(x,y,1,'spline')
interp1(x,y,2,'spline')
interp1(x,y,3,'spline')
The area of the plate can be calculated
by using Simpson’s rule. Then, the
density of the steel can be calculated as
mentioned before.
Simpson’s Rule:
Example: Calculate the integral of the given function.
M()  2.5e
1.4 

cos4.2  1.4 
 M()d  ?
0
4.2i
0  1.42  4.22  4.427
-1.4
T0 
z
2
2

 1.419
0 4.427
4.49
1.4
 0.316
4.427
s 
T0 1.419

 4.49
z 0.316
 M()d  ?
0
n  12
4.49  0
 
 0.3742
12
Simpson’s Rule:
k
θ
M(θ)
0
0
0.4249
1
0.3742
-1.4592
2
0.7484
-0.1476
>>clc;clear;
3
1.1226
0.5119
>> syms teta
4
1.4968
0.0512
5
1.8710
-0.1796
6
2.2452
-0.0178
7
2.6194
0.0630
8
2.9936
0.0062
9
3.3678
-0.0221
10
3.7420
-0.0021
11
4.1162
0.0078
12
4.49
0.000744
Solution with Matlab:
>>f=2.5*exp(-1.4*teta)*cos(4.2*teta+1.4)
>>y=int(f,0,4.49)
>>vpa(y,5)
I=-0.4966
h
I  f0  4 f1  2f2  4 f3  2f4  4 f5  2f6  4 f7  2f8  4 f9  2f10  4 f11  f12 
3
I

0.3742 0.4249  4 * 1.4592  2 * 0.1476  4 * 0.5119  2 * 0.0512  4 * 0.1796 
3 2 * 0.0178  4 * 0.0630  2 * 0.0062  4 * 0.0221  2 * 0.0021  4 * 0.0078  0.000744 
I  0.5123
Simpson’s Rule:
Example:
M()  2.5e1.4  cos4.2  1.4 

2
M
(

)
d  ?

0
n  12
4.49  0
 
 0.3742
12
k
θ
M2(θ)
0
0
0.1806
1
0.3742
2.1293
2
0.7484
0.0218
3
1.1226
0.2621
4
1.4968
0.0026
5
1.8710
0.0323
6
2.2452
0.000316
7
2.6194
0.0040
8
2.9936
3.81x10-5
9
3.3678
4.88x10-4
10
3.7420
4.598x10-6
11
4.1162
6.013x10-5
12
4.49
5.541x10-7
0.1806  4 * 2.1293  2 * 0.0218  4 * 0.2621  2 * 0.0026  4 * 0.0323  
0.3742 
5
4
6 
I
2
*
0
.
000316

4
*
0
.
0040

2
*
3
.
81
x
10

4
*
4
.
88
x
10

2
*
4
.
59
x
10

3 
 4 * 6.013x10 5  5.541x10 7



I  1.2402
Simpson’s Rule:
Solution with Matlab:

2
M
(

)
d  ?

0
n  12
4.49  0
 
 0.3742
12
>>clc;clear;
>> syms teta
>>f=(2.5*exp(-1.4*teta)*cos(4.2*teta+1.4))^2
>>y=int(f,0,4.49)
>>vpa(y,5)
I=0.898
We must increase the number of sections!
Simpson’s Rule:
A stationary car starts to move with the acceleration given below
1.4
1.2
t2  1
1
Find the speed of the car at the end of 10 seconds
a)
b)
Manually
With computer
a
a)
f 
v
t
İvme m/s2
a
1  sin(t3 )
10
dv
  dv   a dt  v t 10   a dt
dt
0
0
0
1  sin( t 3 )
t 1
2
,n  4
b  a 10  0
h  t 

 2.5
n
4
0.8
a
1  sin(t3 )
t2  1
0.6
0.4
0.2
0
0
2
4
6
8
10
12
Zaman (s)
k
t
f
0
0
1
1
2.5
0.40216
h
f0  4f1  2f2  4f3  f4 
3
2.5
1  4 * 0.40216  2 * 0.0753  4 * 0.2358  0.18178  3.236
v I
2
5
0.0753
b) With computer
3
7.5
0.2358
4
10
0.18178
v I
3
using Matlab
>>syms t
>>I=int((1+sin(t)^3)/sqrt(t^2+1),0,10);vpa(I,5)
m/s
Simpson’s Rule:
Find the intersection area of the curves y=x2+2 ile y=3x .
3x  x  2
2
x  3x  2  0
2
 3x  x
2
y  x2  2
A I
x
x1  1
x2  2
x 1 ,2 
 b  b2  4ac
2a
>> roots([1 -3 2])
 2dx  ?
1
y  3x
k
2
Roots
f
0
1
0
1
1.25
0.1875
2
1.5
0.25
3
1.75
0.1875
4
2
0
A I
h
f0  4 f1  2f2  4f3  f4 
3
0.25
0  4 * 0.1875  2 * 0.25  4 * 0.1875  0  0.16667 br 2
3
using Matlab
>>syms x
>>I=int(3*x-x^2-2,1,2);vpa(I,5)
System of linear equations:
w  3z  9  u
3w  12  6z
w z u5  0
 u  w  3z  9
3w  6z  12
uw z  5
With Matlab
clc;clear
a=[-1 1 -3;0 3 -6;1 1 1];
b=[9;12;5];
c=inv(a)*b
How do you calculate u,w and z with computer?
 1 1  3  u   9 
 0 3  6 w  12

   
  
 1 1 1  
z   5 
u  8
w  10
z3
1
 u    1 1  3  9 
  
  
w    0 3  6 12
z   1 1 1   5 
  
  
System of linear equations:
As a result of the equilibrium conditions, the
equations given below are obtained for a
truss system. How do you calculate the
member forces FJD, FFD, FCD and FFC if
FCK=6.157 kN and FCB=-3.888 kN are known?
 FJD  0.707FFD  0.894 FCD  0.466  0
 0.707FFD  FCD  0.447FCB  1.738  0
3FJD  1.065FCK  2.365FFC  0
0.894 FCD  FFC  0.707FCK  0
FCK  6.157 , FCB  3.888
0  FJD   0.466
 1  0.707  0.894
 0  0.707
1
0  FFD   0 

   

3
0
0
2.365 FCD   6.557

  
0
0
0
.
894
1

 FFC   4.353 
A
F
b
1
F  A *b
F  inv (A) * b
System of linear equations:
0  FJD   0.466
 1  0.707  0.894
 0  0.707
1
0  FFD   0 

   

3
0
0
2.365 FCD   6.557


0
0.894
1  FFC   4.353 
0
A
F
b
with Matlab
clc;clear
A=[-1 -0.707 -0.894 0;0 -0.707 -1 0;3 0 0 2.365;0 0 0.894 1];
b=[-0.466;0;-6.557;4.353];
F=inv(A)*b
FJD= 1.5429 kN
FFD= -14.3701 kN
FCD= 10.1596 kN
FFC= -4.7297 kN
Download