SlideShare a Scribd company logo
1 of 25
1.2 MATLAB Numerical Data
◼ Types of numerical data
◼ Output format of numerical data
◼ Common mathematical function
1
1. Types of Numerical Data
◼ Integer
◼ Floating Point
◼ Complex
The system allocates different storage unit to each data type.
Therefore, it determines the range of data.
2
1. Types of Numerical Data
(1) Integer
◼ unsigned integer: unsigned 8-bit integer, unsigned 16-bit integer, unsigned 32-bit
integer, unsigned 64-bit integer.
◼ signed integer: signed 8-bit integer, signed 16-bit integer, signed 32-bit integer,
signed 64-bit integer.
3
According to the number of bytes required in storage space, each type
of integer is divided into 8-bit, 16-bit, 32-bit, 64-bit integer, so there are
8 types of integers.
1. Types of Numerical Data
(1) Integer
◼ the value of a unsigned 8-bit integer ranges from 00000000~11111111(0~28-1).
◼ the value of a signed 8-bit integer ranges from 10000000~01111111(-27~27-1).
4
A note of clarification here, since the number of bytes used to represent an
integer is different, the range of data is different.
1. Types of Numerical Data
(1) Integer
>> x=int8(129)
x =
127
>>
x=uint8(129)
x =
129
Note: the maximum value of a signed 8-bit integer is 127.
5
uint8 function can convert numerical data to 8-bit
unsigned integers.
int8 function can convert numerical data to 8-bit
signed integers.
But because the maximum value of the 8-bit signed integer data is
127, it can only be converted to the maximum of 127.
Because the maximum value of 8-bit unsigned integer data is 255,
and 129 does not exceed, the result after the conversionis still 129.
(2) Floating point
Floating-point data is divided into single-precision and double-precision types.
Single-precision real numbers require 4 bytes of storage space, while the double-
precision real numbers require 8 bytes of storage space. So the double-precision type has
higher data accuracy.
◼ the single function: to convert other types of data to single-precision.
◼ the double function: to convert other types of data to double-precision.
>> class(4)
ans =
double
>> class(single(4))
ans =
single
6
(3) Complex
Complex numbers include real and imaginary part, the real and imaginary parts are double-
precision by default, i and j represent the basic imaginary unit.
◼ The real function: to evaluate the real part of a complex number.
◼ The imag function: to evaluate the imaginary part of a complex number.
>> 6+5i
ans =
6.0000 + 5.0000i
>> 6+5j
ans =
6.0000 + 5.0000i
7
Form of the format command:
format specifier
>> format long
>> 50/3
ans =
16.666666666666668
>> format
>> 50/3
ans =
16.6667
2. Output Format of Numerical Data
Note: the format command only affects the output
format of the data without affecting the calculation
and storage of data.
8
A =
2
6
4
3
>> B=exp(A)
B =
54.5982
20.0855
7.3891
403.4288
3. Common Mathematical Functions
(1) The form of calling the function is:
function name(the value of the independent variable of the function )
>> A=[4,2;3,6]
Note: In the operation of a function, it acts on each
element of the matrix one by one, so the final result
is a matrix that has the same type of variable.
9
MATLAB provides many common mathematical functions, for example, the trigonometric
functions, the square root function, and the natural logarithmic function, etc.
(2) Application of commonly used functions
① The trigonometric functions: some functions use radian measure while some use
degree measure. If the function is in degrees just put a "d" after the function name to
show the difference.
>> sin(pi/2)
ans =
1
>> sind(90)
ans =
1
10
② The abs function can be used for evaluating absolute values of real numbers, modulus
of complex numbers, and ASCII code value of strings.
>> abs(-4)
ans =
4
>> abs(3+4i)
ans =
5
>> abs('a')
ans =
97
11
>> round(4.7)
ans =
5
>> fix(-3.2)
ans =
-3
>> floor(3.6)
ans =
3
>> ceil(-3.8)
ans =
-3
③ The functions used to round integers are fix, floor, ceil, andround.
◼ The fix function rounds to the nearest integer
toward zero.
◼ The floor function rounds to the nearest integer
toward negative infinity.
◼ The ceil function rounds to the nearest integer
toward positive infinity.
◼ The round function rounds to the nearest
integer.
12
④ Examples of function applications.
◼ Calculate a three-digit positive integer's ones, tens, and hundreds.
>> m=345;
>> m1=rem(m,10)
m1 =
5
>> m2=rem(fix(m/10),10)
m2 =
4
>> m3=fix(m/100)
m3 =
3
13
To establish variable m, then assign it a value of 345.
To establish variables m, then assign it a value of 345
To call the fix function first, then round the result of
345 divided by 10
To call the rem function to find the remainder of 34 divided
by 10
>> x=1:100;
>> k=isprime(x);
>> k1=find(k);
>> p=x(k1)
p =
1 至 13 列
2
14 至
43
3 5 7 11 13 17 19 23 29 31 37 41
25 列
47 53 59 61 67 71 73 79 83 89 97
◼ Find all prime numbers in the [1, 100] interval.
14
To generate the vector x of all integers in the range from 1 to 100
To call the "isprime" function to generate the k vector. The elements in the k
vector are either 1 or 0. To be 1 or 0 depends on whether the element at the
corresponding position of the x vector is a prime number.
To call the "isprime" function to generate the k vector. The elements in the k
vector are either 1 or 0. To be 1 or 0 depends on whether the element at the
corresponding position of the x vector is a prime number
To output all prime numbers in x
Please follow me to practice in MATLAB
15
1. Types of Numerical Data
(1) Integer
x=int8(129)
x=uint8(129)
(2) Floating point
the single function: to convert other types of data to single-precision.
the double function: to convert other types of data to double-precision.
class(4)
class(single(4))
(3) Complex
Complex numbers include real and imaginary part, the real and imaginary parts are double-precision by
default, i and j represent the basic imaginary unit.
6+5i
6+5j
real(6+5i);
imag(6+5i)
Please follow me to practice in MATLAB
16
2. Output Format of Numerical Data
Form of the format command:
format long
50/3
format
50/3
Please follow me to practice in MATLAB
17
3. Common Mathematical Functions
A=[4,2;3,6]
B=exp(A)
sin(pi/2)
sind(90)
abs(-4)
abs(3+4i)
abs('a')
Please follow me to practice in MATLAB
18
4. The functions used to round integers are fix, floor, ceil, and round.
round(4.7)
fix(-3.2)
floor(3.6)
ceil(-3.8)
Please follow me to practice in MATLAB
19
5. Calculate a three-digit positive integer's ones, tens, and hundreds.
m=345;
m1=rem(m,10)
m2=rem(fix(m/10),10)
m3=fix(m/100)
6. Find all prime numbers in the [1, 100] interval
x=1:100;
k=isprime(x);
k1=find(k); p=x(k1)
Class Quiz
1. In the command window input the command:
>> x = int8(130)
the value of x is ( ).
A. 127
B. 129
C. 128
D. -127
Answer:A
20
Class Quiz
2. fix(264/100)+mod(264,10)*10 equals ( ).
A. 86
B. 62
C. 423
D. 42
Answer:D
21
Class Quiz
33. The value of sin(pi/2) is equal to that of sind(90).
A. √
B. X
Answer:A
22
Class discussion
1. Complex number
Is there a difference between 3 + 4i and 3 + 4*i in a MATLAB
command? Please verify it on the computer.
Tips:Verify the execution results of the following commands in turn and
summarize the rules.
>> clear
>> i=5;
>> 3+4i
>> 3+4*i
>> 3+4*j
>> 3+4j
23
Answer:i or j are all imaginary units before assignment.
After assignment, if there is a multiplier in the formula for
multiplication, and there is no multiplier, it is still an
imaginary number.
Class discussion
2. Prime number
In MATLAB, how to judge whether n is a prime number in a simple
way?
24
Answer:Call function isprime (n), if the return value is 1, it is a prime number; if
the return value is 0, it is not a prime number.
Class discussion
3. Mathematical constant e
There is no built-in constant for e (2.718), so how can that value be
obtained in MATLAB?
25
Answer: In MATLAB, exp (1) is used to represent e, and exp (x) is used to
represent the x power of e.

More Related Content

What's hot

Solution of matlab chapter 3
Solution of matlab chapter 3Solution of matlab chapter 3
Solution of matlab chapter 3AhsanIrshad8
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java languageHareem Naz
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in CSmit Parikh
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programmingAhmed Moawad
 
Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy AminaRepo
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problemsMake Mannan
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 

What's hot (20)

Solution of matlab chapter 3
Solution of matlab chapter 3Solution of matlab chapter 3
Solution of matlab chapter 3
 
Matlab cheatsheet
Matlab cheatsheetMatlab cheatsheet
Matlab cheatsheet
 
2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Mbd2
Mbd2Mbd2
Mbd2
 
basic concepts
basic conceptsbasic concepts
basic concepts
 
Vector3
Vector3Vector3
Vector3
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Array
ArrayArray
Array
 
Intro to matlab
Intro to matlabIntro to matlab
Intro to matlab
 

Similar to 1.2 matlab numerical data

Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second sessionAhmad Bashar Eter
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsYashJain47002
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoreambikavenkatesh2
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12Rabia Khalid
 
chapter one && two.pdf
chapter one && two.pdfchapter one && two.pdf
chapter one && two.pdfmiftah88
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdfMariappanR3
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questionsESWARANM92
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questionsESWARANM92
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfahmed8651
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1Deepak John
 

Similar to 1.2 matlab numerical data (20)

Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Session2
Session2Session2
Session2
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questions
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
 
chapter one && two.pdf
chapter one && two.pdfchapter one && two.pdf
chapter one && two.pdf
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdf
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Module 1 number systems and code1
Module 1  number systems and code1Module 1  number systems and code1
Module 1 number systems and code1
 

Recently uploaded

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

1.2 matlab numerical data

  • 1. 1.2 MATLAB Numerical Data ◼ Types of numerical data ◼ Output format of numerical data ◼ Common mathematical function 1
  • 2. 1. Types of Numerical Data ◼ Integer ◼ Floating Point ◼ Complex The system allocates different storage unit to each data type. Therefore, it determines the range of data. 2
  • 3. 1. Types of Numerical Data (1) Integer ◼ unsigned integer: unsigned 8-bit integer, unsigned 16-bit integer, unsigned 32-bit integer, unsigned 64-bit integer. ◼ signed integer: signed 8-bit integer, signed 16-bit integer, signed 32-bit integer, signed 64-bit integer. 3 According to the number of bytes required in storage space, each type of integer is divided into 8-bit, 16-bit, 32-bit, 64-bit integer, so there are 8 types of integers.
  • 4. 1. Types of Numerical Data (1) Integer ◼ the value of a unsigned 8-bit integer ranges from 00000000~11111111(0~28-1). ◼ the value of a signed 8-bit integer ranges from 10000000~01111111(-27~27-1). 4 A note of clarification here, since the number of bytes used to represent an integer is different, the range of data is different.
  • 5. 1. Types of Numerical Data (1) Integer >> x=int8(129) x = 127 >> x=uint8(129) x = 129 Note: the maximum value of a signed 8-bit integer is 127. 5 uint8 function can convert numerical data to 8-bit unsigned integers. int8 function can convert numerical data to 8-bit signed integers. But because the maximum value of the 8-bit signed integer data is 127, it can only be converted to the maximum of 127. Because the maximum value of 8-bit unsigned integer data is 255, and 129 does not exceed, the result after the conversionis still 129.
  • 6. (2) Floating point Floating-point data is divided into single-precision and double-precision types. Single-precision real numbers require 4 bytes of storage space, while the double- precision real numbers require 8 bytes of storage space. So the double-precision type has higher data accuracy. ◼ the single function: to convert other types of data to single-precision. ◼ the double function: to convert other types of data to double-precision. >> class(4) ans = double >> class(single(4)) ans = single 6
  • 7. (3) Complex Complex numbers include real and imaginary part, the real and imaginary parts are double- precision by default, i and j represent the basic imaginary unit. ◼ The real function: to evaluate the real part of a complex number. ◼ The imag function: to evaluate the imaginary part of a complex number. >> 6+5i ans = 6.0000 + 5.0000i >> 6+5j ans = 6.0000 + 5.0000i 7
  • 8. Form of the format command: format specifier >> format long >> 50/3 ans = 16.666666666666668 >> format >> 50/3 ans = 16.6667 2. Output Format of Numerical Data Note: the format command only affects the output format of the data without affecting the calculation and storage of data. 8
  • 9. A = 2 6 4 3 >> B=exp(A) B = 54.5982 20.0855 7.3891 403.4288 3. Common Mathematical Functions (1) The form of calling the function is: function name(the value of the independent variable of the function ) >> A=[4,2;3,6] Note: In the operation of a function, it acts on each element of the matrix one by one, so the final result is a matrix that has the same type of variable. 9 MATLAB provides many common mathematical functions, for example, the trigonometric functions, the square root function, and the natural logarithmic function, etc.
  • 10. (2) Application of commonly used functions ① The trigonometric functions: some functions use radian measure while some use degree measure. If the function is in degrees just put a "d" after the function name to show the difference. >> sin(pi/2) ans = 1 >> sind(90) ans = 1 10
  • 11. ② The abs function can be used for evaluating absolute values of real numbers, modulus of complex numbers, and ASCII code value of strings. >> abs(-4) ans = 4 >> abs(3+4i) ans = 5 >> abs('a') ans = 97 11
  • 12. >> round(4.7) ans = 5 >> fix(-3.2) ans = -3 >> floor(3.6) ans = 3 >> ceil(-3.8) ans = -3 ③ The functions used to round integers are fix, floor, ceil, andround. ◼ The fix function rounds to the nearest integer toward zero. ◼ The floor function rounds to the nearest integer toward negative infinity. ◼ The ceil function rounds to the nearest integer toward positive infinity. ◼ The round function rounds to the nearest integer. 12
  • 13. ④ Examples of function applications. ◼ Calculate a three-digit positive integer's ones, tens, and hundreds. >> m=345; >> m1=rem(m,10) m1 = 5 >> m2=rem(fix(m/10),10) m2 = 4 >> m3=fix(m/100) m3 = 3 13 To establish variable m, then assign it a value of 345. To establish variables m, then assign it a value of 345 To call the fix function first, then round the result of 345 divided by 10 To call the rem function to find the remainder of 34 divided by 10
  • 14. >> x=1:100; >> k=isprime(x); >> k1=find(k); >> p=x(k1) p = 1 至 13 列 2 14 至 43 3 5 7 11 13 17 19 23 29 31 37 41 25 列 47 53 59 61 67 71 73 79 83 89 97 ◼ Find all prime numbers in the [1, 100] interval. 14 To generate the vector x of all integers in the range from 1 to 100 To call the "isprime" function to generate the k vector. The elements in the k vector are either 1 or 0. To be 1 or 0 depends on whether the element at the corresponding position of the x vector is a prime number. To call the "isprime" function to generate the k vector. The elements in the k vector are either 1 or 0. To be 1 or 0 depends on whether the element at the corresponding position of the x vector is a prime number To output all prime numbers in x
  • 15. Please follow me to practice in MATLAB 15 1. Types of Numerical Data (1) Integer x=int8(129) x=uint8(129) (2) Floating point the single function: to convert other types of data to single-precision. the double function: to convert other types of data to double-precision. class(4) class(single(4)) (3) Complex Complex numbers include real and imaginary part, the real and imaginary parts are double-precision by default, i and j represent the basic imaginary unit. 6+5i 6+5j real(6+5i); imag(6+5i)
  • 16. Please follow me to practice in MATLAB 16 2. Output Format of Numerical Data Form of the format command: format long 50/3 format 50/3
  • 17. Please follow me to practice in MATLAB 17 3. Common Mathematical Functions A=[4,2;3,6] B=exp(A) sin(pi/2) sind(90) abs(-4) abs(3+4i) abs('a')
  • 18. Please follow me to practice in MATLAB 18 4. The functions used to round integers are fix, floor, ceil, and round. round(4.7) fix(-3.2) floor(3.6) ceil(-3.8)
  • 19. Please follow me to practice in MATLAB 19 5. Calculate a three-digit positive integer's ones, tens, and hundreds. m=345; m1=rem(m,10) m2=rem(fix(m/10),10) m3=fix(m/100) 6. Find all prime numbers in the [1, 100] interval x=1:100; k=isprime(x); k1=find(k); p=x(k1)
  • 20. Class Quiz 1. In the command window input the command: >> x = int8(130) the value of x is ( ). A. 127 B. 129 C. 128 D. -127 Answer:A 20
  • 21. Class Quiz 2. fix(264/100)+mod(264,10)*10 equals ( ). A. 86 B. 62 C. 423 D. 42 Answer:D 21
  • 22. Class Quiz 33. The value of sin(pi/2) is equal to that of sind(90). A. √ B. X Answer:A 22
  • 23. Class discussion 1. Complex number Is there a difference between 3 + 4i and 3 + 4*i in a MATLAB command? Please verify it on the computer. Tips:Verify the execution results of the following commands in turn and summarize the rules. >> clear >> i=5; >> 3+4i >> 3+4*i >> 3+4*j >> 3+4j 23 Answer:i or j are all imaginary units before assignment. After assignment, if there is a multiplier in the formula for multiplication, and there is no multiplier, it is still an imaginary number.
  • 24. Class discussion 2. Prime number In MATLAB, how to judge whether n is a prime number in a simple way? 24 Answer:Call function isprime (n), if the return value is 1, it is a prime number; if the return value is 0, it is not a prime number.
  • 25. Class discussion 3. Mathematical constant e There is no built-in constant for e (2.718), so how can that value be obtained in MATLAB? 25 Answer: In MATLAB, exp (1) is used to represent e, and exp (x) is used to represent the x power of e.

Editor's Notes

  1. Look at the complex numbers which consists of both real and imaginary(/ɪˈmædʒɪnəri/) parts, the real and imaginary parts are double-precision by default. In MATLAB. i and j represent the basic imaginary unit. For example, 6+5i and 6+5j represent the same complex number. For the complex numbers, we can use the real function to evaluate (/ɪˈvæljueɪt/) the real part of a complex number, and use the imag function to evaluate(/ɪˈvæljueɪt/) the imaginary part of a complex number.
  2. In MATLAB, you can use the format(/ˈfɔːmæt/) command to set output format for numeric data. The form of the format command is format specifier(/'spesifaiə/). The format specifier determines the output format of the data. For example, The first command is format long. this command sets output format to long format. The second command outputs a value of 50/3(50 divided by 3). We can see the output is 15 decimal(/ˈdesɪml/) places(/'pleɪsɪz/). The third command is to enter the format command without format specifiers and back to the default output format, which is the short(/ʃɔːt/) format, then output a value of 50/3. The output is four decimal places, so different format specifiers make the data output format different. But it should be noted that the format command only affects(/əˈfekts/) the output format of the data without affecting the calculation and storage of data.
  3. MATLAB provides many common mathematical functions, for example, the trigonometric(/ˌtrɪɡənəˈmetrɪk/) functions, the square root function, and the natural(/ˈnætʃrəl/) logarithmic(/ˌlɒɡəˈrɪðmɪk/) function, etc. The call form of the function is the function name (value of independent variable of the function). The independent variable of the function is specified(/ˈspesɪfaɪd/) as a matrix variable. Of course, It can be scalars(/ˈskeɪlə(r)/). The scalar itself is a trope(/trəʊp/) of the matrix. In the operation of a function, it acts on each element of the matrix one by one, so the final result is a matrix that has the same type of variable. Next, let's have a look at an example. The first command creates matrix A which is a two-row, two-column(/ˈkɒləm/) matrix. The second command calls the exp function to evaluate(ɪˈvæljueɪt) natural index. The independent variable is matrix A then assign the result of the call to B. We can see that in the end B is also a two-row, two-column matrix. Each element in B is actually(/ˈæktʃuəli/) the natural index of the corresponding element in matrix A.
  4. Next, let's illustrate (/ˈɪləstreɪt/) the application of functions in MATLAB. First, the trigonometric(/ˌtrɪɡənəˈmetrɪk/) functions. Some functions use Radian(/ˈreɪdiən/) Measure(/ˈmeʒə(r)/) while some use Degree Measure. If the function is in degrees just put a "d" after the function name to show(/ʃəʊ/) the difference. For example, enter the first command in the command window to evaluate the value of the sine function of π/2 radians and the second command to evaluate a sine function of 90 degrees. Both commands result in 1.
  5. Third, In MATLAB, the functions used to round are fix(/fɪks/), floor(/flɔː(r)/), ceil and round. It's easy for us to feel confused (/kənˈfjuːzd/)when we use them. The round function rounds to the nearest integer. As for the other 3 functions, the meaning of their names can help you remember how they round. You can take ceil for a ceiling over your head, so it rounds up to an integer. It rounds to the nearest integer toward positive infinity. floor is under your feet, so it rounds down to an integer. It rounds to the nearest integer toward(/tɔːd) minus infinity(ɪnˈfɪnəti). fix means fixed. It rounds to the nearest integer toward zero. That is, rounding off decimals. Next, let’s use some examples to help you further(/ˈfɜːðə(r)/) understand. The first command round(4.7) rounds to 5. The second command fix(-3.2) rounds to the nearest integer toward zero, the result is -3 The third command floor(3.6) it rounds to the nearest integer toward minus infinity((ɪnˈfɪnəti), so the result is 3 instead of 4. The fourth command ceil(-3.8). It rounds to the nearest integer toward positive infinity, and the result is -3.
  6. Just now, we listed the uses of some common functions , but actually(/ˈæktʃuəli/), there are more functions available(/əˈveɪləbl/) in MATLAB. Let's look at two examples next. The first question is to calculate a three-digit(/ˈdɪdʒɪt/) positive integer's ones, tens, and hundreds. Think about how do you mathematically solve for a three-digit positive(/ˈpɒzətɪv/) integer's ones, tens, and hundreds? The remainder of a three-digit positive integer divided by 10 is the ones of this number. How about the tens? A three-digit positive integer divided by 10 has removed its ones after being rounded. The remainder of the new number divided by 10 is the ones of the new number. That's also the tens of the original(/əˈrɪdʒənl/) number. How do you calculate the hundreds? A three-digit positive integer, after being divided by 100 and rounded up, its ones and tens are removed. So we can get its hundreds. Think about how is it done in MATLAB? Obviously(/ˈɒbviəsli/), rounding functions and remainder functions are needed. The rounding function was mentioned earlier. As for the remainder(/rɪˈmeɪndə(r)/) function, we can use rem function or mod function. Let’s notice(/ˈnəʊtɪs/) the results of the operation next. The first command is to establish variables m, then assign it a value of 345. The second command calls the rem function to find the remainder of 345 divided by 10 and assign it to m1. The result is 5, the ones of 345. The third command is to call the fix function first, then round the result of 345 divided by 10. The result is 34. Then call the rem function to find the remainder of 34 divided by 10. The result is 4. The tens of 345. The fourth command calls the fix function to round the result of 345 divided by 100. The result is 3. Namely the hundreds of 345.
  7. The second problem is to find all prime(/praɪm/) numbers in the [1, 100] interval(/ˈɪntəvl/). This is a very common problem in programming learning. Usually based on the definition of a prime number, we can use a loop structure(/ˈstrʌktʃə(r)/) to solve this problem. Here is the solution of the MATLAB function. MATLAB provides a function "isprime" to check whether n is a prime number. When n is a prime number, it returns 1, Otherwise returns 0. Using this function and the features (/ˈfiːtʃəz/) of MATLAB data, you can find all the prime numbers between 1 and 100. Let's see the command next. The first command is to generate(/ˈdʒenəreɪt/) the vector x of all integers in the range from 1 to 100. The second command is to call the "isprime" function to generate the k vector. The elements in the k vector are either 1 or 0. To be 1 or 0 depends on whether the element at the corresponding position of the x vector is a prime number. The third command is to call the find function to generate the k1 vector. The elements in the k1 vector are serial(/ˈsɪəriəl) number of non-zero elements of the k vector, That is, the index of the prime element in x. The fourth command is to output all prime numbers in x, Namely all the prime numbers in the range from 1 to 100. By learning this example. We can learn the characteristics and rules(/ruːlz/)of MATLAB data.
  8. Today, I’ve introduced the numeric data of MATLAB. and we've learned about MATLAB data types, features, classification(/ˌklæsɪfɪˈkeɪʃn/), output formats and common internal functions.
  9. That's all for this section. Thank you. I'll see you next time.