- File
- File history
- File usage
- Metadata
Size of this PNG preview of this SVG file: 720 × 540 pixels. Other resolutions: 320 × 240 pixels | 640 × 480 pixels | 800 × 600 pixels | 1,024 × 768 pixels | 1,280 × 960 pixels | 2,560 × 1,920 pixels.
Original file (SVG file, nominally 720 × 540 pixels, file size: 369 KB)
Summary
DescriptionHeatEquationCNApproximate.svg | English: Crank-Nicolson method to approximate the heat equation , where . |
Date | |
Source | Own work |
Author | Shiyu Ji |
Python/Matplotlib Code
# Crank-Nicolson method to solve the heat equation.from mpl_toolkits.mplot3d import axes3dimport matplotlib.pyplot as plimport numpy as npimport matplotlib.patches as mpatchest0 = 0.0t_final = 1.0n_grid = 20dt = t_final / n_griddx = 1.0 / n_gridT = np.arange(t0, t_final+dt, dt)X = np.arange(0, 1+dx, dx)ax = pl.figure().add_subplot(111, projection='3d')ax.set_xlabel('t')ax.set_ylabel('x')ax.set_zlabel('U')ax.set_xlim([t0,t_final])ax.set_ylim([0, 1])Umax= .15ax.set_zlim([0, Umax])# Exact solutiondef exact(t, x): return np.exp(-t)*np.sin(np.pi*x)/(np.pi*np.pi) for t in T: for x in X: if t>t0: ax.plot([t-dt, t],[x, x],[exact(t-dt, x), exact(t, x)], 'b-', linewidth=0.5) if x>0.0: ax.plot([t, t],[x-dx, x],[exact(t, x-dx), exact(t,x)], 'b-', linewidth=0.5)# Crank-Nicolson methodr = dx/(dt*dt)/(np.pi*np.pi)U = [[0.0 for _ in X] for _ in T]A = [[0.0 for _ in X] for _ in X]A_prime = [[0.0 for _ in X] for _ in X]b = [0.0 for _ in X]for i in range(len(X)): if i in [0, len(X)-1]: A[i][i] = 1.0 A_prime[i][i] = 1.0 else: A[i][i] = 2+2*r A[i][i-1] = -r A[i][i+1] = -r A_prime[i][i] = 2-2*r A_prime[i][i-1] = r A_prime[i][i+1] = rA = np.linalg.solve(A_prime, A)for i in range(len(T)): if i==0: for j in range(len(X)): U[i][j] = exact(T[i], X[j]) b[j] = U[i][j] else: b = np.linalg.solve(A, b) b[0], b[-1] = 0.0, 0.0 for j in range(len(X)): U[i][j] = b[j]for i in range(len(T)): for j in range(len(X)): if i>0: ax.plot([T[i-1], T[i]],[X[j], X[j]],[U[i-1][j], U[i][j]], 'r-', linewidth=0.5) if j>0: ax.plot([T[i], T[i]],[X[j-1], X[j]],[U[i][j-1], U[i][j]], 'r-', linewidth=0.5)bluePatch = mpatches.Patch(color='blue', label='Exact')redPatch = mpatches.Patch(color='red', label='Crank-Nicolson')pl.legend(handles = [bluePatch, redPatch], loc=2)pl.show()
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
| This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license. | |
https://creativecommons.org/licenses/by-sa/4.0 CC BY-SA 4.0 Creative Commons Attribution-Share Alike 4.0 truetrue |
Items portrayed in this file
depicts
creator<\/a>"}},"text\/plain":{"en":{"":"creator"}}},"{\"value\":{\"entity-type\":\"property\",\"numeric-id\":2093,\"id\":\"P2093\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"":"author name string<\/a>"}},"text\/plain":{"en":{"":"author name string"}}},"{\"value\":\"Shiyu Ji\",\"type\":\"string\"}":{"text\/html":{"en":{"P2093":"Shiyu Ji","P4174":"Shiyu Ji<\/a>"}},"text\/plain":{"en":{"P2093":"Shiyu Ji","P4174":"Shiyu Ji"}}},"{\"value\":{\"entity-type\":\"property\",\"numeric-id\":4174,\"id\":\"P4174\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"":"Wikimedia username<\/a>"}},"text\/plain":{"en":{"":"Wikimedia username"}}},"{\"value\":{\"entity-type\":\"property\",\"numeric-id\":2699,\"id\":\"P2699\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"":"URL<\/a>"}},"text\/plain":{"en":{"":"URL"}}},"{\"value\":\"http:\\\/\\\/commons.wikimedia.org\\\/wiki\\\/User:Shiyu_Ji\",\"type\":\"string\"}":{"text\/html":{"en":{"P2699":"http:\/\/commons.wikimedia.org\/wiki\/User:Shiyu_Ji<\/a>"}},"text\/plain":{"en":{"P2699":"http:\/\/commons.wikimedia.org\/wiki\/User:Shiyu_Ji"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P170 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
creator
some value
author name string: Shiyu Ji
Wikimedia username: Shiyu Ji
URL: http://commons.wikimedia.org/wiki/User:Shiyu_Ji
copyright status<\/a>"}},"text\/plain":{"en":{"":"copyright status"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":50423863,\"id\":\"Q50423863\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P6216":"copyrighted<\/a>"}},"text\/plain":{"en":{"P6216":"copyrighted"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P6216 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
copyright status
copyrighted
copyright license<\/a>"}},"text\/plain":{"en":{"":"copyright license"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":18199165,\"id\":\"Q18199165\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P275":"Creative Commons Attribution-ShareAlike 4.0 International<\/a>"}},"text\/plain":{"en":{"P275":"Creative Commons Attribution-ShareAlike 4.0 International"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P275 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
copyright license
Creative Commons Attribution-ShareAlike 4.0 International
inception<\/a>"}},"text\/plain":{"en":{"":"inception"}}},"{\"value\":{\"time\":\"+2016-11-16T00:00:00Z\",\"timezone\":0,\"before\":0,\"after\":0,\"precision\":11,\"calendarmodel\":\"http:\\\/\\\/www.wikidata.org\\\/entity\\\/Q1985727\"},\"type\":\"time\"}":{"text\/html":{"en":{"P571":"16 November 2016"}},"text\/plain":{"en":{"P571":"16 November 2016"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P571 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
inception
16 November 2016
source of file<\/a>"}},"text\/plain":{"en":{"":"source of file"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":66458942,\"id\":\"Q66458942\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P7482":"original creation by uploader<\/a>"}},"text\/plain":{"en":{"P7482":"original creation by uploader"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P7482 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
source of file
original creation by uploader
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 11:02, 16 November 2016 | 720 × 540 (369 KB) | Shiyu Ji | User created page with UploadWizard |
File usage
The following pages on the English Wikipedia use this file (pages on other projects are not listed):
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
Width | 576pt |
---|---|
Height | 432pt |