简体   繁体   中英

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.

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).

You need more basic information before you can use a tool like 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

I'd recommend plotting your equations over a range of x and 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. Plot a few periods of x and y and see what you get back.

You can use Matlab's symbolic solver if you have the Symbolic toolbox...

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 . You can then evaluate the solutions at multiple values of a by either doing

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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