0% found this document useful (0 votes)
9 views39 pages

Module1 Part1

The document provides an introduction to Computational Physics, detailing the assessment breakdown for the course and the fundamental concepts of computation, algorithms, and flowcharts. It covers algorithm characteristics, procedures, recursion, and the complexity of algorithms, alongside practical examples in Python. Additionally, it discusses data structures, numerical methods, floating-point arithmetic, and computer architecture basics.

Uploaded by

ac2011491981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views39 pages

Module1 Part1

The document provides an introduction to Computational Physics, detailing the assessment breakdown for the course and the fundamental concepts of computation, algorithms, and flowcharts. It covers algorithm characteristics, procedures, recursion, and the complexity of algorithms, alongside practical examples in Python. Additionally, it discusses data structures, numerical methods, floating-point arithmetic, and computer architecture basics.

Uploaded by

ac2011491981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Introduction to Computational Physics

Dr. Sharad Chandra Tripathi

School of Advanced Sciences and Languages, VIT Bhopal University

1/39 © SCTripathi
Assessment Breakdown

Introduction to Computational Physics (PHY1003)

Sl.No. Mark Title Max. Mark Weightage %


1 Mid Term 50 30
2 Class Assessment - Tutorial 5 5
3 Class Assessment - Group Activity 5 5
4 Lab Assessment - Continuous Assessment 10 10
5 Lab Assessment - Challenging Task 10 10
6 Lab Assessment - Viva 5 5
7 Attendance 5 5
8 Term End Examination 100 30
Table: Assessment Breakdown

2/39 © SCTripathi
Introduction to Computations

Definition: What are computations?


The fundamentals of computation refer to the basic principles,
concepts, and techniques that form the foundation of computer science
and programming and form the basis for understanding how problems
are solved using algorithms and computational models.
Importance: Why are computations fundamental in
engineering?
computations are fundamental in engineering because they provide
powerful tools for modeling, analyzing, optimizing, and controlling
complex systems. They enhance efficiency, innovation, and reliability,
making them indispensable in modern engineering practice.

3/39 © SCTripathi
Algorithm

Definition:
A step-by-step procedure or formula for solving a problem.
Complexity:
Measures how the runtime or space requirements of an algorithm grow
with the size of the input (e.g., time complexity and space complexity).
Examples:
Sorting algorithms (like quicksort and mergesort), search algorithms
(like binary search), and graph algorithms (like Dijkstra’s shortest
path).

4/39 © SCTripathi
Algorithm
For a good algorithm, it must satisfy the following characteristics or
properties:
Input:
There must be a finite number of inputs for the algorithm.
Output:
There must be some output produced as a result of execution of the
algorithm.
Definiteness:
There must be a definite sequence of operations for transformation of
input into output.
Effectiveness:
Every step of the algorithm should be basic and essential.
Finiteness:
The transformation of input to output must be achieved in finite steps,
i.e. the algorithm must stop, eventually! Stopping may mean that it
should produce the expected output or a response that no solution is
possible.
5/39 © SCTripathi
Algorithm

Desirable Charactristics of an Algorithm


The algorithm should be general and is able to solve several cases.
The algorithms should use resources efficiently, i.e. takes less time and
memory in producing the result.
The algorithms should be understandable so that anyone can
understand and apply it to own problem.
The algorithm should follow the uniqueness such that each instruction
of the algorithm is unambiguous and clear.

6/39 © SCTripathi
What is a Flowchart?

Definition: A visual representation of a process or algorithm.


Components:
Start/End
Process
Decision
Input/Output
Flow lines

7/39 © SCTripathi
Flowchart Symbols

Start/End

Process

Decision

Input/Output

8/39 © SCTripathi
Creating a Flowchart

Identify the Process: Determine what needs to be represented.


Define Steps: Outline each step in the process.
Use Symbols: Apply appropriate symbols for each step.
Connect Steps: Use arrows to show the flow.

9/39 © SCTripathi
Example Algorithm

Problem: Find the largest number in a list.


Steps:
1 Start
2 Initialize max to the first number
3 For each number in the list
If number >max, update max
4 Output max
5 End

10/39 © SCTripathi
Python Code to find the largest number in a list

1
2 def find_l ar g es t _ nu m ber ( numbers ):
3 # Step 2: Initialize max to the first number
4 if not numbers : # Handle the case where the list is empty
5 return None
6
7 max_num = numbers [0]
8 # Step 3: For each number in the list
9 for number in numbers :
10 # Step 3.1: If number > max , update max
11 if number > max_num :
12 max_num = number
13 # Step 4: Output max
14 return max_num
15 # Example usage
16 numbers = [3 , 5 , 2 , 9 , 1]
17 largest_number = fi n d_largest_number ( numbers )
18 print ( " The largest number in the list is : " , largest_number )

11/39 © SCTripathi
Algorithm vs. Flowchart

Algorithms: Abstract, step-by-step logic


Flowcharts: Visual representation, easier to understand process

12/39 © SCTripathi
Algorithm

Greatest Common Divisor (GCD) of two given integers.


The pseudo code for computing GCD (a, b) by Euclid’s method is as
follows:
// a and b are two positive numbers where a is dividend and b is a divisor
1 If b=0, return a and exit.
2 else go to step 3.
3 Divide a by b and assign remainder to r.
4 Assign the value of b to a and the value of r to b and go back to step
1.
To validate the algorithm, it must produce the desired result within finite
number of steps. The above-mentioned algorithm has two inputs and one
output. The algorithm is also definiteness and written in basic and effective
sentences. The algorithm is also finite as it terminates in finite steps.

13/39 © SCTripathi
Algorithm

Greatest Common Divisor (GCD) of two given integers.


To observe the same, let us find the GCD of a = 1071 and b = 462 using
Euclid’s algorithm.
Iteration 1:
1 Divide a=1071 by b=462 and store the remainder in r.
r= 1071 % 462 (here, % represents the remainder operator)
r = 147
2 If r = 0, the algorithm terminates and b is the GCD. Otherwise, go to
Step 3.
Here, r is not zero, so we will go to Step 3.
3 The integer will get the current value of integer b and the new value
of integer b will be the current value of r.
Here, a=462 and b=147
4 Go back to Step 1.

14/39 © SCTripathi
Algorithm

Greatest Common Divisor (GCD) of two given integers.


Iteration 2:
1 Divide a= 462 by b= 147 and store the remainder in r.
r= 462 % 147 (here, % represents the remainder operator)
r = 21
2 If r = 0, the algorithm terminates and b is the GCD. Otherwise, go to
Step 3.
Here, r is not zero, so we will go to Step 3.
3 The integer a will get the current value of integer b and the new
value of integer b will be the current value of r.
Here, a= 147 and b= 21
4 Go back to Step 1.

15/39 © SCTripathi
Algorithm

Greatest Common Divisor (GCD) of two given integers.


Iteration 3:
1 Divide a=147 by b=21 and store the remainder in r.
r= 147 % 21 (here, % represents the remainder operator)
r=0
2 If r = 0, the algorithm terminates and b is the GCD. Otherwise, go to
Step 3.
Here, r is zero, so the algorithm terminates and b is the answer, i.e.
21.

16/39 © SCTripathi
Building Blocks of Algorithm

An algorithm is a procedural way to write the solution of a problem. It is


designed with five basic building blocks.

Building Block Common Name


Sequencing Step by step actions
Selection Decision
Iteration Repetition or Loop
Procedure
Recursion

Sequencing: A problem can be solved by performing some actions in a


sequence [called algorithm], and the order of execution of those actions is
important to ensure the correctness of an algorithm. If the order of steps
of algorithm changes and does not follow the steps as specified, it will not
produce the correct output as expected.
17/39 © SCTripathi
Algorithms and Flowcharts

Selection: As an algorithm has to be generalized to solve many cases,


there may be situations where the sequence of execution of actions may
depend on some condition. That is, some of the instructions will only be
executed if a given condition satisfies. It is like the next action to be
performed is dependent upon some Boolean expression. So, using
selection, next step to be executed is determined.
Iteration: While solving a problem certain actions may be required to
execute a certain number of times or until a certain condition is met.

18/39 © SCTripathi
What is a Procedure?

It may happen that a sequence frequently occurs either in the same


algorithm repeatedly in different parts of the algorithm or may occur in
different algorithms. In such cases, writing repeatedly of the same
sequence, is a wasteful activity. Procedure is a mechanism that provides a
method of checking this wastage.
For example we can define GCD(a, b) as a procedure/function only once
and can call it a number of times in a main function with different values
of a and b.
In the realm of algorithms and computer science, a procedure refers to a
well-defined sequence of steps or a method for accomplishing a specific
task or function. It encompasses several important concepts:

19/39 © SCTripathi
Algorithmic Procedure

An algorithmic procedure is a detailed sequence of actions designed to


solve a particular problem or perform a specific computation. For instance,
sorting algorithms such as QuickSort or MergeSort are procedures
specifically crafted to arrange elements in a list.

20/39 © SCTripathi
Subroutines and Functions

In programming, a procedure is often implemented as a subroutine,


function, or method. These are blocks of reusable code that execute a
particular task. Examples include:
A function that calculates the factorial of a number.
A method that finds the greatest common divisor (GCD) of two
integers.
These elements are integral to structuring code efficiently and maintaining
modularity.

21/39 © SCTripathi
Procedures in Programming Languages

In various programming languages, procedures are defined using specific


syntax and can be invoked from other parts of the code. They promote:
Code Reusability: Write once, use multiple times.
Modularity: Break down complex tasks into simpler, manageable
components.

22/39 © SCTripathi
Procedure vs. Process

It’s essential to distinguish between procedures and processes. While a


procedure refers to a defined set of steps for performing a task, a process
encompasses the broader execution environment, including various
procedures and their management.

23/39 © SCTripathi
Summary

In summary, a procedure in the context of algorithms is a structured


method or set of steps for achieving a specific objective. Whether solving
a problem, performing a computation, or executing a task in programming,
procedures are fundamental to efficient and organized coding practices.

24/39 © SCTripathi
What is Recursion?

Recursion is a method where a function calls itself to solve smaller


instances of the same problem.
Useful for problems that can be broken down into simpler, similar
sub-problems.
Key Components:
Base Case: Termination condition, solving the simplest form of the
problem directly.
Recursive Case: Function calls itself with a modified argument,
moving towards the base case.
Recursive Call: The function calls itself with new parameters to solve
a smaller problem.

25/39 © SCTripathi
Factorial Definition:
Base Case: 0! = 1 and 1! = 1
Recursive Case: n! = n × (n − 1)!
Python Implementation:
1
2 def factorial ( n ):
3 if n == 0 or n == 1:
4 return 1
5 else :
6 return n * factorial ( n - 1)

26/39 © SCTripathi
Advantages and Disadvantages

Advantages:
Simplicity: Often more elegant and easier to understand.
Reduction in Code Complexity: Can reduce the amount of code
compared to iterative solutions.
Disadvantages:
Memory Usage: Each recursive call adds to the call stack, leading to
higher memory consumption.
Performance: Recursive calls can be less efficient due to overhead
from multiple function calls.

27/39 © SCTripathi
Fibonacci Definition:
Base Case: fib(0) = 0 and fib(1) = 1
Recursive Case: fib(n) = fib(n − 1) + fib(n − 2)
Python Implementation:
1
2 def fibonacci ( n ):
3 if n == 0:
4 return 0
5 elif n == 1:
6 return 1
7 else :
8 return fibonacci ( n - 1) + fibonacci ( n - 2)

28/39 © SCTripathi
Complexity of Algorithms
Time Complexity: The running time of an algorithm for producing the
output is also known as time complexity. The running time of an
algorithm is represented as a function T (n), where n is the input size. In
this presentation, we will examine a specific case where the running time is
given by a linear function.
Consider an algorithm with a running time T (n) expressed as:

T (n) = cn (1)

where c is a constant.
In this linear model:
T (n) denotes the running time of the algorithm.
n represents the size of the input.
c is a constant factor that characterizes the time required per unit of
input size.
29/39 © SCTripathi
The unit of T (n) is unspecified and depends on the context (e.g.,
milliseconds, seconds). The linear dependency means:
If the input size n doubles, the running time T (n) also doubles.
This straightforward relationship makes it easier to predict the
algorithm’s performance as the input size increases.

30/39 © SCTripathi
Data Structures

Introduction:
What are data structures and why they matter?
Types of Data Structures:
Arrays, Linked Lists, Stacks, Queues, Trees, Graphs
Applications in Engineering:
Practical examples where data structures are used

31/39 © SCTripathi
Numerical Methods

Introduction:
Importance of numerical methods in engineering computations
Common Methods:
Root finding, Integration, Differentiation, Solving ODEs
Tools:
MATLAB, Python libraries (e.g., NumPy, SciPy)

32/39 © SCTripathi
Floating-Point Arithmetic

Representation:
How real numbers are represented in computers
Precision and Errors:
Rounding errors and precision limits
IEEE Standard for Floating-Point Arithmetic:
Basic understanding of IEEE 754 standard

33/39 © SCTripathi
Computer Architecture Basics

Overview of Computer Architecture:


CPU, Memory, Input/Output devices
Von Neumann Architecture:
Stored-program concept
Execution Cycle:
Fetch, Decode, Execute, Store

34/39 © SCTripathi
Introduction

Computer architecture refers to the design and organization of a


computer system.
It includes the hardware components and their interactions.
Key aspects include the CPU, memory hierarchy, and I/O systems.

35/39 © SCTripathi
Basic Components

Central Processing Unit (CPU):


Executes instructions
Consists of an Arithmetic Logic Unit (ALU) and Control Unit (CU)
Memory:
Stores data and instructions
Includes RAM, cache, and secondary storage
Input/Output (I/O):
Interfaces with external devices
Examples include keyboards, monitors, and printers

36/39 © SCTripathi
Data Path and Control

Data Path:
The path data follows within the CPU
Includes buses, registers, and ALU
Control Unit:
Directs operations of the CPU
Decodes instructions and generates control signals

37/39 © SCTripathi
Memory Hierarchy

Registers:
Small, fast storage within the CPU
Cache:
Fast memory closer to the CPU
Stores frequently accessed data
Main Memory (RAM):
Larger but slower than cache
Secondary Storage:
Non-volatile storage like SSDs and HDDs

38/39 © SCTripathi
Conclusion

Computer architecture encompasses all aspects of a computer’s


design and function.
Understanding these components helps in optimizing performance and
efficiency.
Future advancements continue to evolve the architecture, impacting
both hardware and software.

39/39 © SCTripathi

You might also like