Вы находитесь на странице: 1из 6

Name : Anayosi Br Ginting

Id : 4183322002

Courses : Algorithm and Comp Programming

Question:

1. Design algorithms and computer programs using sequential logic and write the
program code for the calculation of the following physics formulas:
 Kinetic energy. Input data : velocity and mass.

Algorithm Laguage
start
input of data
 m
 v
process
 Ek=0.5*m*v^2
output
 Ek
Stop

Computer Programming

%formula Ek=0.5.m.v^2

clc;

%input

m=input('mass=');

v=input('velocity=');

%process

Ek=0.5*m*v^2;

%output

Ek

OUTPUT

mass=60
velocity=5

Ek =750J

 Distance Of Straight Motion With Constant Acceleration. Input


data: initial velocity, acceleration and time
Answer :

Algorithm Laguage
start
input data
 v0
 a
 t
process
 s=v0*t+0.5*a*t^2
output
 s
stop

Computer Programming

%formula s=v.t+0,5.a.t^2
clc;
%input
v=input('velocity=');
a=input('acceleration=');
t=input('time=');
%process
s=v*t+0.5*a*t^2;
%output
s

OUTPUT

velocity=9
acceleration=3
time=2

s =24m
2. Design algorithms and computer programs using decision logic and write the
program code to calculate the following physics formula:
 S = (v2 - v02 )/(2a) . Input data : a, v and v0
Answer :

Algorithm Language

start
input data
 V
 v0
 a
process
 s=(v^2-v0^2)/(2a)
output
 s
Stop

Computer Programming

%formula s=((v^2)-(v0^2))/(2*a)
clc;
%input
v=input('velocity=');
v0=input('initial velocity=');
a=input('acceleration=');
%process
if a==0
ex='the formulacant be calculated';
else
s=((v^2)-(v0^2))/(2*a);
end
%output
if a==0
disp(ex);
else
disp(['s=',num2str(s),'m']);
end

OUTPUT
velocity=20
initial velocity=4
acceleration=5
s=38.4m

 Spring constant k = F/x . Input data: F and x


Answer :

Algorithm Language

start
input data
 f
 x
process
 k=f/x
output
 k
Stop

Computer Programming

%formula k=f/x
clc;
%input
f=input('force=');
x=input('extension=');
%process
if x==0
ex='the formula cannot be calculated';
else
k=f/x;
end
%output
if x==0
disp(ex);
else
disp(['k=',num2str(k),'N/m']);
end

OUTPUT
force=15
extension=3
k=5N/m

3. Design algorithms and computer programs using loop logic and write the
program code to calculate the number of terms in the following series: 3, 7,
13, 21, ... Input data : amount of terms.
Answer:

clc;
a=3;
b=4;
c=2
n=7;
total=0;
for i=1:n
total=total+a;
disp(['Term ', num2str(i), '=',num2str(a)]);
a=a+b;
b=b+c;
end
disp(['Total=',num2str(total)]);
Output
c=

Term 1=3
Term 2=7
Term 3=13
Term 4=21
Term 5=31
Term 6=43
Term 7=57
Total=175
4. Design algorithms and computer programs using two dimensional data arrays
or matrices to solve the following system of linear equations:
3 X1 + X2 + 4 X3 =25

2 X1 + 3 X2 + X3 =17

3 X1 + 4 X2 +2 X3 =26

ANSWER:

Coding
clc;
disp('Aljabar Linear and Matrix; Ax = b');
a=input('Input Elemen Matrix a= ');
b=input('Input Elemen Matrix b= ');
%proses
x=a\b;
%output
disp('Elemen matrix a ');
a
disp('Elemen matrix b ');
b
disp('Elemen matrix x or the result ');
x

Output
Aljabar Linear and Matrix; Ax = b
Input Elemen Matrix a= [3 1 4;2 3 1;3 4 2]
Input Elemen Matrix b= [25;17;26]
Elemen matrix a

a=

3 1 4
2 3 1
3 4 2

Elemen matrix b

b=

25
17
26

Elemen matrix x or the result

x=

2.0000
3.0000
4.0000

Вам также может понравиться