Question: Question 1 ( 1 0 points ) :Purpose: To practice string and file manipulation; to solve a problem using numpySolving systems of ( linear )

Question 1(10 points):Purpose: To practice string and file manipulation; to solve a problem using numpySolving systems of (linear) equations is a common task in mathematics. For example, here is a small systemof three equations with three unknowns: 2 x + y +3 z =95 x +3 y + z =15x +7 y +12 z =0 Solving the system means finding numeric values for all the unknowns, in this case, x, y, and z, such thatall three equations are simultaneously true.Small systems of equations can be solved by hand, but most programming languages, and certainlyPython, have libraries that can solve them for you. Youll explore that idea in this question.Using NumpyThe programming parts of this assignment will require using the numpy module. This module is NOT stan-dard, so if you are working on your own machine, you may need to install it first. Depending on how youinstalled Python, this can hopefully be as easy as pulling up a terminal and typing conda install numpy.Part 1: Hand SolveFirst solve the system of equations found in the provided file system1.txt (its the same one as the exampleshown just above). Do it by hand using any method you like, but without using a program of any kind. Showyour work and hand it in. You can round any decimal numbers in your final answer to 4 figures of precision.Part 2: Solve using numpyTo verify your work from part 1, write a very small program that uses the numpy module to solve the systemof equations from system1.txt. The method you need from the numpy module is numpy.linsolve.solve().The only trick comes from figuring out the format that you need to use for your system in order to feed itin to the solve() method.In order to do that, go ahead and use ChatGPT! Go to ChatGPT (or any other large language model thatyou like) and ask it something like "show me a simple example of how to solve systems of linear equationsin Python". Dont tell ChatGPT anything about your SPECIFIC system of equations. Just use the exampleit gives you to write your own program that solves that system. Most likely your program will be no morethan 5 lines of code. Check it against the answer you figured out by hand, and then hand this program in.Part 3: Write an equation parserTake a look at the systems of equations found in system2.txt and system3.txt. Would you want to solvethese systems by hand or even manually plug them in to the format that numpy.linsolve.solve() requires?If you said no, then good. Youre ready for the main part of this question.Your last task is to write a program that: asks the user to enter the name of a file containing a system of equations extracts the necessary info from that file and solves the system using numpy prints the solution to the console in a simple but readable way Equation file formatThe systems of equations will be given in files similar to the provided examples. You can count on thefollowing simplifying guarantees concerning that file format: Each line of the file will be a single equation All of the variables and their coefficients will be on the left hand of the equal sign All of the variables in each equation will be the same, and in the same order Every equation will include every variable (using a coefficient of 0 if needed) All of the constants and coefficients will be integers (not floats) The variables will be joined exclusively with + signs (the coefficients themselves may be negative) The first character of each variable will always be an alphabetic letterYou will find the provided equation files match these rules, and your program should work on any otherfile that also follows these rules.Problem DecompositionWrite 3 separate functions that will divide the overall work for this problem, and that when called in se-quence, will extract the info you need from the equations file in the format required by numpy. Well de-scribe those functions here.Note that this is NOT the only way to solve this problem; its exposing you to just ONE reasonable way todecompose this problem into manageable chunks.Function 1: Get the equationsWrite a function that accepts the file name where the equations are scored, and returns TWO separatelists. The first list should be a list of strings, where each string is one of the equations (i.e. everything upto the equal sign). The second list should be a list of integers of all the constants (i.e. all the numbers onthe right hand sign of the equal sign). For example, for system1.txt, the lists returned from this functionshould look like this: [2 x + y +3 z ,5 x +3 y + z , x +7 y +12 z ][9,15,0] Function 2: Get the variable namesWrite a function that accepts a list of equations (like the list produced by function 1) and returns a list ofall the variable names from the system (youll need this simply to print out the solution a little more nicelyat the end). For example, for system1.txt, the list returned should look like this: [ x , y , z ] Function 3: Get the coefficientsWrite a function that accepts a list of equations (like the list produced by function 1) and returns a list-of-lists of integers, where each sublist contains all the coefficients of a SINGLE equation. For example, forsystem1.txt, the list returned should look like this: [[2,1,3],[5,3,1],[1,7,12]] Page 3Main ProgramIf all three of your functions are working, the main part of your program will be very simple. It only needsto ask the user for the file name, call the three functions in sequence, feed the resulting lists into the linearsolver from numpy, and then use a simple loop of some kind to nicely print out the solution to the system

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!