Kennesaw State University CS 4491 Assignment 2
Kennesaw
State University
Department
of Computer Science
Advanced
Topic in Computer Science CS 4491/2
Assignment
#2: Computer Modeling
Dalibor
Labudovic
01/29/2013
Initial
Problem Statement:
1.)
Assume that the initial velocity, v0, of the free-falling object is
not zero. Develop a computational model (in the C language) that
computes the time the object takes to reach ground level and the
vertical velocity at that time instance, given the initial height,
y0.
2.)
A large tent is to be set up for a special arts display in the main
city park. The tent material is basically a circular canvas; the tent
size can be adjusted by increasing or decreasing the distance from
the center to the edge of the canvas, varying from 5 feet to 35 feet.
The cost of the event will be paid based on the circular area
occupied, $1:25 per square foot. Develop a computational model that
takes several values of the distance from the center to the outer
edge of the canvas (the radius) and provide the cost for the event.
Summary
and Purpose of the Assignment Activity:
The
purpose of the assignment is to critically analyze and abstract the
problem. With an abstraction of the problem, a mathematical model can
be created. Working with the mathematical algorithm and principles of
software development, a computational model is developed. Once a
reasonable computational model is reached then I was able to
constructed, compiled, tested and deployed the program.
Detail
Description of the Solution Used in the Project:
- To develop a C program to calculate the time and velocity for a free falling object, I initially started with a mathematical model of the problem. First I analyzed the given variables. The distance is given and constant is acceleration. The formula for distance on free falling object is , where a, as a double value, is acceleration at -9.8 m/s , d, as a double value, is distance in meters, and t , as a double value, is for time in seconds. The manipulated mathematical model for finding time of a free falling object is: . The formula for calculating the velocity of the object is , where v , a double value, is velocity in m/ and a, as a double value, is for constant acceleration,- 9.8 m/ and t , as a double value, is for time in seconds. Mathematical model provides a clear picture to the components required for the computational model. The variable d is needed from the end user. The library math.h is required to compute the algorithms. The computational model will implement the mathematical formulation . The main function will execute the formula for time, . Once the time has been calculated then the function will resume to calculate the velocity using formula, .
- To develop a computational model for determining the setup cost of tent display for marketing. The tent size ranges from 5ft to 35 ft. To calculate the area, a double value, of the tent, I will use a mathematical formula, area of a circle, . The constant is PI is a double value of 3.14159 and the r is a double value as the radius , which ranges from 5ft to 35ft. Once the area of the tent is calculated, we apply the mathematical formula , for the cost, at $1.25 per square feet.
Table
of Results:
1.)
In the C program of a free-falling object, the results are:
Source
File:
#include
<stdio.h>
#include <math.h>
int main(){
double a =
-9.8;//accelertion due to gravity
double
x;//distance
double t;//time
double
v;//initial velocity
double
vf;//final velocity
//user input
printf("\nThis
program calculates time and velocity for free falling object\n");
printf("\nProvide
distance in meters:");
scanf("%lf",
&x);
printf("\nProvide
Initial Velocity in m/s: ");
scanf("%lf",
&v);
//Calculate
final velocity
vf =
sqrt(pow(v,2) +( 2 * a * x));
//calculate time
t = (vf -
v)/(a);
//print output
printf("\nWith
initial velocity of %g m/a and distance of %g meters", v,x);
printf("\nThe
finail velocity is %g m/s and time it took to fall is %g seconds",
vf, t)
return 0;
}
2.)
Source
File:
#include <stdio.h>
#include <math.h>
#include <stdio.h>
#include <math.h>
int main(){
//data structure
double area;
double radius;
double tentcost;
const double PI =
3.14159;
//user input
printf("\nEnter
tent radius 5-35ft\n");
scanf("%lf",
&radius);
if (radius < 4){
printf("Error,
radius too small");
}
else if (radius >
35){
printf("Error,
radius too large");
}
else{
//calcualte area
area = PI *
pow(radius,2);
//calculate cost
tentcost = area *
1.25;
//print results
printf("\nTotal
area is %g sqft", area);
printf("\nTotal
cost at $1.25/sqft is $%g", tentcost);
}
return 0;
}
Discussion
of How the System Modeled can be Improved and Extended to Include
other Services:
1.)
The free-falling object program can be improved by using an animation
of the object falling by using a GUI and introducing an option of
initial velocity and final velocity. The program could also include
an option for drag co-efficiency calculations.
2.)
The cost of the tent computational model could be improved with an
introduction of a seek bar in a GUI environment.
Comments
and Conclusion:
The
interesting part of the project is distinguishing the differences
between the mathematical model and computational model. With more
complex problems, the use of translating from mathematical model to
computational model will become a required skill.
List
of References:
"Area
of a Circle." Area
of a Circle.
N.p., n.d. Web. 30 Jan. 2013.
"Kinematic
Equations and Free Fall." Kinematic
Equations and Free Fall.
N.p., n.d. Web. 30 Jan. 2013.
Script:
- Script File
Script
started on Sat 09 Feb 2013 11:22:42 PM EST
[?1l>[dlabudov@cs3
~]$ gcc -Wall freefall.c -lm
[dlabudov@cs3
~]$ ./a.out
This
program calculates time and velocity for free falling object
Provide
distance in meters:-20
Provide
Initial Velocity in m/s: 6
With
initial velocity of 6 m/a and distance of -20 meters
The
finail velocity is 20.6882 m/s and time it took to fall is -1.49879
seconds[dlabudov@cs3 ~]$ exit
exit
Script
done on Sat 09 Feb 2013 10:31:35 PM EST
- Script File
Script
started on Sat 09 Feb 2013 11:22:42 PM EST
[?1l>[dlabudov@cs3
~]$ gcc -Wall tentcost.c -lm
[dlabudov@cs3
~]$ ./a.out
Enter
tent radius 5-35ft
10
Total
area is 314.159 sqft
Total
cost at $1.25/sqft is $392.699[dlabudov@cs3 ~]$ ./a.out
Enter
tent radius 5-35ft
2
Error,
radius too small[dlabudov@cs3 ~]$ ./a.out
Enter
tent radius 5-35ft
40
Error,
radius too large[dlabudov@cs3 ~]$ exit
exit
Script
done on Sat 09 Feb 2013 11:23:34 PM EST
Comments
Post a Comment