Julia Tutorial - 3. Complex and Rational Numbers

codebasics · Beginner ·🛠️ AI Tools & Apps ·10y ago

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
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from codebasics · codebasics · 21 of 60

1 Python Tutorial - 1. Install python on windows
Python Tutorial - 1. Install python on windows
codebasics
2 Python Tutorial - 2. Variables
Python Tutorial - 2. Variables
codebasics
3 Python Tutorial - 3. Numbers
Python Tutorial - 3. Numbers
codebasics
4 Python Tutorial - 4. Strings
Python Tutorial - 4. Strings
codebasics
5 Python Tutorial - 5. Lists
Python Tutorial - 5. Lists
codebasics
6 Python Tutorial - 6. Install PyCharm on Windows
Python Tutorial - 6. Install PyCharm on Windows
codebasics
7 PyCharm Tutorial - 7. Debug python code using PyCharm
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
8 Python Tutorial -  8. If Statement
Python Tutorial - 8. If Statement
codebasics
9 Python Tutorial - 9. For loop
Python Tutorial - 9. For loop
codebasics
10 Python Tutorial -  10. Functions
Python Tutorial - 10. Functions
codebasics
11 Python Tutorial - 11. Dictionaries and Tuples
Python Tutorial - 11. Dictionaries and Tuples
codebasics
12 Python Tutorial - 12. Modules
Python Tutorial - 12. Modules
codebasics
13 Python Tutorial - 13. Reading/Writing Files
Python Tutorial - 13. Reading/Writing Files
codebasics
14 How to install Julia on Windows
How to install Julia on Windows
codebasics
15 Python Tutorial - 14. Working With JSON
Python Tutorial - 14. Working With JSON
codebasics
16 Julia Tutorial - 1. Variables
Julia Tutorial - 1. Variables
codebasics
17 Julia Tutorial - 2. Numbers
Julia Tutorial - 2. Numbers
codebasics
18 Python Tutorial - 15. if __name__ == "__main__"
Python Tutorial - 15. if __name__ == "__main__"
codebasics
19 Julia Tutorial - Why Should I Learn Julia Programming Language
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
20 Python Tutorial  - 16. Exception Handling
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
22 Julia Tutorial - 4. Strings
Julia Tutorial - 4. Strings
codebasics
23 Python Tutorial -  17. Class and Objects
Python Tutorial - 17. Class and Objects
codebasics
24 Julia Tutorial - 5. Functions
Julia Tutorial - 5. Functions
codebasics
25 Julia Tutorial - 6. If Statement and Ternary Operator
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
26 Julia Tutorial - 7. For While Loop
Julia Tutorial - 7. For While Loop
codebasics
27 Python Tutorial  - 18. Inheritance
Python Tutorial - 18. Inheritance
codebasics
28 Julia Tutorial - 8. begin and (;) Compound Expressions
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
29 Python Tutorial - 12.1 - Install Python Module (using pip)
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
30 Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
31 Julia Tutorial - 10. Exception Handling
Julia Tutorial - 10. Exception Handling
codebasics
32 Python Tutorial  - 19. Multiple Inheritance
Python Tutorial - 19. Multiple Inheritance
codebasics
33 Python Tutorial - 20. Raise Exception And Finally
Python Tutorial - 20. Raise Exception And Finally
codebasics
34 Python Tutorial - 21. Iterators
Python Tutorial - 21. Iterators
codebasics
35 Python Tutorial - 22. Generators
Python Tutorial - 22. Generators
codebasics
36 Python Tutorial - 23. List Set Dict Comprehensions
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
37 Python Tutorial - 24. Sets and Frozen Sets
Python Tutorial - 24. Sets and Frozen Sets
codebasics
38 Python Tutorial - 25. Command line argument processing using argparse
Python Tutorial - 25. Command line argument processing using argparse
codebasics
39 Debugging Tips - What is bug and debugging?
Debugging Tips - What is bug and debugging?
codebasics
40 Debugging Tips - Conditional Breakpoint
Debugging Tips - Conditional Breakpoint
codebasics
41 Debugging Tips - Watches and Call Stack
Debugging Tips - Watches and Call Stack
codebasics
42 Python Tutorial - 26. Multithreading - Introduction
Python Tutorial - 26. Multithreading - Introduction
codebasics
43 Git Tutorial 3:  How To Install Git
Git Tutorial 3: How To Install Git
codebasics
44 Git Tutorial 1: What is git / What is version control system?
Git Tutorial 1: What is git / What is version control system?
codebasics
45 Git Tutorial 2 : What is Github? | github tutorial
Git Tutorial 2 : What is Github? | github tutorial
codebasics
46 Git Tutorial 4: Basic Commands: add, commit, push
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
47 Git Tutorial 5: Undoing/Reverting/Resetting code changes
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
48 Git Tutorial 6: Branches (Create, Merge, Delete a branch)
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
49 Git Github Tutorial 10: What is Pull Request?
Git Github Tutorial 10: What is Pull Request?
codebasics
50 Git Tutorial 7: What is HEAD?
Git Tutorial 7: What is HEAD?
codebasics
51 Git Tutorial 9: Diff and Merge using meld
Git Tutorial 9: Diff and Merge using meld
codebasics
52 Difference between Multiprocessing and Multithreading
Difference between Multiprocessing and Multithreading
codebasics
53 Python Tutorial - 27. Multiprocessing Introduction
Python Tutorial - 27. Multiprocessing Introduction
codebasics
54 Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
55 Git Tutorial 8 - .gitignore file
Git Tutorial 8 - .gitignore file
codebasics
56 Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
57 Python Tutorial - 30. Multiprocessing Lock
Python Tutorial - 30. Multiprocessing Lock
codebasics
58 Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
59 What is code?
What is code?
codebasics
60 Python unit testing - pytest introduction
Python unit testing - pytest introduction
codebasics

This video tutorial introduces complex and rational numbers in Julia, covering creation, manipulation, and arithmetic operations. It also demonstrates how to use various functions and operators to work with these numbers.

Key Takeaways
  1. Create a complex number using the complex function
  2. Extract the real and imaginary parts of a complex number
  3. Perform arithmetic operations on complex numbers
  4. Create a rational number using the rational function
  5. Extract the numerator and denominator of a rational number
  6. Convert a rational number to a float
💡 Julia uses the 'im' keyword to represent the imaginary unit, rather than 'i', to avoid conflicts with common variable names.

Related Reads

Up next
How to Get Your Brand Cited by ChatGPT, Claude and Gemini
Arvow
Watch →