Making mathematical operations in MatLab® is generally very useful with various useful commands. Here, we explain another useful command to solve systems of equations in Matlab®. This command is the ‘solve()’ command.
YOU CAN LEARN MatLab® IN MECHANICAL BASE; Click And Start To Learn MatLab®!
You can solve systems of equations that have more than one variable. Take a look at the examples below to understand the syntax and the use of the ‘solve()’ command below. All the codes below are executed in the Matlab® command window. So you can try it in your Matlab® software.
How To Use ‘solve()’ Command In Matlab®?
>> syms a b x = solve(a^2+2*a*b+b==6,a^2-4*a+3==0) x = struct with fields: a: [2×1 sym] b: [2×1 sym] >> x.a ans = 1 3 >> x.b ans = 5/3 -3/7 >>
As you see above, we firstly defined two symbolic variables that do not have any values, with the syms command. And we typed our equations by using these two variables ‘a’ and ‘b’, inside the ‘solve()’ command. Put commas between the equations and assign the ‘solve()’ command to a variable like above ‘x’.
Use the logical operators in equations.
When you execute the code, the answer will be given as vectors that include the number of elements equals several solutions of each variable.
If you type ‘x.a’ or ‘x.b’ the equation variable with the symbolic variable to see solutions like above. You can see that there are two solutions for both ‘a’ and ‘b’ variables.
>> syms a b c x = solve(a*sin(b)==c,a) x = c/sin(b) >>
Also, you can find out the mathematical expressions of unknown variables with the ‘solve()’ command like above. For example, we created an equation with three variables and we want to find the values of ‘a’ which is defined after the equation inside the ‘solve()’ command.
And the value of ‘a’ is found in the ‘ans’ in terms of other variables in the equation.
The ‘solve()’ command is one of the most useful mathematical commands in Matlab® to find out the algebraic solutions of systems of equations.
Do not forget to leave your comments and questions below about the use of the ‘solve()’ command in Matlab® below.
If you want further coding examples about the ‘solve()’ command in Matlab®, inform us in the comments.
This article is prepared for completely educative and informative purposes. Images used courtesy of Matlab®
Your precious feedbacks are very important to us.