Julia Tutorial - 3. Complex and Rational Numbers
Key Takeaways
This video tutorial covers complex and rational numbers in the Julia programming language, demonstrating how to create and manipulate these numbers using various functions and operators.
Full Transcript
hello and welcome to code Basics coding tutorial today we are covering complex and rational numbers in Julia programming language we are doing little different thing today uh until now we were using uh Julia terminal like this one but today we will uh use the Julia box.org which is basically a python Julia notebook uh what this does is it allows you to do the same thing that you are able to do here but within a browser so go to juliab box.org website and from here click on new and you can use the latest version uh there is this version which is still in development so I'm going to use Julia 0.4.3 this is going to open a Julia notebook and I will show you what a notebook means so when you come here here you can type in your Julia commands for example I'll just do simple math and to get the result like let's compare this side by side so here when you do 2 + 3 and enter it gives you the result here you can do the same thing but you have to hit Alt Enter that's a key stroke so you see it gave the same result or you can uh click on this button which is a execute the cell so they both are same uh depends which one is convenient for you okay now let's start talking about uh complex number uh I will first delete all these cells so that it is uh clear so if you have uh studied complex number in your math class during your school days you might recall that complex number is a number that can be expressed in the form of a + b i where A and B are real numbers and I is an imaginary unit the value of I is square otk of min-1 let's first create our first complex number the way you do it is by doing this so you will say x = 3 + 4 I Alt Enter and when I do type of X it will tell me it's a complex number here three is a real unit and four is an imaginary unit and to get that you can use this inbuilt function called real and when you do real X Alt Enter it says three same way to get imaginary number you can say image X and it gives you the imaginary unit so this imaginary unit is here whatever is with I am and the real number is three now one question you might have is why don't we do why didn't Julia creators decided to do in a way that we do it in our standard mathematics class where which is is use I so like 3 + 4 i instead of I I am well the reason is I is such a common variable name that we use in our for Loops all the time so if you have a variable called I like this and if you do let's say 2 + 3 I imagine what's going to happen if you remember Julia support uh mathematical coefficient which means to multiply 3 with I you don't need to write multiplication in between you can just write like this and it will multiply so what it did here is 3 into 5 which is 15 + 2 17 that's the main reason why Julia creators decided not to use I now if you have a variable with a name I am then it's going to do the same thing but I is not a very common variable name that's why they thought we'll just do I am which really means imaginary the first two letters of word imaginary okay let's go through couple of more functions the third function that we want to cover is angle when you say angle X it gives you the angle created by the complex number in the complex plane okay fourth function is is absolute it gives you the absolute value of a complex number if you remember the formula of uh an absolute for the absolute value of a complex number then it is the square of real number plus square of imaginary number and you just take the square root of the entire thing so here it is three and 4 so you will do 3 S + 4 sare which is really 9 + 16 which is 25 and the square root of 25 is 5 if you want to look at the list of functions all the list of functions that you can use on complex number go to Julia l.org website this one right here so if you go to Julia Lang do juliia l.org and if you go to documentation here you should be able to find uh all the the entire list of functions so these are the operators and you will find all the functions at the bottom check all check this list there a whole uh long list of all kind of functions so we're not going to cover all of these we just covered a few basic of them okay next thing we want to talk about is uh the standard arithmetic operations with complex numbers as like any other number you can do a standard arithmetic operation you can do something like this and it's going to multiply it you can also add two numbers so this is my first complex number and I want to add with this number and you can guess what will be the result you can also do multiplication so 1 + 2 I into 3 + 4 I uh let's see call has no matter matching this okay let's see what happened here maybe you need a multiplication operator okay so we forgot to write multiplication operator that's why I gave this error if you uh recall the formula of this then uh you should be able to figure out why it gave you this result you can also do division again the same number let's do the division you can do square of a complex number and for that you will use this particular character okay uh what if I have two real numbers and from that I want to create generator complex number uh if you have two real numbers like this you want to generate a complex number you can use a function complex so you complex a comma B A the first parameter in this function is the real unit the second parameter is the imaginary unit so it is giving you 2 + 5 I okay that was all about complex numbers next topic we want to cover is rational number again if we go back to our high school days and try to recall the definition of irrational number then that number is any number that can be expressed as fraction P / Q of two integers for example if you do y = 2 SL this is how you write a rational number in Julia using two slashes okay so it says 2/ three and if you do type of Y it is telling me that it is a rational number contrast this thing with a normal Division if you have normal division it gives you a float result so here this one is a float this one is a rational number and this is an exact ratio sometimes in decimal or the some ratios cannot be represented in decimal accurately for example this one even 1X 3 when you say this is not the correct answer there are like threes all the way until Infinity that's why you have to use rational numbers sometimes as is without converting them to a deal number so here I will use just one/ 3 okay now uh if you want to figure out the numerator and denominator of this uh complex number so the way you do it is an new M function will return you numerator of a rational number so here numerator is four and denominator is five denominator you can figure out using function DN all these are built-in functions available in Julia okay how about we go over some operators now when you do 2/ this 3 equal to double equal to is a comparison operator and let's do this and see what happens H interesting here it is saying these both of these numbers are true why is that okay let's figure out so if I do 4/ 6 here you see what just happened uh whenever you are creating a rational number it will uh give you the fraction it will do all the normalization and it will give you the basic number so here 4 by 6 is 2x3 similarly if you do 8 SL SL 12 this is also 2x3 so if you know the logic of rational numbers uh here what happened is it was 8 and 12 so 8 can be so 2 into 4 is 8 and 3 into 4 is 12 so you just uh cut down the four and you get 2 / by three okay what if I want to convert this number which is a rational number into a float number well there is an easy operator there is an easy a function called float you do 2 3 float it will yield the float number this is how you do a conversion from a rational number to a float number okay that was all about complex and real numbers thanks for watching
Original Description
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Playlist
Uploads from codebasics · codebasics · 21 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
▶
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
Related Reads
📰
📰
📰
📰
Sora by OpenAI MOD APK v1.0 (Unlimited Video Generation & Pro Unlocked)
Dev.to AI
5 Illustration Prompts for Exploring Distinct Visual Styles With AI
Medium · AI
How to Generate 30 Days of Faceless Short Videos Using AI
Medium · AI
AI Images Look Perfect. Until You Notice These 7 Details.
Medium · AI
🎓
Tutor Explanation
DeepCamp AI