Document 11550298

advertisement
ARRAYS
A set of numbers in a specific order or pattern
1 x n dimensional matrix
In Matlab, you must always define arrays:
๏‚งTo input y=f(x) you must
๏‚งDefine x
๏‚งDefine y as a function of x using the hundreds
of functions available in Matlab
ARRAYS
Define y=sin(x) on the interval [0, 2π]
Is it continuous?
How accurate should you have it?
How ‘big’ is the array(s)?
What is the 10th value?
FILES
Find zeros of a polynomial
ex
๐‘ฅ
ln(x)
log ๐‘ ๐‘ฅ
cos x (radians)
cos x (degrees)
๐‘๐‘œ๐‘  −1 ๐‘ฅ (radians)
๐‘๐‘œ๐‘  −1 ๐‘ฅ (degrees)
6x3 + 5x2-20x+40=0
e2
15
ln(20)
log 9
π
cos ( )
3
cos (48o)
๐‘๐‘œ๐‘  −1 −0.3
๐‘๐‘œ๐‘  −1 (−0.3)
PLOT
Must define independent
and dependent variables
Plot(independent,
dependent,…, ‘+’)
title (‘ ‘)
xlabel (‘ ‘)
ylabel(‘ ‘)
gtext(‘ ‘)
[x,y] ginput( n )
grid
Plot the function
w=e-0.3x+3x on [0,5]
y= 4 3๐‘ฅ − 1
Graph displays Force
x is in meters
w,y is in newtons
Label line ‘w’ and ‘y’
Approximate their
intersection
Add a grid
MATRICES
Combination of
arrays
n x m dimensions
Constructed using a
semi colon
between rows
Ax=b
x=?
Solve using Matlab
2x+2y+3z=10
4x-y+z=-5
5x-2y+6z=1
FOURIER SERIES
Used:
Originally to solve heat
equation
Differential EquationsEigensolutions
Electrical Engineering
Vibrational Analysis
Signal Processing, etc.
Breaks down repeating,
step, or periodic
functions into a sum of
sine and cosine
FOURIER SERIES
Given f(x) where xั”(-π,π)
Then f(x) can be approximated a.e. by:
f(x) ≈
๐’‚๐ŸŽ
๐Ÿ
+
∞
๐’=๐Ÿ[๐’‚๐’ ๐’„๐’๐’”
Where
๐Ÿ
๐’‚๐’ =
π
๐Ÿ
๐’ƒ๐’ =
π
๐’๐’™ + ๐’ƒ๐’ ๐’”๐’Š๐’(๐’๐’™)]
π
๐’‡ ๐’™ ๐’„๐’๐’” ๐’๐’™ ๐’…๐’™ ๐’ ≥ ๐ŸŽ
−๐Ÿ, −π < ๐’™ < ๐ŸŽ
If ๐’‡ ๐’™ =
๐Ÿ, ๐ŸŽ < ๐’™ < π
Find:
a0, a1, a2, a3
b1, b2, b3, b4
−π
π
๐’‡ ๐’™ ๐’”๐’Š๐’ ๐’๐’™ ๐’…๐’™ ๐’ ≥ ๐Ÿ
−π
to approximate f(x) in a
Fourier Series
P1.23 FT APPROXIMATION
Consider the Step Function
๏ƒฌ๏€ญ 1
f ๏€จx ๏€ฉ ๏€ฝ ๏ƒญ
๏ƒฎ 1
The Fourier
Transform
for the
above Function
for
for
Taking the First FOUR Terms of the Infinite Sum
f
f
๏€จx ๏€ฉ ๏‚ป
๏€จx ๏€ฉ ๏‚ป
4
๏ฐ
k ๏€ฝ๏‚ฅ
๏ƒฅ
k ๏€ฝ1
๏€ญ๏ฐ ๏€ผ x ๏€ผ 0
0๏€ผ x ๏€ผ๏ฐ
sin ๏€จ๏›2k ๏€ญ 1๏x ๏€ฉ
2k ๏€ญ 1
4 ๏ƒฉ sin ๏€จ x ๏€ฉ
sin ๏€จ3 x ๏€ฉ
sin ๏€จ5 x ๏€ฉ
sin ๏€จ7 x ๏€ฉ
๏ƒน
๏€ซ
๏€ซ
๏€ซ
๏€ซ
๏Œ
๏ƒบ
๏ฐ ๏ƒช
1
3
5
7
๏ƒซ
๏ƒป
GRAPHING THE FUNCTION
How can we plot f(x)?
๏ƒฌ๏€ญ 1
f ๏€จx ๏€ฉ ๏€ฝ ๏ƒญ
๏ƒฎ 1
for
for
๏€ญ๏ฐ ๏€ผ x ๏€ผ 0
0๏€ผ x ๏€ผ๏ฐ
Solution 1
x1=[-pi,0]
f1= [-1,-1]
OR Solution 2
x2=[0,pi]
f2=[1,1]
f0=[-1,-1,1,1]
x0=[-pi,-1e-6,1e-6,pi]
PLOT THE FUNCTION
Solution 1
plot(x1,f1,x2,f2);grid;
title(‘f(x)’);xlablel(‘x’)
Solution 2
plot(x,f);grid;title(‘f(x
)’);xlabel(‘x’);
GRAPHING THE APPROXIMATION
How can we graph?
f
๏€จx ๏€ฉ ๏‚ป
4 ๏ƒฉ sin ๏€จ x ๏€ฉ
sin ๏€จ3 x ๏€ฉ
sin ๏€จ5 x ๏€ฉ
sin ๏€จ7 x ๏€ฉ
๏ƒน
๏€ซ
๏€ซ
๏€ซ
๏€ซ
๏Œ
๏ƒบ
๏ฐ ๏ƒช
1
3
5
7
๏ƒซ
๏ƒป
Solution 1
x=-pi:0.01:pi;
f=4/pi(sin(x)/1+sin(
3*x)/3+sin(5*x)/
5+sin(7*x)/7);
Solution 2:
ftot=zeros(1,length(x)
for k=1:2:7;
fc=sin(k*x)/k;
ftot=fc+ftot;
end
CAN WE GET A BETTER APPROXIMATION?
Let’s make a program
for solution 2 and
plot all on same axis!
function fourier(n)
x=-pi:0.01:pi;
f1=[-1,-1,1,1];
x1=[-pi,-1e-6,1e-6,pi];
ftot=zeros(1,length(x));
for k=1:2:n;
fc=sin(k*x)/k;
ftot=ftot+fc;
end
f=4/pi*ftot;
plot(x,f,x1,f1)
THE HEAT EQUATION
Q=m c Δt
Ut=α Uxx (Diff. Eq)
U(x,t)=
∞
๐’=๐Ÿ ๐‘ซ๐’
๐’π๐’™
๐’”๐’Š๐’( )
๐‘ณ
∗๐’†
Where
And f(x)=initial temperature
distribution at t=0
๐’๐Ÿ π๐Ÿ α๐’•
−
๐‘ณ๐Ÿ
Download