tags:

views:

142

answers:

4

Hi,

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

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

Please advise.

Thanks, Oz

+6  A: 

(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
+1  A: 

Perhaps this answer in SO is what you are after?

Noel Abrahams
A: 

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
A: 

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