Can you please revise the python code
import numpy as np
import matplotlib.pyplot as plt
N = 20 # number of points to discretize
L = 1.0
X = np.linspace(0, L, N) # position along the rod
h = L / (N - 1) # discretization spacing
C0t = 0.1 # concentration at x = 0
D = 0.02
tfinal = 50.0
Ntsteps = 1000
dt = tfinal / (Ntsteps - 1)
t = np.linspace(0, tfinal, Ntsteps)
alpha = D * dt / h**2
print (alpha)
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]
# 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]))
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()
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
- code in c++arrow_forwardCan you fix the error in the python code. import numpy as npimport matplotlib.pyplot as plt N = 20 # number of points to discretizeL = 0.15X = np.linspace(0, L, N) # position along the rodh = L / (N - 1) # discretization spacing C0t = 0.200 # concentration at x = 0Cth = 0.00000409D = 0.0000025t_avg = 0n = 0 tfinal = 300Ntsteps = 1000dt = 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 = 0C = 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…arrow_forwardIn PYTHON use a Monte Carlo Simulation to write a code that gives the probability that in a classroom of x people, at least 2 will be born on the same day of the year, ignoring leap year? The number of people in the class is given by the user as variable x. Here is the code outline that is needed to answer this question. Please use it in your answer: import mathimport random # create and initialize frequency table:ft = []k = 0while(k < 365) : ft.append(0) k = k+1 # Allow the user to determine class size:print("Please type in how many people are in the class: ")x= int(input()) success = 0 # Simulate:c = 0while(c < 10000) : # Step 1: re-initialize birthday frequency table (it must be re-initialized for each play-through (why?): k = 0 while(k < 365) : ft[k] = 0 k = k+1 # Step 2: randomly get x birthdays and update frequency table: k = 0 while(k < x): # your code goes here ########################## k = k+1 # Step 3: Check to see if this…arrow_forward
- Using jGRASP please de-bug this /**This program demonstrates an array of String objects.It should print out the days and the number of hours spent at work each day.It should print out the day of the week with the most hours workedIt should print out the average number of hours worked each dayThis is what should display when the program runs as it shouldSunday has 12 hours worked.Monday has 9 hours worked.Tuesday has 8 hours worked.Wednesday has 13 hours worked.Thursday has 6 hours worked.Friday has 4 hours worked.Saturday has 0 hours worked.Highest Day is Wednesday with 13 hours workedAverage hours worked in the week is 7.43 hours*/{public class WorkDays{public static void main(String[] args){String[] days = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"}; int[] hours = { 12, 9, 8, 13, 6, 4}; int average = 0.0;int highest = 0;String highestDay = " ";int sum = 0; for (int index = 0; index < days.length; index++){System.out.println(days[index] + " has "…arrow_forwardThere are given code: # TODO: Import math module def quadratic_formula(a, b, c):# TODO: Compute the quadratic formula results in variables x1 and x2return (x1, x2) def print_number(number, prefix_str):if float(int(number)) == number:print("{}{:.0f}".format(prefix_str, number))else:print("{}{:.2f}".format(prefix_str, number)) if __name__ == "__main__":input_line = input()split_line = input_line.split(" ")a = float(split_line[0])b = float(split_line[1])c = float(split_line[2])solution = quadratic_formula(a, b, c)print("Solutions to {:.0f}x^2 + {:.0f}x + {:.0f} = 0".format(a, b, c))print_number(solution[0], "x1 = ")print_number(solution[1], "x2 = ")arrow_forwardPython Turtle: How do I fix the code to make it generate lakes as bigger random dots, and mountains as a separate color (gray) from the grass area? (Big error: lake generates as entire circle inside land, want it generating like mountains).AKA: How do I separate each of the values to generate on its own without conflicting eachother. import turtleocean = "#000066"sand = "#ffff66"grass = "#00cc00"lake = "#0066ff"mountain = [[-60, 115], [-65, 200], [-10, 145], [-30, 70], [50, 115], [100, 150], [70, 200], [30, 70], [10, 180], [-10, 220]]def draw_circle(radius, line_color, fill_color): my_turtle.color(line_color) my_turtle.fillcolor(fill_color) my_turtle.begin_fill() my_turtle.circle(radius) my_turtle.end_fill()def move_turtle(x, y): my_turtle.penup() my_turtle.goto(x, y) my_turtle.pendown()num_cuts = int(input("How many rivers do you want on your Island? ")) screen = turtle.Screen()screen.bgcolor(ocean)screen.title("Island Generator")my_turtle =…arrow_forward
- My code to formulate a circle is giving me an 0.08% difference: Here's my code: # draw circle using turtle object import turtle import math def drawCircle(tobj,x,y,radius): # calculate the distance to travel each time distance = 2.0*math.pi*radius / 120.0 # take the turtle to the x,y co-ordinates tobj.penup() tobj.setposition(x,y) # draw the circle tobj.pendown() for i in range(0,120): tobj.right(3) tobj.fd(distance) def main(): x = 50 y = 75 radius = 100 t = turtle.Turtle() # call drawCircle drawCircle(t,x,y, radius) if __name__=='__main__': main() turtle.mainloop()arrow_forwardPython Turtle: How do I increase my circle size by 2x its current diamater, add/fix random mountain generation, keep lakes and mountains generating on the island (not off in the ocean), and have 'river' cuts going through the WHOLE circle instead of just stopping at the middle?My code so far: import turtleimport random # Define colorsocean = "#000066"sand = "#ffff66"grass = "#00cc00"lake = "#0066ff"mountain_color = "#808080" # Gray color for mountains def draw_circle(radius, line_color, fill_color): my_turtle.color(line_color) my_turtle.fillcolor(fill_color) my_turtle.begin_fill() my_turtle.circle(radius) my_turtle.end_fill() def move_turtle(x, y): my_turtle.penup() my_turtle.goto(x, y) my_turtle.pendown() def draw_lake(): x = random.randint(-100, 100) y = random.randint(-50, 100) move_turtle(x, y) draw_circle(30, lake, lake) screen = turtle.Screen()screen.bgcolor(ocean)screen.title("Island Generator") my_turtle =…arrow_forwardMipMaps I Suppose that a pixel projects to an area of 10x28 texels in a texture map. From what mipmap level does the texture unit look up the texture value for this pixel, if the texture unit is using "nearest" lookup for mipmaps? Enter a single integer that is the mipmap level. A/arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education