Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I solve this three variable equation with C#?

Tags:

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 = ?

Problem is, this is literally the first two days of class and he expects us to make something like this.

Any help?

like image 245
Sergi Avatar asked Nov 28 '22 23:11

Sergi


2 Answers

Since this is homework, I'll provide guidance, but not a complete answer...

My suggestion: Write this out on paper. How would you approach this on paper? Once you figure out the basic logic required, translating that into C# should be fairly straightforward.

You'll need to assign a variable for each portion of the equation (not just x/y/z, but also the coefficients), and just step through it in code using the same steps you do on paper.

like image 109
Reed Copsey Avatar answered Dec 11 '22 06:12

Reed Copsey


If you know some maths, you can solve systems of equations using a matrix library (or roll your own).

like image 21
Pontus Gagge Avatar answered Dec 11 '22 05:12

Pontus Gagge