ComputersSoftware

Tabulation function: how to write a program?

Tabulation of the function is a classical problem of mathematics and programming. It consists in sequentially finding the value of f (x) for varying values of x . The results of calculations are most often output as a table of two lines. The first corresponds to x , the second corresponds to f (x) .

Theory

The algorithm for determining the values of a function consists of six steps.

  1. Selection of the initial and final value of the argument, the number of points.
  2. Calculation of the step is the value by which the argument will change.
  3. The argument is assumed to be equal to the initial value.
  4. Function calculation.
  5. Increase the argument by the step value.
  6. Repeat steps 4-5 until the required number of points is counted.

The values set in the first step are not always selected, they can be specified by the job. In practice, a situation occurs when a range of values and a step of calculations is specified. The tabulation of the function in this case does not require finding the number of points, since the condition of the termination of the calculation (point 6 of the algorithm) is the equality of the argument to the specified finite value.

Practical example

An example will help you understand how to use theory. Let a quadratic function g ( x) = x 2 + 9 be given . We compose a table of its values in the range [-2; 2], taking the number of points equal to five. From the initial data it is easy to estimate that the calculation step should be equal to 1.

In accordance with the algorithm, the next action is the calculation of g (-2), "-2" is the initial value of the function. By sequentially increasing x by one (in programming this operation is called incrementing) and defining the function g , the function is tabulated.

X

-2

-1

0

1

2

G (x)

13

10

9

10

13

Checking the correctness of the calculations is easy - you should get a graph of the parabola.

Software implementation

Creating a function table manually - a long occupation. Calculations should be performed carefully, an error in the calculation will make the remaining values also incorrect. The solution is to transfer the task to the computer.

Below is a tabulation program for the function on the so-called "pseudocode". To execute it, you must specify a function, the initial and final value of the arguments, the number of points. In the example, f (x) = 18 * x + 5 is calculated. The result of the program is the successively derived values of x , f (x) .

- Argument: = N.Value.

- Calculation step: = (N. value - K. value) / Col. Points.

- FOR (Counter: = 0 to the Number of points).

Start:

- Function: = 18 * Argument + 5.

- Argument: = H. value + Counter * Step.

- Output to the screen (Argument, Function).

The end.

The code adapts to any programming language. That is, the function's tabulation can be implemented in Pascal, C +, C # and even in the language of office programming VBA, integrated into the MS Office package.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.