Sei sulla pagina 1di 8

Group 2 ROUTINE TASK 2

BILINGUAL PHYSICS17 (ALGORITHM AND PROGRAMMING)

Elfi Dwi Ansa (4173121013)

Ruth Sondang (4173121049)

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 :

Basic data types


 Integers
Example of integers: amount of productions, amount of students,
amount of employees, amount of atoms, amount of proton, etc.
 Real Numbers
Example of Real Number: Result of measurement (length, mass,
electric current, etc) ‘ Result of calculating (22/4, 23%,etc)
 Constant
Example of constant number: value of pi, Earth mass, electron
mass, euler number, etc)

Character data types

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.

Logical data types

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

 Array data type


A number of similar data collected by variables that have an index.
sample array data dimension one: the value of 50 students, to
distinguish grades of students 1 to 50 used indexes 1 to 50. sample
array data dimension two: the production of goods types 1 to n from
2000 to 2016. to distinguish the types of products and production year
uses two indexes
 String data type
Data which is a series of characters that form words or sentences. For
example: name, address, description, status, etc.
 Record data type
Data that consists of several data types, such as real, integer, character
and string. Examples of data record types are employee records
containing data: name (string), NIP (integer), address (string), salary
(real), dependent (integer)

2. Explain the difference of variable and Constant.

Answer : Variable are used to store information to be referenced and manipulated in


programming. In Variable, the value can be assigned and changed anytime. Constant are the
same as Variable, but the value will always be the same and cannot be changed and it remains
constant throughout the program.

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’

4. Explain two ways to give a variable value by giving 5 examples.

Answer : The assignment of variable values can be through the assignment process and

reading.

1. Through reading.

Grading values through readings is carried out through data input

the keyboard.

Example:

 Using the Pascal language: read (variable);


 Using MatLab: variable = input (‘Enter data =‘);

2. Through Assignments.

Example:

 Variable value; area 25.89


 Variable1 variabel2; distance 70; x distance;
 Variable expression; y 5 * x + 6 * z;

Example of using MatLab. Give values directly to the variable

»A = 10

a = 10

Provide value via other variables

»A = 50;

»B = a;
»B

b=

50

5. Explain four ways to make variable expressions in programming by giving 5 examples.

Answer :

There are four types of expressions, namely:

arithmetic expressions, relational expressions, logical expressions and string expressions.

 Arithmetic expressions

o Vt v0 + a * t;

o Salary + allowance

o Area 0.5 * base * tg;

 Relational expressions

o Score A> Score B

o (a + b) <c

o p <> q

 Logic Expression

om (n) and (o)

op (q) or (r)

oa not (b)

String expression

o Address' 'JL W Iskandar no 8 Medan';

o The name 'Zakarni Yusuf';


o Value 'A';

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:

 Greater than : >


 Greater than or equal to : >=
 Less than : <
 Less than or equal to : <=
 Equal to : = =
 Not equal to : ~=

Example:

If answer = 0 mean false, 1 mean true.

>> p=10 ; q=15 ;

%equal operator

>> p=q

ans =

% greather than operator

>> p>q

ans =

% less than operator


>> p<q

ans =

%negation operator

>> p~=q

ans =

3. Explain 3 kinds of basic operator logic in Matlab. Give 1 example.


Answer :
 And : &
 Or : |
 Not : ~

Example :

>> x=1;y=0

>> x&y (x and y)

ans=

>> x|y (x or y)

ans=

>> ~x (not y)

ans=

>> ~y (not x)
ans=

4. Give 10 examples using standard mathematic function in matlab.


Answer :
 abs : absokute value
 atan : invers tangent
 cos : cosinus
 fix : pembulatan ke arah nol
 floor : pembulatan ke arah minus
 imag : imaginer part
 log : natural logarithm
 sin : sinus
 tan : tangent
 tanh : hyperbolic tangent
5. Give 5 examples using standard function for text data in matlab
Answer :
 Strcmp
 Strcat
 Isletter
 Isspace
 Int2sr
 Num2str

Potrebbero piacerti anche