Question

In: Computer Science

Write a Python program tat asks the user for the number of equations (n) to be...

Write a Python program tat asks the user for the number of equations (n) to be solved and fill the coefficient matrix A and the right matrix b with random integers. Limit the values of the elements of A to numbers between 0 and 50 and elements of b to 0 and 500. Lastly, put the matrices into an Excel file.

Solutions

Expert Solution

Python 3 code

import random  #imported python inbuilt library for generation random numbers

import xlsxwriter #library for writing in excel file


n=int(input("Enter the number of equation: "))

#As we dont know the number of variables to be solved so we consider n equations with n different varibles

#So to solve n quations with n varible we use quation Ax=B where A is matrix of n*n and x is a varible matrix with n unknown varibles of n*1 an B is right matrix with solution variables of n*1.

#For generating matrix A with random variables between 0 to 50 of n*n

A=[[random.randint(0,50) for i in range(n)] for j in range(n)] #using random function and for loops

x=[f'x{k}' for k in range(n)] #generation of variable matrix

B=[random.randint(0,500) for l in range(n)] #generation of right matrix B

# Workbook() takes one, non-optional, argument  

# which is the filename that we want to create.

workbook = xlsxwriter.Workbook(f'result{n}.xlsx')

# The workbook object is then used to add new  

# worksheet via the add_worksheet() method.

worksheet = workbook.add_worksheet()

# Start from the first cell. Rows and

# columns are zero indexed.


# Iterate over the data and write it out row by row.

for row in range(n):

    for col in range(n):

        worksheet.write(row, col, A[row][col])

for rowv in range(n):

    worksheet.write(rowv,n,x[row])

for rowb in range(n):

    worksheet.write(rowb,n+1,B[rowb])

# Finally, close the Excel file

# via the close() method.

workbook.close()


Related Solutions

CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
Write a program using a Scanner that asks the user for a number n between 1...
Write a program using a Scanner that asks the user for a number n between 1 and 9 (inclusive). The program prints a triangle with 2n - 1 rows. The first row contains only the square of 1, and it is right-justified. The second row contains the square of 2 followed by the square of 1, and is right justified. Subsequent rows include the squares of 3, 2, and 1, and then 4, 3, 2 and 1, and so forth...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT