I've tried a few formats and ideas, but the syntax is kind of confusing. Help is appreciated, danke.
Asked
Active
Viewed 660 times
-1
-
3I would start with learning about Python's [arithmetic operators](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) and the [`math`](https://docs.python.org/3/library/math.html) module. Otherwise, the main thing to keep in mind is that `sin^5(...)` is really `(sin(...))^5`. – chepner Jul 08 '21 at 13:59
-
Exactly what I was looking for, Chepner, thanks. – KarlMarxsDog Jul 08 '21 at 14:15
4 Answers
1
Only with python built-in functios:
import math
r = math.e**(math.cos(theta)) - 2 * math.cos(4 * theta) + math.sin(theta/12)**5
With Sympy(for symbolic computation):
from sympy import Symbol, cos, sin, E
t = Symbol('Θ')
E**(cos(t)) - 2 * cos(4 * t) + sin(t/12)**5
Result:

Hugo Amorim
- 23
- 6
-
Upvoted because this is the only answer that suggests the `sympy` alternative. – Stef Jul 08 '21 at 14:26
0
from math import exp, cos, sin
theta = 0.1 # Just as an example
r = exp(cos(theta)) - 2 * cos(4 * theta) + sin(theta / 12) ** 5

Pippet39
- 127
- 4
0
A very straightforward, but naive approach would be to just use the math
library, which is a standard library in python.
import math
def r(theta):
return math.pow(math.e, math.cos(theta)) - 2 * math.cos(4*theta) + math.pow(math.sin(theta/12), 5)
better results are possible with libraries for scientific computing, like numpy or other members of the scipy ecosystem.

Simon B
- 92
- 1
- 6
-
I've never ever seen that second interpretation of sin^5(x) - citation needed... – Alnitak Jul 08 '21 at 14:02
0
How about something like this?
import matplotlib.pyplot as plt
import numpy as np
theta = np.linspace(-2*np.pi, 2*np.pi, 10)
r = np.exp(np.cos(theta)) - 2*np.cos(4*theta) + np.sin(theta/12)**5
plt.plot(theta,r)
plt.savefig('parametric.jpg')

user32882
- 5,094
- 5
- 43
- 82