Solving systems of linear equations is an elementary topic in linear algebra, and is often encountered by high school and college students alike. MATLAB is ideally-suited to solve such simultaneous equations, provided the student is comfortable representing the equations as a matrix and using row reduction to determine the solution; these types of representations and operations are essential functions of MATLAB. However, MATLAB also has a more general equation-solving function that accepts symbolic statements of any system of equations, linear or not, and uses numerical methods if necessary. Use "solve" to quickly attempt a solution to simultaneous equations if you don't have a more specific strategy in mind.
- Skill level:
- Moderately Easy
Other People Are Reading
Assign the results of "solve" to a single variable to produce a structure array containing the solutions to the simultaneous equations:
solutions = solve('y=x^2','y=x')
There are two solutions to the equations used in this example, the points (0,0) and (1,1). The array contains the values of x and y as separate entries. To see the pairs of x and y results together, type:
Assign the results of "solve" to several variables to place the solution values directly into them:
[x,y] = solve('y=x^2','y=x')
The variables "x" and "y" now contain column vectors corresponding to the solutions. Place the variable names in alphabetical order in the on the left side of the assignment to make sure they receive the correct values.
Specify the variable names as extra arguments if you're using symbolic constants. For example,
[x,y] = solve('y=ax^2+bx+c','y=x','x','y')
These results are stored symbolically, allowing you to derive an expression for the solution(s) without specifying the values of the parameters.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for