Solving non-linear and linear simultaneous equations with fsolve

版本 1.1.0.0 (1.5 KB) 作者: Bruce Raine
solvesimul.m solves non-linear and linear simultaneous equations.
1.2K 次下载
更新时间 2010/1/27

查看许可证

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 版本兼容性
创建方式 R2009b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Updated title, summary and description fields.

1.0.0.0