简体   繁体   English

在MATLAB中求解非线性方程

[英]Solve nonlinear equation in matlab

I need to know how to solve a system of nonlinear equations but varying a parameter, so that every time you change that parameter will throw me the result of that system (need all results), I thought a for, which is changing the parameter, solve the equation and each result is stored in a spreadsheet, the problem is that as you can not solve the system and as a result I throw and nonsymbolic numerical values​​, they give you an example of the system that must be solved: 我需要知道如何求解非线性方程组但改变参数的方法,以便每次更改该参数都会抛出该系统的结果(需要所有结果),我认为这是改变参数的原因,求解方程式,每个结果都存储在电子表格中,问题是由于您无法求解系统,因此我抛出了非符号数值,它们为您提供了必须求解的系统示例:

0 = 125 +100 * cos (x) -25 * cos (a) -175 * cos (y)
0 = 100 * sin (x) -25 * sin (a) -175 * sin (y)

In the parameter to be changed is a and going to go keeping the corresponding values ​​of x and y in the spreadsheet. 在要更改的参数是a和要去保持的相应值xy在电子表格中。

You need to know how to solve non-linear equations. 您需要知道如何求解非线性方程。 That means picking a starting point, creating an incremental, iterative solution, and providing tolerances for stopping. 这意味着选择一个起点,创建一个增量的迭代解决方案,并为停止提供容忍度。 You need to know that not every non-linear equation has a solution. 您需要知道并非每个非线性方程都有一个解。 Your choice of starting point and iterative strategy might have a profound influence on whether or not you can find a solution and the efficiency of the process. 您对起点和迭代策略的选择可能会对您能否找到解决方案和过程效率产生深远影响。

What are you solving for here? 您在这里要解决什么? You have two equations; 您有两个方程式; I'll assume two unknowns (x, y). 我假设两个未知数(x,y)。

You need more basic information before you can use a tool like Matlab. 您需要更多基本信息,才能使用Matlab之类的工具。 It might encapsulate a lot of the details for you, but it won't make algorithm choices for you. 它可能为您封装了许多细节,但不会为您选择算法。 You still have to know something, especially about your system of equations. 您仍然必须了解一些知识,尤其是关于方程组的知识。

Start by reading stuff like this: 首先阅读如下内容:

http://www.physicsforums.com/archive/index.php/t-106606.html http://www.physicsforums.com/archive/index.php/t-106606.html

I'd recommend plotting your equations over a range of x and y. 我建议在x和y范围内绘制方程式。 You should know what the terrain looks like before you start. 开始之前,您应该知道地形的外观。 You're dealing with trig functions, so x and y vary from zero to 2π and then repeat. 您正在处理触发函数,因此x和y从零到2π变化,然后重复。 Plot a few periods of x and y and see what you get back. 画出x和y的几个周期,看看你得到了什么。

You can use Matlab's symbolic solver if you have the Symbolic toolbox... 如果您具有符号工具箱,则可以使用Matlab的符号求解器。

syms x y a
b(1)  = 100 * sin (x) -25 * sin (a) -175 * sin (y)
b(2)  = 125 +100 * cos (x) -25 * cos (a) -175 * cos (y)
z     = solve(b,x,y)
Xsoln = simplify(z.x)
Ysoln = simplify(z.y)

where Xsoln and Ysoln denote the solutions written in terms of the value of a . 其中XsolnYsoln表示用a的值表示的解。 You can then evaluate the solutions at multiple values of a by either doing 然后,您可以评估在多个值的解决方案, a由要么做

aval = 0.5; % or whatever value you want
subs(Xsoln,a,aval)

or by converting the solution to a function handle and evaluating it that way (this is the preferred approach if you need to evaluate at many points): 或通过将解决方案转换为函数句柄并以此方式进行评估(如果您需要在许多地方进行评估,则这是首选方法):

xf = matlabFunction(Xsoln)
xf(0.5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM