Solving non-linear (and linear) simultaneous equations with 'solve'
symsolvesimul.m can be easily adapted to solve more equations but as it stands it will solve 2 unknowns in 2 non-linear equations (can be linear too or a mixture).
At the MATLAB command-line prompt you run the 'symsolvesimul' m-file function with the correct vector arguments i.e. exponents, coefficients and constants in the equations in the appropriate order.
...typing 'help symsolvesimul' like so for detailed help at the
MATLAB command-line prompt:
>> help symsolvesimul
solves a system (a pair) of non-linear or linear equations or a mixture,
returning a n x 2 column solution vector for x and y. The first parameter
is a row vector (1 x 4) of exponents used in both equations. An exponent
of one for both terms indicates a linear equation. The second parameter
(1 x 6) is also a row vector of all the coefficients and the constants
used in both equations. The order of both vector's elements is critical.
Note that there may be more than 1 solution for x and y (sometimes
complex)
and that they are presented in a symbolic format at times rather than a
pure numeric format.
USAGE: symsolvesimul([ex1 ex2 ex3 ex4],[a b a1 b1 c1 c2])
a*x^ex1 + b*y^ex2 = c1 (1)
a1*x^ex3^2 + b1*y^ex4 = c2 (2)
i.e.
>> z=symsolvesimul([1 1 2 2],[2 3 4 5 8 24]);
2 x + 3 y = 8
2 2
4 x + 5 y = 24
>> z
z =
[ 1, 2]
[ 13/7, 10/7]
These are the solutions for the 2 equations i.e. x = 1, y=2,
x=13/7, y = 10/7.
----------------------------------------------------------------
The code I wrote for 'solvesimul' is attached. Save it to your working folder and run as above.
Cite As
Bruce Raine (2024). Solving non-linear (and linear) simultaneous equations with 'solve' (https://www.mathworks.com/matlabcentral/fileexchange/26293-solving-non-linear-and-linear-simultaneous-equations-with-solve), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |