Question: Question 1 ( 1 0 points ) :Purpose: To practice string and file manipulation; to solve a problem using numpySolving systems of ( linear )
Question 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: x y z x y z x y z 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 standard, 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 : Hand SolveFirst solve the system of equations found in the provided file systemtxt 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 figures of precision.Part : Solve using numpyTo verify your work from part write a very small program that uses the numpy module to solve the systemof equations from systemtxt The method you need from the numpy module is numpy.linsolve.solveThe 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 lines of code. Check it against the answer you figured out by hand, and then hand this program inPart : Write an equation parserTake a look at the systems of equations found in systemtxt and systemtxt 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 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 separate functions that will divide the overall work for this problem, and that when called in sequence, will extract the info you need from the equations file in the format required by numpy. Well describe 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 : 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 ie everything upto the equal sign The second list should be a list of integers of all the constants ie all the numbers onthe right hand sign of the equal sign For example, for systemtxt the lists returned from this functionshould look like this: x y z x y z x y z Function : Get the variable namesWrite a function that accepts a list of equations like the list produced by function 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 systemtxt the list returned should look like this: x y z Function : Get the coefficientsWrite a function that accepts a list of equations like the list produced by function and returns a listoflists of integers, where each sublist contains all the coefficients of a SINGLE equation. For example, forsystemtxt the list returned should look like this: Page Main 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
