Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Chapter 3
D.Exercise
1. Explain the difference in basic data types,character types, logical types and formed data
types. Give 5 examples each one.
Answer :
A character is a single data that has all letters, read symbols, and also numeric
symbols that cannot be operated automatically. For example: 'A', 'B', ... 'Z', 'a',
'b', 'c', ..., 'z', '1', ..., '9', ' ? ','! ','; ', etc.
The data has two conditions for example true(1) or false (0). The example of
logical data types: on or off, man or woman, tall or short, day or night, etc.
Formed data types
3. Explain the rules of creating variables in progamming. Give 5 example of writing the
correct variable.
Answer :
Variable must be start with alphabet not with numbers or other characters.
Names can only contain letters, numbers and underscore
Names should not use function characters such as +; – ; * ; / ; < ; > ; : ; = ; # ; etc.
It is forbidden to use the same variable name with the name of exiating function. For
example mesh,sqrt,sin, etc
Example :
$name = ‘kiara’ , ’rafles ’ , ‘cika’
$fruit = ‘banana’ , ‘pineaple’ , ‘grape’
$days = ‘wednesday’ , ‘Friday ’ , ‘saturday’
$country = ‘America’, ‘Russia’ , ‘Myanmar’
Answer : The assignment of variable values can be through the assignment process and
reading.
1. Through reading.
the keyboard.
Example:
2. Through Assignments.
Example:
»A = 10
a = 10
»A = 50;
»B = a;
»B
b=
50
Answer :
Arithmetic expressions
o Vt v0 + a * t;
o Salary + allowance
Relational expressions
o (a + b) <c
o p <> q
Logic Expression
op (q) or (r)
oa not (b)
String expression
Chapter 3
F. Exercise
1. Explain the 5 basic types of arithmetic operators in Matlab. Give 2 examples each.
Answer:
Penjumlahan (+)
Contoh:
>> 2+2
Ans = 4
>> 7+3
Ans = 10
Pengurangan (-)
Contoh:
>> 7-5
Ans = 2
>> 9-4
Ans = 5
Perkalian (*)
Contoh:
>> 6*5
Ans = 30
>> 8*4
Ans = 32
Pembagian (/)
Contoh:
>> 6/3
Ans = 2
>> 10/2
Ans = 5
Pangkat (^)
Contoh:
>> 6^2
Ans = 36
>> 8^2
Ans = 54
2. Explain the six basic types of relation operators in Matlab. Give each of two
examples.
Answer:
Example:
%equal operator
>> p=q
ans =
>> p>q
ans =
ans =
%negation operator
>> p~=q
ans =
Example :
>> x=1;y=0
ans=
>> x|y (x or y)
ans=
>> ~x (not y)
ans=
>> ~y (not x)
ans=