-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fn := GenDisplaceFn(10, 2, 0) | ||
fmt.Println(fn(3)) | ||
fmt.Println(fn(5)) | ||
} | ||
|
||
// GenDisplaceFn forming a function with initial value except time of displace formulation | ||
func GenDisplaceFn(acceleration, initialVelocity, initialDisplacement float64) func(float64) float64 { | ||
fn := func(time float64) float64 { | ||
return 1.0/2*acceleration*time*time + initialVelocity*time + initialDisplacement | ||
} | ||
return fn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Instructions | ||
The goal of this assignment is to create a routine that solves a linear kinematics problem. | ||
|
||
## Review criterialess | ||
This assignment is worth a total of 10 points. | ||
|
||
Test the program by running it twice and testing it with two different sets of values for acceleration, initial velocity, initial displacement, and time. Give 3 points if the program works correctly for one set of values, and give 3 more points if the program works correctly for the other set of values. | ||
|
||
Examine the code. If the code contains a function called GenDisplaceFn() which takes three float64 arguments, acceleration a, initial velocity vo, and initial displacement so and returns a function, then give another 2 points. If the function returned by GenDisplaceFn() is used to compute the time, give another 2 points. | ||
|
||
## Specific Instructions | ||
|
||
Let us assume the following formula for displacements as a function of time t, acceleration a, initial velocity vo, and initial displacement so. | ||
|
||
s =½ a t2 + vot + so | ||
|
||
Write a program which first prompts the user to enter values for acceleration, initial velocity, and initial displacement. Then the program should prompt the user to enter a value for time and the program should compute the displacement after the entered time. | ||
|
||
You will need to define and use a function called GenDisplaceFn() which takes three float64 arguments, acceleration a, initial velocity vo, and initial displacement so. GenDisplaceFn() should return a function which computes displacement as a function of time, assuming the given values acceleration, initial velocity, and initial displacement. The function returned by GenDisplaceFn() should take one float64 argument t, representing time, and return one float64 argument which is the displacement travelled after time t. | ||
|
||
For example, let’s say that I want to assume the following values for acceleration, initial velocity, and initial displacement: a = 10, vo = 2, so = 1. I can use the following statement to call GenDisplaceFn() to generate a function fn which will compute displacement as a function of time. | ||
|
||
fn := GenDisplaceFn(10, 2, 1) | ||
|
||
Then I can use the following statement to print the displacement after 3 seconds. | ||
|
||
fmt.Println(fn(3)) | ||
|
||
And I can use the following statement to print the displacement after 5 seconds. | ||
|
||
fmt.Println(fn(5)) |