Transcript
In Smybolic tool box, one can use solve command to find solutions of equations. The solve command can be used to solve a single equation as well as simultaneous equations. Let's see how it works for a single equation first.
For example, if you have to solve this equation, 10 over X cubed +1 equal to 4 minus 2X. So the very first step is that you write, you rearrange your equation in such a way that you have the function of X on one side and zero on either side. Solving this equation is the same as solving the equation 10 over X cubed plus 1 minus 4 plus 2x equal to 0. So therefore we take f of X equal to this expression and now let's go to MATLAB.
First make x a symbolic variable, syms x. And then you can type the expression, F equal to 10 divided by x-cubed
plus 1 and then it is minus 4 plus 2 times X. And now you can command to solve it. Solve f - you don't really need to write X there because X is the only variable in the equation and it will solve for X by default. Okay, solve f. It is a good idea to give a name so you can refer to it later if needed. And it is solved. So you can see there that there are four solutions. All are complex numbers and looks like there are so many square roots are involved. Not easy to interpret.
If you like you can use pretty command to see how they look like .... yes there are so many square roots of course.
So if you want to convert the solution into Decimal format - what to do? We can use double command, double so if you say double u it will convert these numbers into so these are those 4 solutions here, easy to interpret now.
Let us solve the quadratic equation a x squared plus b x plus C equal to 0 symbolically. So let me type syms x a b and c. They are all symbolic variables now. And then I can type solve and in the bracket the expression which is
a times X squared plus b times X plus C. If I don't specify any variable to solve for, it will solve for X by default. Okay, let me also give it a name. Solution. Equal to that - so it will solve for X by default. Now, if I want to get certain solution for a, I should specify that variable a. So now it will solve it for a.
Let us solve ourselves the same equation again, but instead of having a, b, c and x, let's have some other alphabets
as variable. So let me have syms u, v, w and s and I'm going to solve the same equation replacing a, b, c with u, v, w and x by s. Okay so a is u, x is s, b is v, x is s and c is w.
Let us not specified for which variable the equation to be solved and see what what it does. It has solved for the variable W. So if there is no X in the equation, and if you don't specify for which variable to solve the equation, it solves for the last alphabetical variable which is W here.
Let us solve these two simultaneous equations for X and Y using solve command. So first thing is to make symbolic variables x and y. And then we need to rearrange these equations so that is is something equal to zero and something equal to 0. Let's call that something F1. So F1 is for first equation, 2 times y plus 3 x. Three times x.
Minus 4 that is equal to 0 - right? So that is F1. And similarly F2 is for second equation 5 times y minus 2 times x
minus 5 equal to 0. So that is F2. And then we can use solve command in the bracket F1, F2. And on the left-hand side in the square brackets, you can put x, y so that the solution is saved in the variables x and y. Okay. Solved now. You got x equal to 10 over 19 and y equal to 23 over 19.