Variable not updating with each iteration
Show older comments
I have many different equations with variables and coefficients running through a for loop and at the end, are sorted into [A] [b] and [x] matrices which are used to perform matrix math to solve for unknown x's before the loop starts over. [A] consists of the coefficients, [b] consists of numbers changing with the increase of each time step, and [x] consists of variables that are supposed to be updating. The problem is that the [x] variables aren't updating, it just gives me the original x's each time. What am I doing wrong? I would post the code here but it is pretty lengthy.
8 Comments
John D'Errico
on 19 Jun 2016
Ok, so you have a bug somewhere. You can't really tell us where. You won't let us see your code, which will probably be convoluted, from your description.
Is there any way we can guess what you are doing wrong? Let me see, that darn crystal ball is just so often on the fritz, as it is today. And my MATLAB tarot cards are short circuiting, as I spilled coffee on them. All that is left are the tea leaves. They tell me...
... that you need to learn to use the debugger. See what is happening as you follow the flow of your code. If you expect something to happen, and it does not, then it will be clear form the debugger.
Or, you can wait for my crystal ball to come back from the repair shop. They are just so slow to get parts though.
zephyr21
on 19 Jun 2016
John D'Errico
on 19 Jun 2016
You step through the code, one line at a time if necessary, though you can set breakpoints where you expect to see something, and then jump to the next breakpoint.
You watch the values of the variables where something is supposed to be happening. I use the debugger frequently enough even when no error is generated.
Posting the code, if it is as complex as you seem to indicate will do little. Especially since you have not clearly explained exactly what you are trying to do or solve. This is a case where you have the most incentive, and the ability to solve the problem.
Walter Roberson
on 19 Jun 2016
Make sure the code is well commented. When people see long code that is poorly commented or is uncommented, they tend to move on to better-written questions.
zephyr21
on 19 Jun 2016
Walter Roberson
on 19 Jun 2016
Post it. If it is well commented, I might glance at it and see if there is anything obvious. If it is not well commented then I will not spend any time trying to figure it out.
zephyr21
on 19 Jun 2016
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!