1

I need to represent these mathematical equations in code and to solve them:

2x = 3y
3y = 4z
2x + 3y + 4z = 1

Please advise.

Avada Kedavra
  • 8,523
  • 5
  • 32
  • 48
Oz Radiano
  • 779
  • 2
  • 11
  • 30
  • 2
    What _exactly_ are you struggling with? Also, if this is homework, please tag it as such. – Oded Oct 08 '10 at 15:49
  • 1
    as Oded said, it's not quite clear what you need. Generally speaking on here, more information is better than too little. – Dave Oct 08 '10 at 15:50

4 Answers4

6

(I suspect this is homework, so I will give you some clues as to how to proceed...)

Think about how you would solve these equations on paper.

The same steps can be written into your software. Each equation has a variable and a coefficient, so you will most likely want to represent the coefficient with a variable in your program, and "solve" the equations using the same techniques you would by hand.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
1

Perhaps this answer in SO is what you are after?

Community
  • 1
  • 1
0

Here is a complete, documented/tutorial C# program to solve sets of linear equations: http://www.codeproject.com/KB/cs/LinearEquationsSystemSoln.aspx

By the way, C# isn't really the language for this. MATLAB or Python/scipy would have built-in solvers. See things like this: http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html

Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
0

This sound like a simple case a linear algebra. Throw the equations into an M x N matrix where M is the number of coefficients + 1 and N is the number of equations.

Babak Naffas
  • 12,395
  • 3
  • 34
  • 49