eq1 = 
Why are these interations not working?
Show older comments
Hi there,
I am trying to perform simple iterations to solve a pair of simultaneous equations. However, I am not getting the correct results when using a for loop. My code looks like this:
syms x y
eq1 = 2*x + y == 16
eq2 = 5*y - x == 25
x1 = 16/2;
y1 = 25/5;
fyx = -1/2;
fxy = 1/5;
x2 = fyx*y1
y2 = fxy*x1
x3 = fyx*y2
y3 = fxy*x2
x4 = fyx*y3
y4 = fxy*x3
for i = 1:4
x2 = fyx*y1
y2 = fxy*x1;
y1 = x2;
x1 = y2;
end
Outside the loop the iterations are giving the correct answer. That is x2, x3, x4 = -2.50, -0.80, 0.250 respectively, and y2, y3, y4, 1.69, -0.50, -0.160 repectively.
But in the loop for x2, x3, x4 is 2.50, 1.250, -0.6250...
Am I doing something incorrect in my for loop to get these incorrect results?
Many thanks in adavance!
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!