sqrt in matlab This is a topic that many people are looking for. star-trek-voyager.net 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, star-trek-voyager.net would like to introduce to you Matlab Essentials – Sect 15 – Factorial, Square Roots, and nth Roots. Following along are instructions in the video below:
“And welcome to the section of the matlab tutor in this section. We re going going to concentrate on learning about factorials and square roots and how to kind of all that stuff in terms of matlab. So the easiest one to cover first something you probably won t use that much. But you might you might use it and that s the factorial how to take factorial of something you might think that you would do something like 5 factorial.
But it doesn t understand what that is so what you need to do to do a factorial is you need to literally type in factorial and pass. It as an argument past the number that you d like to take the factorial of so it literally does all the math 5 times 4 times 3 times 2 times 1. You get 120. So basically that s how you use the factorial command.
It s pretty straightforward now now that that s out of the way. I mean you know factorial is not something you ll use all that much but occasionally when you define sequences and series in calculus. You ll be using the factorial guy. So this is where you you where you get that information and if you forget you can always go here and type in factorial and hover over this guy.
And it ll tell you it s factorial you pass in or n. Is a scalar. Which is a number product on all the integers to 1 to n. And it gives you all the information about what exactly it s doing all right let me go and clear the screen that just took a few minutes.
Now what i d like to spend a little bit more time is how to take square roots. And also i m going to get into cube roots and in throats and things like that because those are things that you ll be using pretty frequently in matlab i thing there s no square root button anywhere on the screen here so what you need to remember is to do a square root you type in sq rt square root. So let s do something simple square root of 4 is 2. So matlab understands the square root operator the square root of 81 is going to give you 9.
If you put something in there. That s not a perfect square like square root of 80..
Let s say then it s just going to give you the decimal answer. And that s perfectly fine now what if you d like to express the square root. But not do it in terms of the square root function. Just as a reminder you can always go 81 raise to the power of 1 2.
Because as you all know when you raise something to the power of 1 2. It s exactly the same thing as taking the square root. So i can come up here and say. 9 to the power of 1 2.
And give me 3. So there s really two different ways to do square roots and it just depends on what you want to do using the sq rt command. May be a little bit more readable it just depends on exactly what you d like to do now. If you d like to take a root of of a number that s not a square root.
Maybe you want to take a cube root or a fourth root or a fifth root. There is a function for that and to demonstrate i want to show you how you might use the help system. If you happen to forget the syntax. So you just type this end type in nth root.
Ok. There is a power called function called enth root of real numbers. So it says you pass it two values the first one is a number the second one is whatever root you re trying to take and it should return the end through so let s type in in root. All right let s type in something we know i know i happen to know that the cubed root of 8.
Is is something that we can easily find so the first number you pass. It is the number you want to take the root of the second number you pass..
It is what root. It is so in this case. It s a third root or cube root. So we re going to go in hit enter.
And the answer is 2. The reason. It s 2 is because 2 times 2 times 2. Gives you 8 let me recall the last command another.
Nice cube root that i just happen to remember is the cube root of 27 which is 3 because 3 times 3 times. 3 is 27. So that s that s kind of nifty now also those of you this high up in math. Also know that you can do things like taking.
27 raised to the power of 1 3. Much like 1 2. Gave us a square root. Before raising something to the 1 3.
Power will give you a cube root. It s mathematically. The same thing okay so if you wanted to do something like 2 cube root of 8. You could do it that way so you can definitely handle all of this stuff by just raising things to fractional powers.
The only thing is it kind of sacrifices a little bit of readability. But you know you can totally do it if you want to use the square root command..
That s fine. If you want to use the in through command. That s totally fine too those are all available to you now. I d like to clear the screen really quickly and turn your attention to using the square roots functions.
When you have a basically a symbolic system going on here when you want to treat it perfectly a lot of times in algebra. You have the square root of 40 or something like that and you like you know you do the factor tree and you like to figure out what what that is equal to so obviously you can go square root of 40 right. And you ll get a number. I know the answer six point three two four six.
But if you wrap that in a symbol square root of 40 right so now it s doing square root of 40. But the answer basically is going into the symbol operator. So it s trying to keep everything exact and when you do that the symbolic math toolbox kicks in because we did this symbol operator here and the answer we get is not a decimal. We get something more perfect than that two times ten to the one half and if your heart if it s hard for you to read that i mean it s fine for me.
But if it s hard for you to read that you can type in pretty answer. And you ll see two times. Ten to the one half now you should know that anything to the one half is just a square root. So really what we have is two times.
The square root of 10 2. Times the square root of 10 and we all learn in algebra. How to factor. 40 and get all the common things and do all this by hand.
But you can use matlab to keep everything perfect as well so you know if you wanted to do something you know taking the square root of 40 is not a big deal. But what if you wanted to take the square root..
You know the perfect square root of you know something large like this let s see what matlab does ok. Very exact answer all right. It keeps everything as exact as it possibly can notice that this is a huge numerator divided by a huge denominator. If we want to convert it to a decimal.
Then this is going to be the square root of that large number then go ahead and clear the screen to declutter our screen. What if we wanted to do as another test symbolic representation of the square root of let s say 1050 something large. This is something that would take you a little while by hand to actually factor it all out select all the terms and figure out what it all is lab quickly tells you it s five times 42 to the power of 1 2. Which if you want to visualize that a little bit better.
That s five times 42 to the power of 1 2. So five times the square root of 42 is going to be that answer and if you require that in decimal form you can always just type double answer. It basically converts whatever you want to a decimal. So.
The answer is 32 point four zero three seven all right so that about covers everything i d like to cover in this section. We learned how to take the factorial of a number. We ve learned how to take the square root. We ve learned how to take the intrude and we ve learned how to use the symbolic math toolbox to manipulate square roots to simplify them into exact form.
Which is something that s pretty common actually you might need to do and then if we need to we can take these answers and convert them back to decimal as well so the nice thing about matlab is you have the flexibility of both you can work in decimals that s sort of the default mode. That s fine. If you want to deal in pure math. Terms.
You have that option as well just takes a little bit of time to understand how to talk to matlab to get it to do what you like it to do ” ..
Thank you for watching all the articles on the topic Matlab Essentials – Sect 15 – Factorial, Square Roots, and nth Roots. All shares of star-trek-voyager.net 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.