-
Notifications
You must be signed in to change notification settings - Fork 2
/
MAIN.py
63 lines (50 loc) · 1.6 KB
/
MAIN.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 31 18:17:37 2018
@author: mathemacode
Plots both the explicit and Crank-Nicolson
Methods for Parabolic problems. 3D exact
solution plot is also included.
Use a=1 for plots on same graphic, a=2 for dual plots
lined up side-by-side for analysis. Also, I made a function
to compare to the exact solution for the heat equation.
It will plot secondary to the methods.
"""
import matplotlib.pyplot as plt
from Explicit import explicit
from Crank import crank
from Heat3Dplot import exact
n = 10
def main():
methods_plot(1) # a = 1 for both on same plot, 2 for side-by-side
exact()
def methods_plot(a):
if a == 1: # Single plot, two lines
plt.plot(explicit(), 'b-o')
plt.plot(crank(), 'r--')
plt.title("Heat Equation Parabolic Methods Results")
plt.xlim(0, n)
plt.ylim(0,0.35)
plt.xlabel("n")
plt.ylabel("Value")
plt.legend(['Explicit', 'Crank-Nicolson'], loc='upper left')
plt.show()
elif a == 2: # Double plot, individual lines
''' Plot Results of Explicit '''
plt.subplot(121)
plt.plot(explicit(), 'b-o')
plt.xlim(0, n)
plt.ylim(0, 0.35)
plt.title("Explicit Method Result")
plt.xlabel("n")
plt.ylabel("Value")
''' Plot Results of Crank-Nicolson Method '''
plt.subplot(122)
plt.plot(crank(), 'r-o')
plt.xlim(0, n)
plt.ylim(0,0.35)
plt.xlabel("n")
plt.title("Crank-Nicolson Method Result")
plt.show()
main()