0

I have a formula which calculates the position of a point in space:

x = d[0]*math.cos(t)

and I would like to be able to call out the position in a certain time. I thought that maybe I could use for loop 'for' so I can know the positions in the intervals for (t = from 1 to 40 for example) but what if I want to know the value for example in t = 2.564. Is there a way to call out this value for a non-integer argument?

MSeifert
  • 145,886
  • 38
  • 333
  • 352
Blazej Kowalski
  • 367
  • 1
  • 6
  • 16
  • Why can't you simple plug `t=2.564` in? Is this some kind of differential equation? What is `d[0]`, just some number? – syntonym Jul 17 '17 at 13:05
  • 1
    `math.cos` accepts non-integers (but not complex numbers - for those you need to use `cmath`) arguments. So you should be able to use any rational or integral value. – MSeifert Jul 17 '17 at 13:06
  • But then I would have to rewrite the whole expression and simply input the desired value of t instead of t. But if the expression is more complicated this doesn't seem like an efficient solution. Is there maybe a way to define an equation and the simply call x(2.564) in the console to receive a value? – Blazej Kowalski Jul 17 '17 at 13:09
  • I'm confused as to what your question is, but it sounds like you might possibly want `functools.partial()` – Brian Jul 17 '17 at 13:13
  • Ok. Sorry for the confusion but I am still a beginner. Seems that simply defining a function works here. and then I can call the function for any argument t. – Blazej Kowalski Jul 17 '17 at 13:17
  • Yes @BlazejKowalski you could define this as a function which takes in a parameter of t, and then accept a user input for a value to calculate and then this can calculate from there. – Professor_Joykill Jul 17 '17 at 13:31

0 Answers0