Expt.
No: 1
Plot a Line Graph
Aim:
To write a Python program to plot a simple line graph using the matplotlib library.
Requirements:
1. Library: [Link]
2. Python Version: 3.x or above
3. Concept Used: 2D plotting and data visualization.
Python Code:
Steps:
1. Import [Link] as plt.
2. Accept number of data points from the user.
3. Input X and Y values from the user.
4. Use [Link]() to draw the line graph.
5. Label the axes and add a title.
6. Display the graph using [Link]().
Sample Output:
Precautions:
1. Ensure matplotlib is installed (pip install matplotlib).
2. The X and Y lists must have the same number of elements.
3. Use numeric values only.
Expt. No: 2
Plot a Pie Chart
Aim:
To write a Python program to plot a pie chart representing percentage distribution using the matplotlib library.
Requirements:
1. Library: [Link]
2. Python Version: 3.x or above
3. Concept Used: Pie chart plotting.
Python Code:
Steps:
1. Import the [Link] library.
2. Ask the user for number of sections in the pie chart.
3. Accept labels (names) and values for each section.
4. Use [Link]() to plot the pie chart with labels and percentages.
5. Display the pie chart using [Link]().
Sample Output:
Precautions:
1. Ensure the total of all values makes logical sense (e.g., total = 100).
2. Always use numeric values for data.
3. Keep label names short for better readability.
Expt. No: 3
Plot a Parabola
Aim:
To write a Python program to plot a parabola y=ax2+bx+cy = a x^2 + b x + cy=ax2+bx+c using the
matplotlib library.
Requirements:
1. Library: [Link], numpy
2. Python Version: 3.x or above
3. Concept Used: Equation plotting and array manipulation.
Python Code:
Steps:
1. Import numpy and [Link].
2. Input the coefficients aaa, bbb, and ccc from the user.
3. Generate a range of X values using [Link]().
4. Compute Y values using the parabola equation.
5. Plot the graph using [Link]().
6. Add title, labels, and grid, then display the graph.
Sample Output:
Precautions:
1. Make sure numpy and matplotlib are installed.
2. Use appropriate range for X to see the full curve.
3. Large values of coefficients may stretch the graph excessively.
Expt. No: 4
Plot a Bar Graph
Aim:
To write a Python program to plot a bar graph using user input for categories and values.
Requirements:
1. Library: [Link]
2. Python Version: 3.x or above
3. Concept Used: Visualization of data using bar charts.
Python Code:
Steps:
1. Import [Link] as plt.
2. Take number of bars and their data from user.
3. Use [Link]() to create the bar graph.
4. Label the X-axis and Y-axis
5. Add a title and display the graph.
Sample Output:
Precautions:
1. Ensure all numeric inputs are valid.
2. Choose suitable bar width for clear visualization.
3. Category names should be short add readable.
Expt. No: 5
Add and Subtract Two Vectors
Aim:
To write a Python program to perform addition and subtraction of two vectors using user input.
Requirements:
1. Libraries: No external library required.
2. Python Version: 3.x or above.
3. Concept Used: Vector operations using lists and loops.
Python Code:
Steps:
1. Input the dimension of the vectors.
2. Enter elements of Vector A and Vector B.
3. Define functions for vector addition and subtraction.
4. Perform element-wise addition and subtraction using list comprehension.
5. Display the results.
Sample Output:
Precautions:
1. Both vectors must have the same dimensions.
2. Only numeric values should be entered.
3. Be careful while entering data — incorrect input size may cause errors.
Expt. No: 6
Find Dot Product of Two Vectors
Aim:
To write a Python program to calculate the dot product of two vectors.
Requirements:
1. Libraries: No external libraries required.
2. Python Version: 3.x or above.
3. Concept Used: Dot product using loops or list comprehension.
Python Code:
Steps:
1. Take the dimension and input both vectors.
2. Multiply corresponding elements of both vectors.
3. Sum up the products to get the dot product.
4. Display the result.
Sample Output:
Precautions:
1. Both vectors must have the same size.
2. Input only numeric values.
3. Double-check element count before execution.
Expt. No: 7
Multiply Two Square Matrices
Aim:
To write a Python program to multiply two square matrices of any order.
Requirements:
1. Library: No external libraries required.
2. Python Version: 3.x or above.
3. Concept Used: Nested loops for matrix multiplication.
Python Code:
Steps:
1. Input order n of the matrices.
2. Accept elements for both matrices A and B.
3. Use nested loops to multiply corresponding rows and columns.
4. Store and print the result matrix.
Sample Output:
Precautions:
1. Both matrices must be square and of the same size.
2. Use only numeric values.
3. Check input carefully for correct dimensions.
Expt. No: 8
Find Inverse of a 3×3 Matrix
Aim:
To write a Python program to find the inverse of a 3×3 matrix using NumPy.
Requirements:
1. Library: numpy
2. Python Version: 3.x or above
3. Concept Used: Matrix inversion using NumPy’s [Link]() function.
Python Code:
Steps:
1. Import numpy as np.
2. Input elements for a 3×3 matrix.
3. Compute determinant using [Link]().
4. If determinant ≠ 0, compute inverse using [Link]().
5. Display the inverse matrix.
Sample Output:
Precautions:
1. Determinant must not be zero; otherwise, inverse doesn’t exist.
2. Use accurate floating-point numbers.
3. Ensure NumPy is installed (pip install numpy).
Expt. No: 9
Find Eigenvalues of a 3×3 Matrix
Aim:
To write a Python program to find the eigenvalues and eigenvectors of a 3×3 matrix.
Requirements:
1. Library: numpy
2. Python Version: 3.x or above
3. Concept Used: Linear algebra computation using [Link]().
Python Code:
Steps:
1. Import numpy.
2. Input a 3×3 matrix.
3. Use [Link]() to find eigenvalues and eigenvectors.
4. Print both clearly.
Sample Output:
Precautions:
1. Input must be a 3×3 square matrix.
2. Floating-point rounding may slightly affect eigenvalues.
3. Ensure all elements are numeric.
Expt. No: 10
Solve Linear Equations with 3 Variables
Aim:
To write a Python program to solve three linear equations in three unknowns using matrices.
Requirements:
1. Library: numpy.
2. Python Version: 3.x or above
3. Concept Used: Solving matrix equations Ax=b
Python Code:
Steps:
1. Input coefficients for 3 linear equations.
2. Store them in a coefficient matrix A and constants vector b.
3. Use [Link](A, b) to compute [x, y, z].
4. Display the result.
Sample Output:
Precautions:
1. Ensure coefficient matrix is non-singular (det(A) ≠ 0).
2. Use numeric values only.
3. Enter coefficients carefully to avoid input errors.