Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
COMPILED BY:
PHYSICS DEPARTMENT
FACULTY OF MATHEMATICS AND NATURAL SCIENCE
STATE UNIVERSITY OF MEDAN
2018
1. Program to Determine Kinetic Energy
1. Definition of Problem
Determine kinetic Energy
Formula: Ek=0.5*m*v2
Data input: velocity, mass.
Output Data: kinetic Energy
2. Data Structure
Unit/Magnitude Variable Type of data Description
Velocity v Real/Numeric Input data
Mass m Real/Numeric Input data
Kinetic Energy ke Real/Numeric Output data
3. Algorithm Program
Algorithm Use Flowchart
Start
v,m
ke = 0.5*m*v
ke
Stop
4. Coding In MatLab
%Program Computer to Determine Kinetic Energy
%Input
v=input ('velocity= ' );
m=input ('mass= ' );
%process
ke=0.5*m*v.^2;
%output
fprintf( '\nKinetic Energy=%8.2f' ,ke) ;disp([ ' joule']);
5. Testing Program
>> test 1
velocity= 42
mass= 30
Kinetic Energy=26460.00 joule
>> test 2
velocity= 30
mass= 30
Kinetic Energy=13500.00 joule
>> test 3
velocity= 23
mass= 4
Kinetic Energy= 1058.00 joule
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
v, t
Q=v/t
Q
Stop
4. Coding In MatLab
%Program Computer to Determine debit fluid
%Input
v=input ('volume= ' );
t=input ('time= ' );
%process
ke=v/t;
%output
fprintf( '\nDebit Fluid=%8.1f' ,ke) ;disp([ ' Liter/sekon']);
5. Testing Program
>> test 1
volume= 300
time= 56
Debit Fluid= 5.4 Liter/sekon
>> test 2
veolume= 150
time= 20
Debit Fluid= 7.5 Liter/sekon
>> test 3
veolume= 100
time= 12
Debit Fluid= 8.3 Liter/sekon
3. Algorithm Program
Algorithm Use Flowchart
Start
F, t
I=F*t
Stop
4. Coding In MatLab
%Program Computer to Determine Implus
%Input
f=input ('Force = ' );
t=input ('time = ' );
%process
I=f*t;
%output
fprintf( '\nImplus=%8.1f' ,I) ;disp([ ' Newton/sekon']);
5. Testing Program
>> test 1
Force = 30
time = 2
Implus= 60.0 Newton/sekon
>> test 2
Force = 40
time = 2
Implus= 80.0 Newton/sekon
>> test 3
Force = 20
time = 43
Implus= 860.0 Newton/sekon
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
Vo, t, a
d= vo *t+0.5*a*t.^2
d
Stop
4. Coding In MatLab
%Program Computer to Determine Distance
%Input
vo=input ('Initial velocity = ' );
a=input ('accelaration = ' );
t=input ('time = ' );
%process
d=vo*t+0.5*a*t.^2;
%output
fprintf( '\ndistance=%8.1f' ,d) ;disp([ ' meter']);
5. Testing Program
>> test 1
Initial velocity = 0
accelaration = 30
time = 2
distance= 60.0 meter
>> test 2
Initial velocity = 20
accelaration = 2
time = 10
distance= 300.0 meter
>> test 3
Initial velocity = 24
accelaration = 3
time = 20
distance= 1080.0 meter
3. Algorithm Program
Algorithm Use Flowchart
Start
s,t
V=s/t
Stop
4. Coding In MatLab
%Program Computer to Determine velocity
%Input
s=input ('direction = ' );
t=input ('time = ' );
%process
v=s/t;
%output
fprintf( '\nvelocity=%8.1f' ,v) ;disp([ ' m/s']);
5. Testing Program
>> test 1
direction = 20
time = 5
velocity= 4.0 m/s
>> test 2
direction = 300
time = 6
velocity= 50.0 m/
>> test 3
direction = 40
time = 3
velocity= 13.3 m/s
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
r, f, sin(x)
Tr = r*f*sin(x)
tr
Stop
4. Coding In MatLab
%Program Computer to Torque
%Input
r=input ('radius = ' );
f=input ('force = ' );
x=input ('alfa = ' );
%process
x=x*pi/180;
tr=r*f*sin(x);
%output
fprintf( '\nTorque=%8.1f' ,tr) ;disp([ ' Nm']);
5. Testing Program
>> test 1
radius = 4
force = 2
alfa = 15
Torque= 2.1 Nm
>> test 2
radius = 6
force = 4
alfa = 45
Torque= 17.0 Nm
>> test 3
radius = 8
force = 12
alfa = 30
Torque= 48.0 Nm
3. Algorithm Program
Algorithm Use Flowchart
Start
Vo, sin(x), g
dmax= vo*(sin(2*x))/g
dmax
Stop
4. Coding In MatLab
%Program Computer to Determine maximum distance
%Input
vo=input ('initial velocity = ' );
x=input ('alfa = ' );
%process
x=x*pi/180;
g=10;
dmax=vo*(sin(2*x))/g;
%output
fprintf( '\nmaximum distance=%8.1f' ,dmax) ;disp([ 'm']);
5. Testing Program
>> test 1
initial velocity = 3
alfa = 15
maximum distance= 0.1m
>> test 2
initial velocity = 4
alfa = 45
maximum distance= 0.4m
>> test 3
initial velocity = 6
alfa = 30
maximum distance= 0.5m
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
c, n
Fs = c*n
fs
Stop
4. Coding In MatLab
%Program Computer to Statis Friction
%Input
c=input ('coefficient of friction = ' );
n=input ('normal force = ' );
%process
fs=c*n;
%output
fprintf( '\nstatis friction=%8.1f' ,fs) ;disp([ ' N']);
5. Testing Program
>> test 1
coefficient of friction = 32
normal force = 30
statis friction= 960.0 N
>> test 2
coefficient of friction = 20
normal force = 5
statis friction= 100.0 N
>> test 3
coefficient of friction = 50
normal force = 67
statis friction= 3350.0 N
3. Algorithm Program
Algorithm Use Flowchart
Start
d, h
P=d*g*h
Stop
4. Coding In MatLab
%Program Computer to Pressure
%Input
d=input ('density = ' );
h=input ('height = ' );
%process
g=10;
P=d*g*h;
%output
fprintf( '\nPressure=%8.1f' ,P) ;disp([ ' Pa']);
5. Testing Program
>> test 1
density = 30
height = 15
Pressure= 4500.0 Pa
>> test 2
density = 20
height = 14
Pressure= 2800.0 Pa
>> test 3
density = 30
height = 40
Pressure= 12000.0 Pa
3. Algorithm Program
Algorithm Use Flowchart
Start
m, h, v
𝑚𝑒 = 𝑚 ∗ 𝑔 ∗ ℎ + 0.5 ∗ 𝑚 ∗ 𝑣. ^2
me
Stop
4. Coding In MatLab
%Program Computer to Mechanic Energy
%Input
m=input ('mass= ' );
h=input ('height = ' );
v=input ('velocity = ' );
%process
g=10;
me=m*g*h+0.5*m*v.^2;
%output
fprintf( '\nMechanic Energy=%8.1f' ,me) ;disp([ ' Joule']);
5. Testing Program
>> test 1
mass= 10
height = 5
velocity = 3
Mechanic Energy= 545.0 Joule
>> test 2
mass= 10
height = 9
velocity = 43
Mechanic Energy= 10145.0 Joule
>> test 3
mass= 45
height = 110
velocity = 30
Mechanic Energy= 69750.0 Joule
11. Program to Determine Period of Pendulum
1. Definition of Problem
Determine of Period of Pendulum
𝐿
Formula: 𝑇 = 2𝜋√𝑔
Data input: length of pendulum
Output Data: T (Priod of Pendulum)
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
T=2*pi*sqrt(l/g)
Stop
4. Coding In MatLab
%Program Computer to Period of pendulum
%Input
l=input ('length of pendulum = ' );
%process
g=10;
T=2*pi*sqrt(l/g);
%output
fprintf( '\nPeriod of pendulum=%8.1f' ,T) ;disp([ ' second']);
5. Testing Program
>> test 1
length of pendulum = 15
Period of pendulum= 7.7 second
>> test 2
length of pendulum = 30
Period of pendulum= 10.9 second
>> test 3
length of pendulum = 40
Period of pendulum= 12.6 second
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
m,c,T1,T2
Q=m*c*(T2-T1)
Stop
4. Coding In MatLab
%Program Computer to Calor
%Input
m=input ('mass = ' );
c=input ('heat type substance = ' );
T1=input ('Temperature1 = ' );
T2=input ('Temperature2 = ' );
%process
Q=m*c*(T2-T1);
%output
fprintf( '\nCalor=%8.1f' ,Q) ;disp([ ' Joule']);
5. Testing Program
>> test 1
mass = 10
heat type substance = 1.6
Temperature1 = 20
Temperature2 = 30
Calor= 160.0 Joule
>> test 2
mass = 32
heat type substance = 1.8
Temperature1 = 40
Temperature2 = 20
Calor= -1152.0 Joule
>> test 3
mass = 10
heat type substance = 2.5
Temperature1 = 30
Temperature2 = 60
Calor= 750.0 Joule
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
m,v
Rho=m/v
rho
Stop
4. Coding In MatLab
%Program Computer to Rho
%Input
m=input ('mass = ' );
v=input ('volume = ' );
%process
rho=m/v;
%output
fprintf( '\nDensity=%8.1f' ,rho) ;disp([ ' kg/m^3']);
5. Testing Program
>> test 1
mass = 32
volume = 40
>> test 2
mass = 20
volume = 10
Density= 2.0 kg/m^3
>> test 3
mass = 15
volume = 36
Density= 0.4 kg/m^3
2. Data Structure
Start
m1, m2, r
F =G*m1*m2/r.^2
Stop
4. Coding In MatLab
%Program Computer to gravity force
%Input
m1=input ('mass 1 = ' );
m2=input ('mass 2 = ' );
r=input ('radius = ' );
%process
G=6.67*(10^-11)
F=G*m1*m2/r.^2;
%output
fprintf( '\nGravity Force=%8.12f' ,F) ;disp([ ' Newton']);
5. Testing Program
>> test 1
mass 1 = 5
mass 2 = 3
radius = 6
G = 6.6700e-011
Gravity Force=0.000000000028 Newton
>> test 2
mass 1 = 6
mass 2 = 4
radius = 8
G =6.6700e-011
Gravity Force=0.000000000025 Newton
>> test 3
mass 1 = 5
mass 2 = 5
radius = 4
G =6.6700e-011
Gravity Force=0.000000000104 Newton
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
F,A
P=F/A
P
Stop
4. Coding In MatLab
%Program Computer to pressure
%Input
F=input ('Force = ' );
A=input ('Area = ' );
%process
P=F/A;
%output
fprintf( '\nPressure=%8.1f' ,P) ;disp([ ' Pa']);
5. Testing Program
>> test 1
Force = 10
Area = 5
Pressure= 2.0 Pa
>> test 2
Force = 15
Area = 3
Pressure= 5.0 Pa
>> test 3
Force = 50
Area = 5
Pressure= 10.0 Pa
2. Data Structure
Start
F,d,cos(x)
W=F*d*cos(x)
Stop
4. Coding In MatLab
%Program Computer to Work
%Input
f=input ('force = ' );
d=input ('distance= ' );
x=input ('teta = ' );
%process
x=x*pi/180;
W=f*d*cos(x);
%output
fprintf( '\nWork=%8.1f' ,W) ;disp([ ' Joule']);
5. Testing Program
>> test 1
force = 10
distance= 30
teta = 30
Work= 259.8 Joule
>> test 2
force = 20
distance= 4
teta = 15
Work= 77.3 Joule
>> test 3
force = 30
distance= 30
teta = 60
Work= 450.0 Joule
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
Q,A
V=Q/A
Stop
4. Coding In MatLab
%Program Computer to Fluid Velocity
%Input
Q=input ('Debit = ' );
A=input ('Area = ' );
%process
V=Q/A;
%output
fprintf( '\nFluid Velocity=%8.1f' ,V) ;disp([ ' m/s^2']);
5. Testing Program
>> test 1
Debit = 30
Area = 2
Fluid Velocity= 15.0 m/s^2
>> test 2
Debit = 40
Area = 4
Fluid Velocity= 10.0 m/s^2
>> test 3
Debit = 50
Area = 10
Fluid Velocity= 5.0 m/s^2
2. Data Structure
Start
m, c
T=2*pi*sqrt(m/c)
Stop
4. Coding In MatLab
%Program Computer to Period of Spring
%Input
m=input ('mass = ' );
c=input ('constanta = ' );
%process
T=2*pi*sqrt(m/c);
%output
fprintf( '\nPeriod of Spring=%8.1f' ,T) ;disp([ ' second ']);
5. Testing Program
>> test 1
mass = 20
constanta = 15
Period of Spring= 7.3 second
>> test 2
mass = 45
constanta = 15
Period of Spring= 10.9 second
>> test 3
mass = 60
constanta = 15
Period of Spring= 12.6 second
2. Data Structure
3. Algorithm Program
Algorithm Use Flowchart
Start
lo, t1, t2
lo*(1+(a*(t2-t1)));
Stop
4. Coding In MatLab
%Program Computer to Long expension coefficient
%Input
Lo=input ('initial length = ' );
T1=input ('Temperature 1 = ' );
T2=input ('Temperature 2 = ' );
%process
a=12*(10^-6);
L=Lo*(1+(a*(T2-T1)));
%output
fprintf( '\nLong expension coefficient=%8.8f' ,L) ;disp([ ' meter ']);
5. Testing Program
>> test 1
initial length = 15
Temperature 1 = 30
Temperature 2 = 60
Long expension coefficient=15.00540000 meter
>> test 2
initial length = 30
Temperature 1 = 20
Temperature 2 = 25
Long expension coefficient=30.00180000 meter
>> test 3
initial length = 10
Temperature 1 = 25
Temperature 2 = 30
2. Data Structure
Start
m, g, al
pe = m*g*al
pe
Stop
4. Coding in MatLab
%Computer program to calculate potential energy
%Input
m=input(‘ Mass = ‘);
g=input(‘ Gravity = ‘);
al=input(‘ Altitude = ‘);
%process
pe=m*g*al;
%output
fprintf('\nPotential Energy =%8.3f',pe);disp(' joule');
5. Testing Program
a) Mass = 20
Gravity = 10
Altitude = 3
Potential Energy = 600 joule
b) Mass = 13
Gravity = 10
Altitude = 10
Potential Energy =1300 joule
c) Mass = 62
Gravity = 9.8
Altitude = 50
Potential Energy =30380 joule