Академический Документы
Профессиональный Документы
Культура Документы
12
10
y
6
4
a 3
n 3 2
b 5 0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
p 2 x
c 5
q 0
25
20
15
dy/dx = a n x(n-1) + 10
y
b p x(p-1) +
c q x(q-1) + …
5
-5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
x
Numerical Derivatives
• slope between points
Derivative of Sine and Cosine
1.5
1
p p
0.5
Sin(x)
0
Cos(x)
0 1 2 3 4 5 6 7
-0.5
-1
-1.5
• sin(0) = 0
• period of both sine and cosine is 2p
• d(sin(x))/dx = cos(x)
• d(cos(x))/dx = -sin(x)
Partial Derivatives
3
2.5
2 2.5-3
1.5 2-2.5
1.5-2
1
1-1.5
0.5 0.5-1
0-0.5
0
-0.5-0
-0.5 -1--0.5
S19
-1 -1.5--1
S13
-1.5 Y
S7
1
10
13
S1
16
19
• Treat ys as constants
• If these constants stand alone, they drop
out of the result
• If they are in multiplicative terms involving
x, they are retained as constants
Partial Derivatives
3
2.5
2 2.5-3
1.5 2-2.5
1.5-2
1
1-1.5
0.5 0.5-1
0-0.5
0
-0.5-0
-0.5 -1--0.5
S19
-1 -1.5--1
S13
-1.5 Y
S7
1
10
13
S1
16
19
• Example:
• C(x,y) = x4 + y3 + xy
• C/ x|y=y0 = 4x3 + y0
WHY?
Gradients
• del h (or grad h)
h h
h i j
x y
• Flow (Darcy’s Law):
q Kh
Gradients
• del C (or grad C)
C C
C i j
x y
• Diffusion (Fick’s 1st Law):
J DC
Basic MATLAB/Python
Matlab/Python
• Programming environment
• Post-processer
• Graphics
• Analytical solution comparisons
a=
1 2 3 4
>> a'
ans =
1
2
3
4
Autofilling and addressing Vectors
> a=[1:0.2:3]'
a=
1.0000
1.2000
1.4000
1.6000
1.8000
2.0000
2.2000
2.4000
2.6000
2.8000
3.0000
>> a(2:3)
ans =
1.2000
1.4000
xy Plots
>> x=[1 3 6 8 10];
>> y=[0 2 1 3 1];
>> plot(x,y)
Matrices
>> b=[1 2 3 4;5 6 7 8]
b=
1 2 3 4
5 6 7 8
>> b'
ans =
1 5
2 6
3 7
4 8
Matrices
>> b=2.2*ones(4,4)
b=
a=
1 2 3 4 5 6 7 8 9
>> bsquare=reshape(a,3,3)
bsquare =
1 4 7
2 5 8
3 6 9
>>
Load
• a = load(‘filename’);
(semicolon suppresses
echo)
a=np.loadtxt('book3.csv',delimiter=',')
If
• if(1)
…
else
…
end
For
• for i = 1:10
• …
• end
BMP Output
bsq=rand(100,100);
%bmp1 output
e(:,:,1)=1-bsq; %r
e(:,:,2)=1-bsq; %g
e(:,:,3)=ones(100,100); %b
imwrite(e, 'junk.bmp','bmp');
image(imread('junk.bmp'))
axis('equal')
Quiver (vector plots)
>> scale=10;
>> d=rand(100,4);
>> quiver(d(:,1),d(:,2),d(:,3),d(:,4),scale)
Contours
• h=[…];
• Contour(h)
• Or
Contour(x,y,h)
Contours w/labels
• C=[…];
• [c,d]=contour(C);
• clabel(c,d), colorbar
Numerical Partial Derivatives
• slope between points
• MATLAB
– h=[]; (order assumed to be low y on top to
high y on bottom!)
– [dhdx,dhdy]=gradient(h,spacing)
– contour(x,y,h)
– hold
– quiver(x,y,-dhdx,-dhdy)
Gradient Function and Streamlines
• [dhdx,dhdy]=gradient(h);
• [Stream]=
stream2(X,Y,U,V,STARTX,STARTY);
• [Stream]= stream2(-dhdx,-
dhdy,[51:100],50*ones(50,1));
• streamline(Stream)
• (This is for streamlines starting at y = 50
from x = 51 to 100 along the x axis.
Different geometries will require different
starting points.)
Stagnation Points
0
-0.5-0
-1--0.5
-0.5
-1.5--1
-2--1.5
-1
S1 -2.5--2
-1.5 S5 -3--2.5
S9
-2
S13
-2.5
S17
-3
7
1
37
34
31
28
25
22
19
16
13
10
Integral Calculus
( n 1)
x
n
ax x a C
n 1
2
x
ax x a
2
C
3
x
2
ax x a C
3
Integral Calculus: Special Case
( n 1)
x
n
ax x a C
n 1
1
ax x ?????
Integral Calculus: Special Case
( n 1)
x
n
ax x a C
n 1
1
ax x a ln x C