0% found this document useful (0 votes)
30 views7 pages

Programming Language and Numerical Analysis - Exercise Before Midterm Test - RUSTAM

The document contains 4 exercises on programming in MATLAB/Octave. The first exercise involves defining a piecewise function, plotting it, and filling in a table of values. The second solves a summation equation and fills a table. The third calculates BMI from data and determines status. The fourth counts prime numbers within ranges and finds the maximum and 10th prime.

Uploaded by

Rustam Efendi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views7 pages

Programming Language and Numerical Analysis - Exercise Before Midterm Test - RUSTAM

The document contains 4 exercises on programming in MATLAB/Octave. The first exercise involves defining a piecewise function, plotting it, and filling in a table of values. The second solves a summation equation and fills a table. The third calculates BMI from data and determines status. The fourth counts prime numbers within ranges and finds the maximum and 10th prime.

Uploaded by

Rustam Efendi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

NAME : RUSTAM EFENDI BATU BARA

STUDENT ID : 003201900015
MAJOR : Mechanical Engineering
SUBJECT : Programming Language and Numerical
Analysis
TOPIC ASSIGMENTS : Exercise before Midterm Test

EXERCISE BEFORE MIDTERM TEST

1) Buat sebuah program dalam Matlab/Octave untuk fungsi berikut

(x)^2 + 2x − 1, x < −1
f(x) = { (x)^2 − 2x + 1, x≥1
0, −1 ≤ x < 1

(A) Tuliskan ALGORITHM (flow chart atau pseudo program dengan kata-kata)

(B) Tuliskan jawabanmu dalam tabel berikut:


X -5 -1.5 -1 0.5 0.75 1 1.5 5 10
f(x)

(C) Plot a graph with X : -10 to 10, increment 0.2

2) Buat sebuah program dalam Matlab/Octave untuk menyelesaikan persamaan berikut

Isilah tabel berikut:

n 5 10 20 40 80 1000
S
3) Tentukan indeks kebugaran masing-masing siswa yg ada dalam tabel di bawah ini.
Nama Jenis Kelamin BB kg) Tinggi (cm) BMI Status
Akbar Pria 75 165
Didin Pria 100 180
Budi Pria 62 162
Wati Wanita 60 155
Robert Pria 95 175
Diah Wanita 48 162
Maya Wanita 45 152
Topan Pria 85 171
Suci Wanita 70 172
Lily Wanita 58 156

Rumus BMI:
BMI = Berat Badan (kg) / Tinggi Badan (cm) ^2

Tabel BMI dan Status

4) Buat program dalam Matlab/Octave untuk mengisi tabel berikut:


Start End Jumlah Total Bilangan Prima Bilangan prima ke-10
Bil.Prima Max dalam range dalam range
0 100
750 1500
5000 15000
PERHATIAN:
Program file (m file) dicopy paste di bawah ini. Kemudian submit dalam bentuk PDF file.

Jawaban
1.
X -5 -1.5 -1 0.5 0.75 1 1.5 5 10
f(x) 14 - 0 0 0 0 0.2500 16 81
1.7500

for i=1:9
x= input ("nilai x =")
if x< -1
hasil = (x^2) + (2*x) - (1)
elseif x>=1
hasil = (x^2) - (2*x) + (1)
else x>= -1 , x <1
hasil =0
end
end

X = [-5 -1.5 -1 0.5 0.75 1 1.5 5 10];


j=0
for i = X
j=j+1;
if x < -1
y(j) -i^2 + 2*1 - 1;
elseif x >=1
y(j)-i^2 + 2*1 - 1;
else
y(j)=0
end
end
plot (X,y), grid on, xlim ([-10, 10])
2.

n 5 10 20 40 80 1000
S 165 1330 10660 85320 682640 1.3333e+09
for i = 1:6;
n= input ("nilai n=")
a=1;
y=0
while a<=n
S=(2*a-1)^2- y;
y=S;
a=a+1;
end
disp (S)
end

3.
Jenis
Nama BB kg) Tinggi (cm) BMI Status
Kelamin
Akbar Pria 75 165 27.548 overweight
Didin Pria 100 180 30.864 obesed
Budi Pria 62 162 23.624 Normal weight
Wati Wanita 60 155 24.974 overweight

Robert Pria 95 175 31.020 obesed

Diah Wanita 48 162 18.290 underweight

Maya Wanita 45 152 19.477 Normal


weight

Topan Pria 85 171 29.069 overweight

Suci Wanita 70 172 23.661 Normal


weight

Lily Wanita 58 156 23.833 Normal


weight

for i=1:10;
wanita=1;
pria=2;
k= input ('jenis kelamin=')
x=input ('berat badan(dalam kg) = ')
y= input ('tinggi badan (dalam m) = ')

z=x/(y^2)
if k=1;
if z<19
disp ('underweight')
elseif and (z>= 19, z<=23.9)
disp ('Normal Weight')
elseif and (z>=24, z<=28.9)
disp ('overweight')
elseif and (z>=29, z<=38.9)
disp ('obesed')
else
disp ('extreme obesed')
endif
endif
if k=2;
if z<20
disp ('underweight')
elseif and (z>=20, z<=24.9)
disp ('Normal Weight')
elseif and (z>=25, z<=29.9)
disp ('overweight')
elseif and (z>=30, z<=39.9)
disp ('obesed')
else
disp ('extreme obesed')
endif
endif
end
4.
Start End Jumlah Total Bilangan Prima Bilangan prima ke-10
Bil.Prima Max dalam range dalam range
0 100 25 97 29
750 1500 132 1499 29
5000 15000 1217 14983 29

x=input ("nilai =")


y=input ("nilai=")
z=input ("nilai=")
hasil = 0;
max = 0;
range = 0;
for i = 0:100
if i==2
hasil = hasil + 1;
else
if mod(i,(2:i-1))~= 0
hasil = hasil + 1;
max = i;
if hasil == x
range=i;
endif
endif
endif
end
disp ('bilangan prima max dalam range 0-100')
disp(max)
disp ('bilangan prima ke 10 dalam range 0-100')
disp(range)
disp('total bilangan prima')
disp (hasil)
for i = 750:1500
if i==2
hasil = hasil + 1;
else
if mod(i,(2:i-1))~= 0
hasil = hasil + 1;
max = i;
if hasil == y
range=i;
endif
endif
endif
end
disp ('bilangan prima max dalam range 750-1500')
disp(max)
disp ('bilangan prima ke 10 dalam range 750-1500')
disp(range)
disp('total bilangan prima')
disp (hasil)
for i = 5000:15000
if i==2
hasil = hasil + 1;
else
if mod(i,(2:i-1))~= 0
hasil = hasil + 1;
max = i;
if hasil == z
range=i;
endif
endif
endif
end
disp ('bilangan prima max dalam range 5000-15000')
disp(max)
disp ('bilangan prima ke 10 dalam range 5000-15000')
disp(range)
disp('total bilangan prima')
disp (hasil)

You might also like