Writing and solving systems of non-linear equation

1 view (last 30 days)
Hi everybody!
I have learned how to use fsolve for systems of non-linear equations, but now I have a problem because the systems that I need to solve are very large ones (not very complicated though) so I would like to know if there is a way in MATLAB to write automatically the systems of equations from a general formula.
As an example, if I want to solve x + y - 4 = 0 & x*y - 4 = 0, I would just write:
function fcns = eqns(z)
fcns(1) = z(1) + z(2) - 4;
fcns(2) = z(1)*z(2) - 4;
end
However, if I want to solve a system whose equations are given by the formula, say, "z(k) = z(k)*z(k-p)" for k=1:100, I cannot write all equations explicitly in a short amount of time, so I would need some MATLAB functions to write them according to the formula. Is there a way to do it? Or, am I following the wrong approach for this kind of problem? Thank you very much!
  2 Comments
Andrew Newell
Andrew Newell on 21 Feb 2015
Sure, MATLAB has powerful tools for handling equations that can be expressed in terms of vectors and matrices. If you can give a better description of the equations you need to solve, we can help you with setting them up.
Lucio Milanese
Lucio Milanese on 22 Feb 2015
Thanks a lot! So, given an arbitrary N > 1, I would like to solve the system involving the unknowns a(1), a(2)... a(N), as given by the two equations in the attachment; the first equation is for p odd, and the second one for p even. p would go from 1 to N. Ideally I would like to be able to change just N on my final code and let MATLAB do the rest, i.d. create the equations according to the two formulas and solve them. Thanks again in advance!

Sign in to comment.

Answers (0)

Categories

Find more on Systems of Nonlinear Equations 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!