-2

我尝试了一些格式和想法,但语法有点令人困惑。感谢帮助,danke。

函数本身

4

4 回答 4

1

仅使用 python 内置函数:

import math
r = math.e**(math.cos(theta)) - 2 * math.cos(4 * theta) + math.sin(theta/12)**5

使用 Sympy(用于符号计算):

from sympy import Symbol, cos, sin, E
t = Symbol('Θ')
E**(cos(t)) - 2 * cos(4 * t) + sin(t/12)**5

结果:

于 2021-07-08T14:12:36.990 回答
0

一个非常简单但幼稚的方法是只使用该math库,它是 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)

使用科学计算库(如 numpy 或scipy生态系统的其他成员)可以获得更好的结果。

于 2021-07-08T14:01:13.567 回答
0

这样的事情怎么样?

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')

在此处输入图像描述

于 2021-07-08T14:01:44.903 回答
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
于 2021-07-08T14:00:08.063 回答