Friday, July 31, 2009

Structured Program in C - Simultaneous Equations?

I'm really struggling to write this C program, with very little time left to write it. Handing it over to you for help





Write a structured program to find the solution of a set of three simultaneous equations with coefficients input by the user in an input file. Complete the pseudo code below and use the following simultaneous equations to verify that the code works.





Pseudo code:


1....


2.....


3. Begin while loop to iterate solution of x, y and z


4. Evaluate new values for x, y and z (retaining a record of the old values)


5. Evaluate the sum of the absolute differences between the old and new values


6. If this sum of differences is less than a tolerence - say 0.0001, then bail out of loop, otherwise go back to step 4.


7....


8....





Simultaneous equations


11x + 2y + z = 15


x + 10y + 2z = 16


2x + 3y - 8z = 1





Rewritten:


Xn+1 = 1/11(15 - 2Yn - Zn)


Yn+1 = 1/10(16 - Xn+1 - 2Zn)


Zn+1 = 1/8(-1 + 2Xn+1 + 3Yn+1)





Additional : How would this code be generalized to solve N simultaneous equation

Structured Program in C - Simultaneous Equations?
Here's an unstructured method in some form of BASIC. It should help you with an approach without handing you your assignment on a plate.





for x=-100 to 100


for y=-100 to 100


for z=-100 to 100


if abs(11x+2y+z-15)%26lt;=0.0001 then


if abs(x+10y+2z-16)%26lt;=0.0001 then


if abs(2x+3y-8z-1)%26lt;=0.0001 then


goto jumppoint


endif


endif


endif


next z


next y


next x


print "no answer found"


end


.jumppoint


print "x=",x," y=",y," z=",z


No comments:

Post a Comment