Answer the question
In order to leave comments, you need to log in
A simple question about Python [functions]?
Hello! A question. Let's say we have some kind of mathematical formula, let's say modulations:
x(t) = sin(omega*t + phi)
We need to set a range of values for omega, t and phi. And, accordingly, to build graphs approximate for these values.
How to implement this in Python? (approximate syntax what should be?)
Most of all confuses the phrase "range of values", because of it and the question.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
The graph is built not by function, but by points, the coordinates of which are obtained by applying the function to a certain range of argument values. The algorithm (simplified) is:
It is best to take Matplotlib as a UI library , there are good tutorials on it, for example - one , another , third and others .
Tabulation of Line and Parabola Functions
>>> def f1(x):
... return 2 * x
...
>>> def f2(x):
... return x * x
...
>>> def g(func, start, end, step):
... while start <= end:
... yield start, func(start)
... start += step
...
>>> list(g(f1, -3, 3, 1))
[(-3, -6), (-2, -4), (-1, -2), (0, 0), (1, 2), (2, 4), (3, 6)]
>>>
>>> list(g(f2, 0, 10, 1))
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36), (7, 49), (8, 64), (9, 81), (10, 100)]
>>>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question