Related questions
Can you fix the error in the python code.
import numpy as np
import matplotlib.pyplot as plt
N = 20 # number of points to discretize
L = 0.15
X = np.linspace(0, L, N) # position along the rod
h = L / (N - 1) # discretization spacing
C0t = 0.200 # concentration at x = 0
Cth = 0.00000409
D = 0.0000025
t_avg = 0
n = 0
tfinal = 300
Ntsteps = 1000
dt = tfinal / (Ntsteps - 1)
t = np.linspace(0, tfinal, Ntsteps)
alpha =( D * dt / h**2)
C_xt = [] # container for all the time steps
# initial condition at t = 0
C = np.zeros(X.shape)
C[0] = C0t
C_xt += [C]
for j in range(1, Ntsteps):
N = np.zeros(C.shape)
N[0] = C0t
N[1:-1] = alpha*C[2:] + (1 - 2 * alpha) * C[1:-1] + alpha * C[0:-2]
N[-1] = N[-2] # derivative boundary condition flux = 0
C[:] = N
C_xt += [N]
if ((Cth-0.000001) < N[-1]<(Cth+0.000001)):
print ('Time=',t[j],'conc=',[N[-1]],'Cthr=',[Cth])
t_avg = t_avg+t[j]
n = n + 1
# plot selective solutions
if j in [1,2,5,10,20,50,100,200,500]:
plt.plot(X, N, label='t={0:1.2f}'.format(t[j]))
t_thre = t_avg/n
plt.xlabel('Position in rod')
plt.ylabel('Concentration')
plt.title('Concentration at different times')
plt.legend(loc='best')
plt.savefig('transient-diffusion-temporal-dependence.png')
C_xt = np.array(C_xt)
plt.figure()
plt.plot(t, C_xt[:,5], label='x={0:1.2f}'.format(X[5]))
plt.plot(t, C_xt[:,10], label='x={0:1.2f}'.format(X[10]))
plt.plot(t, C_xt[:,15], label='x={0:1.2f}'.format(X[15]))
plt.plot(t, C_xt[:,19], label='x={0:1.2f}'.format(X[19]))
plt.legend(loc='best')
plt.xlabel('Time')
plt.ylabel('Concentration')
plt.savefig('transient-diffusion-position-dependence.png')
plt.show()
Step by stepSolved in 4 steps with 3 images
- An array of binary strings is given and you have to find the decimal number of each entry and store in new array and print the new array In JavaScriptarrow_forwardPython! Look at the image Thanksarrow_forward%matplotlib inline import math import numpy as np from matplotlib import pyplot as plt def f(x): return math.sqrt(-x/(x+1)) def g(x): return math.tan(math.sqrt(2*(x + 1))) xs = np.linspace(-0.999,-0.1, 100) fx = [f(x) for x in xs] gx = [g(x) for x in xs] plt.plot(xs,fx) plt.plot(xs,gx) plt.gridarrow_forward
- Python help! How do I code in an input for a specific number of cuts (through the whole pizza) I want throughout my 'pizza'?Code so far: import turtle background="#9EC388"crust="#ECA84F"sauce="#AD0509"cheese="#FBC70F"pepperoni=[[-70,105],[-85,175],[-25,50],[-15,100],[-25,150],[-30,205],[15,50],[20,120],[20,200],[60,156],[71,215],[80,90]]screen=turtle.Screen()screen.bgcolor(background)screen.title("my pizza")my_turtle=turtle.Turtle()my_turtle.pensize(5)my_turtle.shape("circle")def draw_circle(radius,line_color,fill_color): my_turtle.color(line_color)#draw the circle with the defined line color my_turtle.fillcolor(fill_color)#fill the circle my_turtle.begin_fill() my_turtle.circle(radius) my_turtle.end_fill()def move_turtle(x,y): my_turtle.up #my_turtle.penup() my_turtle.goto(x,y) #move the turtle my_turtle.down #my_turtle.pendown()draw_circle(150,crust,crust) #first circle for the crust which is drawn and filled by the same...arrow_forwardDo not copy from other websites (I will downvote) Correct and detailed answer will be Upvotedarrow_forwardHelp with python questions list colorsarrow_forward
- Simple Javascript only: Convert a Hexadecimal array of numbers into decimal values. The decimal values should be treated as ASCII character codes and converted into characters. Return a string of those characters. See the MDN docs for `String.fromCharCode()` method for how to convert character codes into ASCII characters. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode Examples: hexadecimalToString(['0x004a']) => 74 => "J" hexadecimalToString(['0x0041', '0x0042', '0x0043']) => 65, 66, 67 => "ABC" hexadecimalToString(['0x0048', '0x0065', '0x0078', '0x0061']) => 72, 101, 120, 97 => "Hexa". function hexadecimalToString(hexadecimalChars){ }arrow_forward%matplotlib inlineimport mathimport numpy as npfrom matplotlib import pyplot as pltdef bad_poisson(lmd, k): return pow(lmd,k)*math.exp(-lmd)/math.factorial(k)# bad_poisson(1000,1000) # uncomment to see it breaksarrow_forwardWhy my code given me error’s # Python code to draw snowflakes fractal. import turtle import random # setup the window with a background color wn = turtle.Screen() wn.bgcolor("cyan") # assign a name to your turtle elsa = turtle.Turtle() elsa.speed(15) # create a list of colours scolor = ["white", "blue", "purple", "grey", "magenta"] # create a function to create different size snowflakes def snowflake(size): # move the pen into starting position elsa.penup() elsa.forward(10*size) elsa.left(45) elsa.pendown() elsa.color(random.choice(sfcolor)) # draw branch 8 times to make a snowflake for i in range(8): branch(size) elsa.left(45) # create one branch of the snowflake def branch(size): for i in range(3): for i in range (3): elsa.forward(10.0*size/3) # draw branch 8 times to make a snowflake for i in range(8): branch(slice) elsa.left(45) # create one branch of the snowflake def branch (size): for...arrow_forward
- %matplotlib inlineimport numpy as npfrom matplotlib import pyplot as pltimport matharrow_forward2. Problem 2: In this problem you will test our "in class" version of Gaussian elimination against the version in numpy. Use both codes to solve some randomly chosen linear systems of size N 10, 20, 40, 80, 160, 320, 640, 1280, 2560, and 5120. Depending on your computer, the last two may or may not work. If they don't, just say so in your report. If you computer can do N- 10240 then try this as well. Note that in cach case N 10 * 2k for k = 1,..., 10. That is, each time we are doubling the size of the matrix. abone Plot the results as two curves. Our code in red and numPy in bluc. (Or whatever colors you prefer). Can you guess the function which governs the runtime? Based on this guess, how long would it take to do N 40960 using numPy? N=81920?arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education