Solving non-linear and linear simultaneous equations with fsolve
solvesimul.m can be easily adapted to solve more equations but as it stands it will solve 2 unknowns in 2 equations (1 non-linear and one linear).
To solve equations of this form...
a*x + b*y = A (1)
a1*x^2 + b1*y^2 = B (2)
...with fsolve (used by solvesimul.m) you need to rewrite them so that they equal zero.
so (1) and (2) become
a*x + b*y - A = 0 (1a)
a1*x^2 + b1*y^2 - B = 0 (2a)
then using a nested function approach (there are many other ways) you can solve some system of non-linear equations.
An example,
2*x + 3*y - 8 = 0
4*x^2 + 5*y^2 - 24 = 0
At the MATLAB command-line prompt you run the 'solvesimul' m-file function with the correct arguments
i.e. coefficients and constants in the equations in the appropriate order.
NB: please see final note below demo of the solvesimul command.
>> b=solvesimul(2,3,4,5,8,24);
1.0e-014 *
0
0.7105
>> b
b =
1.0000
2.0000
These are the solutions for the 2 equations i.e. x = 1, y=2.
----------------------------------------------------------------
The code I wrote for 'solvesimul' is attached. Save it to your working folder and run as above.
NB: you can use any one of the 3 fsolve formats by commenting out the other 2 you don't need in the attached m-file code.
Important:
You need to enter the args (i.e equation coefficients) to solvesimul.m in the order they appear in the equations with equation constants specified last in the correct order.
引用格式
Bruce Raine (2024). Solving non-linear and linear simultaneous equations with fsolve (https://www.mathworks.com/matlabcentral/fileexchange/26259-solving-non-linear-and-linear-simultaneous-equations-with-fsolve), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!