Sei sulla pagina 1di 7

Matlab Programming – Mechatronics Engineering – SPUP –

2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

Task-02
Input-Output Control

Objectives:
1. to explain the function of disp()
2. to explain the function of input()
3. to explain the function of fprintf()

Instructions:
1. Open your Matlab Program. Let p = last two digits of your student
registration number (e.g. p = 12) and let q = 2p. Write your p and q values in
the below box

p=
q=

Open an M-file or script. Determine the values of P, Q, R, S and T by using


M-file. Remember that Matlab’s variabel is case sensitive.

a. P = 2p + p2
b. Q = x - P / 50q
c. R = 1.8Q / pi
d. S = absolut value of R
e. T = sin (pi / 0.1S)

Copy this below script and paste in the editor window of M-file (script) to find
the answers.

Task02-1
Matlab Programming – Mechatronics Engineering – SPUP –
2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

%Task-2a: Input-Output Control


disp ('*********************************************');
disp ('* Input-Output Control by using Matlab *');
disp ('* by: (your name), Student Reg. No.: (…………) *');
disp ('*********************************************');

%declare variabels
p = ………; %use your own p value
q = ………; %use your own q value

%process of calculations
P = p * 2 + p ^ 2;
Q = p - P / (50*q);
R = Q * 1.8 / pi;
S = abs (R);
T = sin (pi/(0.1*S));

%show the results


disp ('');
disp ('p = ');
disp (p);
disp ('q = ');
disp (q);
disp ('P = p * 2 + p ^ 2');
disp (P);
disp ('Q = p - P / (50*q)');
disp (Q);
disp ('R = Q * 1.8 / pi ');
disp (R);
disp ('S = abs (R)');
disp (S);
disp ('T = sin (pi/(0.1*S))');
disp (T);
disp ('*******************Thank you**********************');

Write your p and q values in the script. Save your script and run it. Print
screen the result and paste it in the below box.

2. Copy this below script and paste in the editor window of M-file (script) to find
the answers.

%Task-2b: Input-Output Control


clc;
disp ('*********************************************');

Task02-2
Matlab Programming – Mechatronics Engineering – SPUP –
2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

disp ('* Input-Output Control by using Matlab *');


disp ('* by: (your name), Student Reg. No.: (…………) *');
disp ('*********************************************');

%input variabels
p = input('Input your own p = ');
q = input('Input your own q = ');

%process of calculations
P = p * 2 + p ^ 2;
Q = p - P / (50*q);
R = Q * 1.8 / pi;
S = abs (R);
T = sin (pi/(0.1*S));

%show the results


fprintf ('\np = %f \n',p); %show the p
fprintf ('q = %f \n',q); %show the q
fprintf ('P = p * 2 + p ^ 2 = %f \n',P); %show the P
………………………………………………… %show the Q
………………………………………………… %show the R
………………………………………………… %show the S
………………………………………………… %show the T

disp ('*******************Thank you**********************');

Write statements for Q, R, S, and T. Save your script with a new name and run
it. Print screen the result and paste it in the below box.

3. Choose 5 cases below that you had choosen in the last semester (Algorithm
and Programming by using CodeBlocks).

o Menghitung Luas segitiga


o Menghitung Luas persegipanjang
o Menghitung Luas lingkaran
o Menghitung Luas permukaan kerucut
o Menghitung Luas permukaan balok
o Menghitung Volume kerucut
o Menghitung Volume silinder
o Menghitung Volume balok

Task02-3
Matlab Programming – Mechatronics Engineering – SPUP –
2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

o Menghitung Kecepatan Gerak Lurus Beraturan


o Menghitung Energi Kinetik
o Menghitung Energi Relativitas Einstein
o Konversi Suhu dari C ke R
o Konversi Suhu dari C ke F
o Konversi Suhu dari C ke K
o Konversi Suhu dari R ke C
o Konversi Suhu dari F ke C
o Konversi Suhu dari K ke C
o Konversi Waktu detik ke menit
o Konversi Waktu detik ke jam
o Konversi Waktu detik ke hari
o Konversi Jarak inchi ke meter
o Konversi Massa ons ke kg
o Konversi Volume liter ke m3

Make a script for the 1 st case (title of case: …………….…….). Save your
script with a suitable name and run it. Copy the script and paste it in the below
box.

Print screen result and paste it in the below box.

Make a script for the 2nd case (title of case: …………….…….). Save your
script with a suitable name and run it. Copy the script and paste it in the below
box.

Task02-4
Matlab Programming – Mechatronics Engineering – SPUP –
2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

Print screen result and paste it in the below box.

Make a script for the 3rd case (title of case: …………….…….). Save your
script with a suitable name and run it. Copy the script and paste it in the below
box.

Print screen result and paste it in the below box.

Make a script for the 4th case (title of case: …………….…….). Save your
script with a suitable name and run it. Copy the script and paste it in the below
box.

Task02-5
Matlab Programming – Mechatronics Engineering – SPUP –
2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

Print screen result and paste it in the below box.

Make a script for the 5th case (title of case: …………….…….). Save your
script with a suitable name and run it. Copy the script and paste it in the below
box.

Print screen result and paste it in the below box.

For the 5th case, copy the script of CodeBlocks in the last semester and
compare with the script of Matlab. Paste them in the below table.

Script of CodeBlocks Script of Matlab

What are the differences of the scripts?

Task02-6
Matlab Programming – Mechatronics Engineering – SPUP –
2019/2020
Name: __________________________________ Student Reg. No. :
_______________ Class: _____

4. Explain the function of these following I/O functions.

a. disp()

b. input()

c. fprintf()

5. Congratulation, you had just finished your second task. 

---end of T2---

Task02-7

Potrebbero piacerti anche