How can I solve these three variable equations using C #?

My teacher asked me to create a program to solve something like:

2x plus 7y plus 2z = 76 6x plus 1y plus 4z = 26 8x plus 2y plus 18z = 1 x = ? y = ? z = ? 

The problem is that this is literally the first two days of the class, and he expects us to do something like this.

Any help?

+4
source share
6 answers

Since this is homework, I will give directions, but not a complete answer ...

My suggestion: write this on paper. How do you approach this on paper? Once you have identified the basic logic, translating that into C # should be fairly simple.

You need to assign a variable to each part of the equation (not just x / y / z, but also the coefficients), and just go to it in the code using the same steps as on paper.

+8
source

If you know the math, you can solve the equation system using the matrix library (or collapse it yourself).

+7
source

I would suggest that you come up with an algorithm in pseudocode before touching any C #.

At least if you have identified the steps you need to complete, the task will simply become one of learning C # syntax to complete the steps.

It looks like you need a math tutorial;)

+4
source

Try to solve this yourself on paper, but pay attention to what steps you are following and try to determine that you are using Algorithm.

Once you have developed your algorithm, try writing some C # that do the same.

+3
source

Another tip that can help you is that you need to save the equation in some data structure and then (re) follow some steps that change the data structure. The question is, what kind of data structure can represent this kind of data well? If you focus only on coefficients (since each row always has the same variable), you can simply write:

 2 7 2 76 6 1 4 26 8 2 18 1 

In addition, you can assume that all operations are + , because "minus 7y" actually means "plus (-7) y". This is like a 2D array, so when programming in C # you can start by representing the equations as int[,] . After you load the data into this data structure, you just need to write a method that performs the operation you performed on paper (in general).

+3
source

As soon as you get the coefficients represented by the matrix (2-dimensional array), try googling "RREF" (a reduced form of line level lines). This is a matrix operation that you want to implement in your program to solve a system of equations. Good luck.

+1
source

Source: https://habr.com/ru/post/1301602/


All Articles