MATLAB: How to implement circular reference in MATLAB

circular reference in matlab

I am trying to implement an Excel formula which has circular reference. I used a iterative method to implement this in MATLAB but it takes more iterations than excel. Any suggestions or better ideas to implement circular referencing in MATLAB. Thanks in advance!!

Best Answer

But this is not excel. circular references don't apply. You are no longer using a spreadsheet. Why does this matter? Really, you can use any tool you like, in any way that you want. But as long as you stay thinking about things in terms of a spreadsheet, you will solve your problems as if you were still using a spreadsheet, just making MATLAB work as if it was a spreadsheet. You will be able to solve far more sophisticated problems once you begin using MATLAB as it was designed to be used.
That it takes more iterations merely means you did probably a poor job of writing the iterative method. But since we don't see what you did, how can we solve that? Anyway, the number of iterations required by any solver will be problem and algorithm dependent, as well as dependent on the tolerances set by the user/programmer.
In general, it is never a good idea to write your own iterative solver anyway. Instead, use the many existing tools.
To solve for a root of one equation in one unknown, you have fzero. It will be efficient, but is designed to solve single variable problems.
With more unknowns, use a solver like fsolve, from the optimization toolbox.
If you have the symbolic toolbox, you can then use tools like solve or vpasolve.
Related Question