Euler’s method (solving 1st order differential equation)

Theory:- dy/dx=f(x,y) is 1st order equation, for approximation, a tangent at a given point will be fairly close to the original curve. Derivative at this point (x0,y0) is (dy/dx)x=x0 = f(x0,y0) Now, the tangent (y-y0)/(x-x0)=f(x0,y0) or, y=y0+f(x0,y0)*(x-x0)……..(I) if x1 is close enough to x0, we can say equation (I) can be the equation of the…… Continue reading Euler’s method (solving 1st order differential equation)

Newton-raphson method.

To find a root , f(x)=0 now, by Taylor series expansion and neglecting the higher orders. f(x)=f(x0)-f'(x0)*(x-x0)=0 or, x=x0-f(x0)/f'(x0) , x0 being the initial guess. generally:- xi=xi-1- f(xi)/f'(xi) i>=1 we iterate the values of x to reach as close to the actual root as possible.. def f(x): y=(1-x*2) return y def deriv(x): h=0.000001 deri=(f(x+h)-f(x))/h #derivative…… Continue reading Newton-raphson method.

Addition, multiplication and transpose of lists in python.

Addition of matrices:- Take the size of the matrix as user input, accept the two matrices and print the resultant matrix after adding the original two matrices. row=int(input(“enter the row”)) column=int(input(“enter the column”)) a=[] b=[] print(“1st matrix elements”) for i in range(0,row): a1=[] for j in range(0,column): e=int(input()) a1.append(e) a.append(a1) print(“2nd matrix elements”) for i…… Continue reading Addition, multiplication and transpose of lists in python.

Lists(built-in functions, list comprehension, Concatenation, examples and programs) in python.

Contents of this blog: Python lists.Built-in list functions.Accept list elements from user.List comprehension.List concatenation. A variable can store only one value at a time, but lists are built in data types which can store multiple values. a=[1,2,3] 1,2 and 3 are list items. They have different positions in the list called index. Indexing start from…… Continue reading Lists(built-in functions, list comprehension, Concatenation, examples and programs) in python.

Matrices using lists in python.

Contents of this blog: Matrix in python: list.Accepting list elements from user. Matrix is nothing but 2D lists, containing rows and columns. Elements in the 2D lists have positions(index). a=[[1,2,4],[2,4,7],[1,9,7]] is an example of 2D list. Column➡row ⬇01201(0,0)2(0,1)4(0,2)12(1,0)4(1,1)7(1,2)21(2,0)9(2,1)7(2,2) Row is denoted by i and columns are by j. So now , a[i][j] is the elements…… Continue reading Matrices using lists in python.

Jump statement in python (break and continue)

Jump statements in python are used to change or terminate the flow of a loop. Break statement:- Break statement is used to terminate a loop. Suppose in the loop , you are adding the iterables, you want to stop the loop when sum reaches a certain value. That can be achieved by, sum=0 for i…… Continue reading Jump statement in python (break and continue)

Getting started and Decision making in python.

Contents of this blog: Python program to find sum, difference and product.Program to find area and perimeter of rectangle.Decision making in python.if statementif else statementnested if statementProgram to accept three numbers. If they are unequal,display the greatest number.Program to accept a number and if it’s an even number, multiply the number by two if the…… Continue reading Getting started and Decision making in python.

General components of python programming.

Contents of this blog: VariablesData typesPrint statementType conversionInput statement Variables are named memory locations containing value. Variables can store values of different types.You can assign a value to a variable using a equal sign(=). Eg:- a=10. If you assign a new value to the same variable, previous value will be erased and the variable will…… Continue reading General components of python programming.

Palindrome number checking in python.

Palindrome number is a number which remains the same when digits are reversed. Eg:- 121, 434, 2442. x=int(input(“enter “)) num=x p=0 while x>0: rem=x%10 p=p*10+rem n=x/10 x=int(n) if(num==p): print(“the number is palindrome”) else: print(“not a palindrome number”) Output:- Explanation:- we store the value of x in some variable sum, because x will get updated through…… Continue reading Palindrome number checking in python.

Design a site like this with WordPress.com
Get started