[SOLVED] 代写 • Content

30 $

File Name: 代写_• Content.zip
File Size: 169.56 KB

SKU: 4304095886 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


•Content
You are required to write a program to solve polynomial equations of the form:
你需要编写一个程序来解决形式的多项式方程:

While there might be more than one solution for such equations, for this particular application we are interested only in the smallest non-negative solution of the equation. If there does not exist such solution, your program should output a negative number, for example -1.
虽然对于这样的方程可能存在多个解,但对于该特定应用,我们仅对该方程的最小非负解决方案感兴趣。 如果不存在此类解决方案,则程序应输出负数,例如-1。

Let us consider a couple of examples.
•For the coefficients= 1, b = 5, c = 6 the corresponding equation has solutionsand ; in this case there is no positive solution and your program should output -1.
对于系数a = 1,b = 5,c = 6,对应的方程x ^ 2 + 5x + 6 = 0具有解x = -2且x = -3; 在这种情况下,没有正解,你的程序应该输出-1。

•If we consider the equation with coefficients= 1, b = 0, c = -1, with solutionsand , your program should output 1.
如果我们考虑系数a = 1,b = 0,c = -1的等式,解x = 1且x = -1,则程序应输出1。

The values forandwill be obtained from three separated csv files. They might take the value of any real number, so your program should be prepared to handle any combination.
a,b和c的值将从三个独立的csv文件中获得。 它们可能会取任何实数的值,因此您的程序应该准备好处理任何组合。
•Your task
You must write your assignment based on the template given on blackboard: “2019_assignment2_student.py”. You must respect the function and variable names present there, but you are permitted to define your own.
您必须根据黑板上给出的模板编写作业:“2019_assignment2_student.py”。 您必须尊重那里存在的函数和变量名,但您可以定义自己的函数和变量名。
Your program should perform the following tasks:
•Read a list of “a”, “b” and “c” coefficients from three separated CSV files.
•Calculate the smallest positive solution of a quadratic equation defined by these lists of coefficients
•You are provided with skeleton code.The functions read_csv_file(), solve_quadratic_equation() and solve_array_of_equations() are incomplete.Your assignment is to complete the functions.
•从三个独立的CSV文件中读取“a”,“b”和“c”系数列表。
•计算由这些系数列表定义的二次方程的最小正解
•您将获得骨架代码。 函数read_csv_file(),solve_quadratic_equation()和solve_array_of_equations()不完整。 您的任务是完成这些功能。

1.2. Functions Specification:
read_csv_file(): The function accepts a single keyword argument – file_path, that represents the CSV filename that it will read. The purpose of the function is to read in a csv file into a Numpy array.The function must return a Numpy array.
read_csv_file():该函数接受一个关键字参数 –file_path,它表示它将读取的CSV文件名。 该函数的目的是将csv文件读入Numpy数组。 该函数必须返回Numpy数组。

solve_quadratic_equation(): The function accepts three keyword arguments – a, b, and c.The keyword arguments a, b and c are floats that represent the coefficients of the quadratic equation.The function must return a Tuple.The first item in the Tuple must be a float representing the smallest positive root of the quadratic.The second item in the Tuple must be an int representing an error code (0, -1 or -2). The purpose of the function is to solve a quadratic for its smallest positive root.
solve_quadratic_equation():该函数接受三个关键字参数 –a,b和c。 关键字参数a,b和c是浮点数,表示二次方程的系数。 该函数必须返回一个元组。 元组中的第一项必须是表示二次方的最小正根的浮点数。 元组中的第二项必须是表示错误代码(0,-1或-2)的int。 该函数的目的是求解其最小正根的二次方。
•If the function successfully finds one or more positive roots of the quadratic then your function must return the smallest positive root and the error code 0.
•If the function does not find any positive roots then it must return a root of -1 instead and an error code of -1.
•If the function does not find any real roots (i.e. no solutions) then it must return a root of -1 and an error code of -2
•如果函数成功找到二次方的一个或多个正根,则函数必须返回最小的正根和错误代码0。
•如果函数没有找到任何正根,那么它必须返回-1的根,错误代码为-1。
•如果函数找不到任何实根(即没有解),那么它必须返回-1的根,错误代码为-2

solve_array_of_equations(): The function accepts three keyword arguments:a_vector, b_vector, and c_vector.The vector keyword arguments are Numpy arrays of the a, b and c coefficients that form the quadratic equations to solve.The function must create and return a Numpy array that contains the smallest positive root of each of these equations.If, however, there are no positive or real roots to the equation then the value -1 must be stored in the array instead.
solve_array_of_equations():该函数接受三个关键字参数:a_vector,b_vector和c_vector。 矢量关键字参数是a,b和c系数的Numpy数组,形成要求解的二次方程。 该函数必须创建并返回一个Numpy数组,该数组包含每个方程的最小正根。 但是,如果等式没有正或根,那么值-1必须存储在数组中。
•General Guidance
•Input Data
The input data is provided in three comma separated value (CSV) files. Each file contains one coefficient per row, used to create the polynomial equation. Your answer file must replicate this order, so the first entry is the solution of the equation formed by the coefficients in the first row of each of the other files. Below is a small example of three input files and the answer file:
a.csv

b.csv

c.csv

answer.

Equation to solve
1

5

6

-1

1

0

-1

1

输入数据以三个逗号分隔值(CSV)文件提供。 每个文件每行包含一个系数,用于创建多项式方程。 您的答案文件必须复制此顺序,因此第一个条目是由每个其他文件的第一行中的系数形成的等式的解。 下面是三个输入文件和答案文件的一个小例子:

2.2 Solving quadratic equations
As a reminder, quadratic equations can generally be solved using the formula: 作为提醒,通常可以使用以下公式求解二次方程

In any case, you must be aware of the possible limitations of the above formula and your code should be able to handle these correctly. For completeness your code must be able to handle a problem instance where a = 0.
在任何情况下,您必须了解上述公式的可能限制,并且您的代码应该能够正确处理这些限制。 为了完整性,您的代码必须能够处理a = 0的问题实例。
Tips:
•It is recommended that you verify that the solve_quadratic_equation() function is working correctly.I.e that it returns the correct solutions and error codes
•A logical way to approach this problem is to write the functionsolve_quadratic_equation() before writing solve_array_of_equations().This function can then be tested independently of the rest of your code.
•You can create new functions if needed.These must follow the good coding practices we have taught in the lectures and labs.Your submission must include the functions solve_quadratic_equation() and solve_array_of_equations().
•If you include comments in your code to explain workings then these must be inunderstandable English.
1.建议您验证solve_quadratic_equation()函数是否正常工作。 即它返回正确的解决方案和错误代码
2.解决此问题的一种合理方法是在编写solve_array_of_equations()之前编写函数solve_quadratic_equation()。 然后可以独立于其余代码测试此函数。
3.如果需要,您可以创建新功能。 这些必须遵循我们在讲座和实验室中教授的良好编码实践。 您的提交必须包含函数solve_quadratic_equation()和solve_array_of_equations()。
4.如果您在代码中包含注释以解释工作原理,那么这些注释必须是可理解的英语。

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 • Content
30 $