Lab 5 - Python
Lab 5 - Python
1. Palindrome number
Write a function to check if the given number is a palindrome number. The function returns True
or False. A palindrome number is a number that is same after reverse. For example 98189, is a
palindrome number. Write a program using that function.
4. Matrix multiplication
Write a function to multiply two matrices: A[n,m] and B[n,o]. Then, check the result by using the
Numpy library (function matmul()).
Hint: use nested list to represent matrix. For example, the list [[1,2], [3,4], [4,5]] represents a 3x2
matrix. Use the statement: X = [ [ 0 for i in range(m)] for j in range(n)] to create an empty matrix
X of n rows and m columns.
Write a function to evaluate a polynomial f(x), defined by its coefficients (c[0] + c[1].x + c[2].x2
+ ...), at a given point x. Hint: x**i computes xi. Then, check the result by using the Numpy library
(function polyval()).
Plot the polynomial with X = [-4, -3, -2, -1, 0, 1, 2, 3, 4]. Hint: use library Matplotlib.
For example, the graph of f(x) = 2x3 - x2 + 1 is illustrated in the figure bellow.