Found 34494 Articles for Programming

Modelling the Trapezoidal Rule for Numerical Integration in Python

Dr Pankaj Dumka
Updated on 03-Oct-2023 14:56:35

495 Views

The purpose of integration (definite) is to calculate the area under a curve of a function between two limits, a and b. The plot shown below will clear this concept further. Quadrature, which is also commonly called as numerical integration, is a method for evaluating the area under the curve of a given function. The process is very simple i.e. first we dividing the bounded area into several regions or strips. Thereafter, the areas is evaluated with the help of mathematical formula of simple rectangle. Then the area of all strips is added to obtain the gross area under ... Read More

Modelling Stirling and Ericsson Cycles in Python

Dr Pankaj Dumka
Updated on 03-Oct-2023 14:52:26

105 Views

Stirling Cycle Four processes—two reversible isochoric and two reversible isothermal—make up the Stirling cycle. In the same temperature range, the efficiency of the ideal regenerative Stirling cycle is equivalent to that of the Carnot cycle. Heat interaction takes place throughout the cycle, whereas work interaction only happens in processes 1-2 and 3–4. The figure shown below displays the cycle's schematic. Maximum pressure $\mathrm{(p_{max})}$, minimum pressure $\mathrm{(p_{min})}$, maximum volume $\mathrm{(v_{max})}$, compression ratio (r), and adiabatic exponent $\mathrm{(\gamma)}$ are the input variables taken into consideration when modelling the cycle. The following list includes the thermodynamic calculations of several processes involved in ... Read More

Finding the Summation of Random Numbers using Python

Kalyan Mishra
Updated on 03-Oct-2023 15:00:10

320 Views

In this article we will learn about different methods to find the Summation of Random Numbers using Python language. In some scenarios we need to generate some random number and find its summation so we will see basic to improved versions of functions using which we can get this task done. Let’s see some methods to find the summation of random numbers. Method 1. Using Simple Loop Example import random n = 10 rand_nums = [] for _ in range(n): rand_nums.append(random.randint(1, 100)) total = sum(rand_nums) print("Random Numbers:", rand_nums) print("Summation of random numbers:", total) Output Random Numbers: ... Read More

Queue.LIFOQueue vs Collections.Deque in Python

Kalyan Mishra
Updated on 03-Oct-2023 16:03:16

161 Views

In this article we will learn about Queue.LIFOQueue vs Collections.Deque in Python programming language. When we need to manage our data using the last in first out method then we can use these data structures. But to choose one of them we need to know about their functionalities and characteristics. Before that let’s get to know about Queue.LIFOQueue and Collections.Deque. LIFOQueue This class is part of the queue module. It works as stack data structure and it is considered as thread safe means we can talk between the different threads at the same time. Here are some specifications of ... Read More

Modelling the Otto and Diesel Cycles in Python

Dr Pankaj Dumka
Updated on 03-Oct-2023 13:54:05

219 Views

Otto Cycle An air standard cycle called the Otto Cycle is employed in spark ignition (SI) engines. It comprises of two reversible adiabatic processes and two isochoric processes (constant volume), totaling four processes. When the work interactions take place in reversible adiabatic processes, the heat addition (2-3) and rejection (4-1) occur isochorically (3-4 and 1-2). The Otto cycle's schematic is shown in Figure given below. To model the cycle in Python, the input variables considered are maximum pressure $\mathrm{(P_{max})}$, minimum pressure $\mathrm{(P_{min})}$, maximum volume $\mathrm{(V_{max})}$, compression ratio (r), and adiabatic exponent $\mathrm{(\gamma)}$. Table 2 explains the thermodynamic computations of ... Read More

Python - Replace sublist with others in list

Kalyan Mishra
Updated on 03-Oct-2023 15:48:19

132 Views

In this article we will get to know how we can replace sublist value with new list. You may have faced this problem while working with manipulation of list. Here we will see various methods using which we can replace the sublist with other list. Let’s get to know this using below example − listItem = [1, 2, 3, 4, 5, 6] new_list = [7, 8, 9] Here we have list named as listItem which contains some elements and we have another list named as new_list. So, we want to replace the sublist of listItem with new_list. Take ... Read More

Python - Replace rear word in String

Kalyan Mishra
Updated on 03-Oct-2023 15:42:20

78 Views

In this article we will learn how we can replace rear (word at the end of the string) word with any other given word. You may have seen this problem while doing manipulation of string. Here we will see various methods for replacing the rear word in string with given word. Let’s get to know this using below example − string_txt = "This cat is running very Fast" Here we have a string string_txt which contains sentences and we want to replace the last word which is "Fast" into "Slow" so that the resulting string will be like. ... Read More

Python - Replace punctuations with K

Kalyan Mishra
Updated on 03-Oct-2023 15:40:12

56 Views

In this article we will learn about replacement of punctuation with letter k in the string. You may have seen this problem while performing text processing or data cleaning task in the python where you need to replace punctuations with specific characters or any symbol. Here we will see various methods for replacing the punctuations with given text "k" Let’s get to know this using below example − string = "Welcome, to, * the website ! aliens" Here we have a string which contains punctuations like [, * !] and we want to replace that with text "k". ... Read More

Modelling the Gauss Seidel Method in Python

Dr Pankaj Dumka
Updated on 03-Oct-2023 13:47:54

2K+ Views

Gauss Seidel Method is the iterative method to solve any system of linear equations. Though the method is very much similar to the Jacobi's method but the values of unknown (x) obtained in an iteration are used in the same iteration in Gauss Seidel whereas, in Jacobi's method they are used in the next iteration level. The updation of x in the same step speeds up the convergence rate. A system of liner equation can be written as − $$\mathrm{a_{1, 1}x_{1} \: + \: a_{1, 2}x_{2} \: + \: \dotso \: + \: a_{1, n}x_{n} \: = \: b_{1}}$$ $$\mathrm{a_{2, ... Read More

Python - Replace negative value with zero in numpy array

Kalyan Mishra
Updated on 03-Oct-2023 15:37:32

1K+ Views

In this article we will see method to replace negative values with zero. If we talk about data analysis then handling negative values is very crucial step to ensure meaningful calculation. So, here you will learn about various methods using which we can replace negative values with 0. Method 1. Using Traversal and List Comprehension. Example import numpy as np arr = np.array([-12, 32, -34, 42, -53, 88]) arr = [0 if x < 0 else x for x in arr] arr = np.array(arr) print("array with replaced values is: ", arr) Output array with replaced values ... Read More

Advertisements