Manipulating Symbolic Expressions and Equations in MATLAB

matlab simplify
This is a topic that many people are looking for. is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, would like to introduce to you Manipulating Symbolic Expressions and Equations in MATLAB. Following along are instructions in the video below:

Something else thats fun to look at is manipulating, like doing symbolic manipulation. Manipu- I dont even know how to spell – lating symbols and stuff. Okay, so manipulating symbols is super fun. So say I have some equation, and its – I think we had these already, I dont know – X plus ooh, ooh I like this one. Lets see, because I want to… sym X&Y. Lets do Y is equal to 2 times X plus 3 squared divided by X squared plus 6X plus 9. Alright, 6 times X plus 9. And youre like, “Whoo-hoo! I got something! Amazing!” But like some like super secret party, we should be like, “Wait a second!” Because what this looks like is, this looks like 2 and then X plus 3 squared, and then on the bottom – like theres like a line – and then on the bottom, it looks like X squared plus 6X plus 9, and youre like, “But I know that that means that (let me put stuff here) on the top, thats still 2 times X plus 3 squared, but on the bottom, that, thats…um, whatever you call it thingy, and I can factor that. If I factor that, I get X plus 3 quantity squared. And if I do that, these cancel out these and I get 2.” Alright? So you should be excited, but MATLAB doesnt seem to understand that. So what I can do is I can actually say to simplify. And it goes, “2.” And youre like, “Yay! I knew that! Thats incredible! Whoot!” Now, if we do this in terms of an equation, I dont know if we get – Its always fun to see what thing will do whenever theyre equations versus when theyre expressions. So Im going to call this my funny equation, and it equals Y is equal to that. And now I want to simplify my funny equation. True. Thats weird. Oh, thats because Y was already defined. So I need to do this again. Thats why were constantly doing this. There we go. Whoo! Oh, thats beautiful! I like it! I was not expecting that! Okay, this is amazing. I dont know if you see what just happened. Okay, so whenever I use a little equation thingy, its like, “Oh, I can simplify that.” It simplifies to 2. But remember like the thing from algebra, where like I cant actually divide by zero? So even though these cancel out, its really important because whenever you cancel those out in algebra, youre supposed to make a little note, like out to the side that the domain does not include X equals negative 3, because if I put in X equals negative 3, then I get a zero on the bottom. And youre like, “They cancel out,” and Im like, “We have to go with the original equation,” and youre like, “Ahhh!” Okay, so anyway Im really excited about this. Whenever I asked it to simplify my funny equation, look what it said. It said, “Well, heres how it simplifies, because -” So this is my equation, and then whenever I ask it to simplify, it says, “X cannot equal to negative 3, because…because it cant.” So when I write it over here, it just like went 2. Like, this is like – so this up here is like like first semester algebra student, and this is like awesome-sauce algebra student whos like, “The answers 2, but I just want to let you know that X cant be equal of 3.” So this is like, this is like the kid whos like really, really excited about algebra, and this is the kid who just like wants to move on with life, because its like, “Oh my god, this is amazing!” Okay, so anyway, you can simplify the funny equation, and it actually tells you what X cannot be equal to, and this is why we love MATLAB – because it makes us happy. Okay, so earlier we had something where we said like, well, so we had symbols Y1, Y2, and X, and we said that Y1 was equal to X plus 1 quantity squared, and Y2 is equal to X squared plus 2X plus 1 and we tried to say, “Okay, well if – Im just retyping this – if Y1 is equal to Y2, then we say, “Yay!” (and cant spell) And otherwise, we say, “Oh noes!” And we ran this and it said, “Oh noes!” but thats stupid, because we know theyre the same thing, but it doesnt care. Its like, “No. Whatever.” Okay? So, we can actually do something with this now. Instead of comparing two different equations, we can compare the two simplified equations. And if we compare the two simplified equations, then it comes back with that. So it says, “Oh, I see it now. Theyre equal.” Remember when we tried to add 1 and Y1 and Y2 and it was like, “Crazy numbers!” And youre like, “But shouldnt it be simpler?” And the answer is yes. I can simplify Y1 plus Y2, and I get 2 times X plus 1 quantity squared. Which is pretty amazing. Its really hard not to get too excited. Wait, yes. Its hard not to get very, very excited, because its easy to get excited. So there. And so we did. Okay, so here are some good things to practice with. So Im going to do this. Im just going to copy and paste this, because I like it. Okay so heres some additional functions that you want to practice with. Whenever you try them, be sure that you try them on both symbolic expressions and on equations, because youre going to get very different – very different, sometimes kind of different – like this was like hardcore, awesome different, right? So you just never know. The best way to do it is just to practice it. You want to practice with paper and pencils sometimes just to get an idea, so you can play around with it a little bit, because sometimes, you know, algebra, depending on your state of mind, is it very mental. Its very like, if I have a pencil in my hand, I can do algebra kind of thing. So this is really something you want to practice with. So remember, learning is like something you have to do on purpose, so pause the computer, try all these things out, try them on expressions and equations, and Ill see you in a sec. Alright! So well pretend that happened. Alrighty, so what do each of of these functions do? Alright, so lets try just expand, and for all of these Im probably gonna have to do a little CLC clear. So this is gonna be for

expand. Start with CLC clear, syms, I dont know. I dont know what Im doing. So, expand. What is it gonna do? I dont know, well find out. Okay, so well say Y is equal to X plus 3 quantity squared and then expand Y and see what I get. Okay, thats kind of what I expected. I expected expand to like multiply something out, so thats not a problem. Lets do it again. I dont know why I did X, Y, and Z. So lets say I have an equation which is Y is equal to X X plus 3 quantity squared, and I want to expand the equation. Why are you yelling at me? Okay, kind of did the same thing. Um, let me try it, so just to be kind of fun, lets – I know. There. Okay, so it expanded both sides of the equation, whereas – so thats kind of cool. Because if I tried to do that up here, it would be like, “I dont think so.” So thats another kind of a feature, I guess, of the…whatever you call it – equation versus expression – is that the left side doesnt have to be perfect. It can be all kinds of weird. So there, it expanded both sides. Basically means it multiplied it out. Alright, factor: I can probably again guess what thats going to do. So lets try factor. CLC clear. Syms, X,Y, and Z. I dont know why I keep doing X, Y and Z; it just makes me happy. So Im going to think of something Im going to have to factor out. So, lets go Y equals X cubed plus 3X squared plus 3X plus 1. And Im going to say, “I want you to factor Y.” And its gonna be like, “Awesome!” Yay, I knew that was gonna happen, because Im kind of awesome at algebra. Just not at, you know, adding and subtracting. CLC clear. So lets do this as an equation. I really need X,Y and Z. I just keep doing it. So my equation is X equals that, and Im going to factor in my equation, and it just does that. So again, on the left, I could actually say X squared minus 1, and then we go X plus 1, X minus 1 on the left, and then factor it out on the right. So thats kind of neat. And again, I wouldnt be able to say X squared minus 1 on the left up here, because its like, “You cant do that with equations.” But I can do it symbolically here. So thats neat. Alright, what am I gonna do next? Numden. Numden numden. “Numden” sounds funny. Huh, numden numden numden. Ooooh.. Numerator and denominator. But its kind of a boring name for a function. Numden. Alright, so numden, numden numden. Its like a terrible name for a child. “This is my little one, Numden.” Alright, so anyway, numden. Im gonna stop now. Okay, so lets say syms X and Y, Y is equal to…well go X plus 3 divided by X plus 6, then I go (numden…chuckles) okay, I had to say it that time. Y. And it just says X plus 3, and youre like, “Thats stupid. It said it was going to give me both.” So (do NOT say it) So if you look at the usage, I actually have to do both. Now this might kind of be something you remember, like if you remember doing mesh grid, is if you didnt ask for two outputs, you didnt get two outputs; you only got the first one, and MATLAB always does that on purpose. By default, if you dont ask for any outputs, it only gives you the first one. So I could say this is the high one, and this is the low one. Noon in London. So the high one is the X plus 3, and the minus one is X plus 6. Connaître? Lets see what this does with an equation. My equation: Y equals that. Can I numden my equation? No! It says I have a mooped mixer. I dont even know what that means. Basically, its telling me no, and that kind of makes sense, because how do you have a numerator and a denominator of an equation? Thats just a little strange, so cant do this one. Alright, Im cool with that. Im strangely comfortable with it. Alright, now Im going to collect. So what do I do with collect? Okay… It has two inputs, regards each element of the symbolic matrix s as a polynomial in terms of V and rewrites it in terms of powers of V. Okay that makes sense. Maybe it makes sense? So Im going to CLC clear it, syms, would be Y and X and Z. Now I want them all. Alright, so lets do something in terms of X,Y, and Z and see what happens. So lets do X plus 3 squared plus X plus Z squared. I dont know what this is doing. Im just trying. When I do collect Y, but collect it by Xes. Alright, Im gonna see what this says. Okay so lets see what we got and see if it makes sense. So, if I multiply this out, I would get X squared plus 6X plus 9 plus X squared plus 2XZ plus Z squared, so basically I said, “I want you to collect Y, the equation Y, and I want you to collect the X terms.” And its like, “Okay.” So basically, Im gonna get 2X squared and then what else has an X? So basically Im going to say, Im going to factor the X out of here and here, so if I factor the X out, I should get 6 plus 2Z, and then I get Z squared plus 9 left over, and thats exactly what I got, just in a different order. Its 2Z plus 6. So basically Im going to collect everything with terms of coefficients of X. So try this one. Try to do…so thats this one. Alright. So then, lets see. If you didnt get anything on this initially, now try it. Like pause the video, see how far you can get, and see if you can anticipate what this outputs going to be. Okay, so Im going to collect X. If Im going to collect the terms in terms of Z, if I look at the original, the only things that have Zs, is it starts off as Z squared, then I have a 2x times Z, and then everything else is a non Z term. So basically I have a 1 in front of the Z squared coefficient, a 2X in front of Z coefficient, and an X,

2X squared (come on) plus 6X plus 9 term in front of the…so what this really is is times a Z to the 0, right? So this is Z to the first, so I collect the Z squared terms, the Z to the first terms, and the Z to the 0 terms. And they might be in a different order, and they were simplified a little bit, but theyre still there. Thats actually interesting to see how that was simplified, so if I dont like the way that looks, um…I wonder if I could expand the collection. Yeah, there we go. So that was kind of neat. I can expand that. But now it doesnt look like its in terms of Z anymore. Actually, like…oh yeah, it does, just not very good looking. I like that one better. I still think that looks better, so Ill stick with that. Alright, collect. Um, Im not entirely sure what collect is going to do on an equation, so lets discover. CLC clear. Syms. (chuckles) I am never going to spell that right. Alright, so say Ive got my equation, and equal to that, with the double equals, and Im going to collect equation one, Im going to collect the Ys. Well, thats weird. Well, no actually, that makes sense. Let me collect the Xs. Okay, let me collect the Zs. Okay, so what if I make it a little different; what if I say Z is Y plus X? What if I collect the Xs? Okay, its just gonna collect them per side, it looks like. So if I do an X plus 2 squared here plus X plus C (Im just doing both sides). So it looks like what its going to do is, its going to collect the Xs on both sides. Just so that you could do…So this would actually be useful if you ever get to the point in math when youre doing like a coefficient comparison, because thats going to come up… I think you do it sometime whenever you are doing partial fraction decomposition. Not that this isnt probably totally capable of doing partial fraction decomposition, but a lot of times what youll do is youll equate the coefficient of the X square and equate the coefficient of the X and equate the coefficient of constant. So this would be a way of collecting the X squareds and the Xs and the constants, so I could say, “Oh, well that must mean that 5 is equal to 2Z plus 6,” or, “Since this is a 1, 1 must equal 2.” Well, that doesnt work, because, you know…yeah. But collect would be a way, if youre going to try to equate coefficients on two sides of an equation, I could totally see how that would be useful. Alright so we did that. Simplify weve already kind of talked about. Simple – its too simple. I think simple is kind of fun. I forgot what it did, but I remember seeing it a minute ago and being like, “This is amazing, we should talk about this.” CLC clear, syms, XYZ. Simple, lets just google it. Okay. Searches for the simplest form of an expression. Awww, thats amazing. Thats very nice of it. So lets try something silly. So Y is equal to X plus 3 cubed plus 2, x plus 3 plus…cubed. I dont know what Im doing. Simple! Ooooh! How can you not love that? Look, look! Look it just did a whole bunch of stuff! I dont know why, but it did. And a doc for my minute…come here, command window. Whoa! Okay. Oh, thats sad. Okay. But this is amazing, because look – its like a whole bunch of different ways to simplify it. I dont really know why it would, but it combines sincos, lane, factor…So factor – that was kind of cool. Expand, combine… Anyway, so which one does it like? So basically what it does is it does all these different ones, and then at the bottom its like, “Here you go, I like this one the best.” And youre like, “Hey, thanks, that was great.” Anyway thats kind of fun. Too bad theyre going to take it out in a future release. But anyway, simple Lets just do this again right quick with an equation. And the equation will be fun because well do something on both sides. Oh, I dont know what Im doing. Oh, there we go. So what that one did is it put all of the… so this is the first one that weve seen thats going to move things from one side of the equation to the other. So on the left I had a Y plus 3, X squared 3X plus 9, and all of that went to the other side. So I wonder if it would just – because it said to use simplify instead. It gave me the same answer, but simple is just kind of cool because its showing me all the different answers, so Im not really sure. Im sure theres a reason why theyre getting rid of it, but thats just something thats kind of cool to to look at. Now something I do want to mention is that, like an “Onoes!” Because we use something called factor, right? So when I had – you know, whatever – this thing. And I had…okay… Okay, we have something called factor, and it factored it out, or expanded it out, or whatever. Well factor I guess could do – let me give you something thats obvious to factor: X cubed plus 3, X squared plus 3, X plus 1, and we factored it. Okay, were like, “Factor.” But you might say, “But didnt factor used to do something else?” And the answer is yes. So if you, you might remember the if we add factor to like the number 23 – not 23, how about 27? It factored it and it said it has three factors in there – 3, 3, and 3, and if we factored, um….you know, I cant think of anything thats not like a perfect something. How about 24? 2, 2, 2, and 3. And it has it to factor. Basically what these are called are overloaded functions, which means that if Im just doing something normal, factor does what you expect it to do, but if its doing something with symbols, then factor is doing something super, super crazy. And so thats always something you want to kind of keep an eye out for. If you go help factor, it will actually show you that it has an overloaded method in the symbol. And that means that factor does different things in different contexts, so thats definitely something you want to keep in mind.

MATLAB, expand, factor, symbolic algebra
Thank you for watching all the articles on the topic Manipulating Symbolic Expressions and Equations in MATLAB. All shares of are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.

Leave a Comment