如何编写参数函数r=e^cos(θ)−python中的2cos(4θ)+sin^5(θ/12)?

kqqjbcuj  于 2021-08-25  发布在  Java
关注(0)|答案(4)|浏览(265)

我尝试了一些格式和想法,但是语法有点混乱。谢谢你的帮助,丹克。

m1m5dgzv

m1m5dgzv1#

仅使用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

结果:

dwbf0jvd

dwbf0jvd2#

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
goucqfw6

goucqfw63#

像这样的怎么样?

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

bwitn5fc

bwitn5fc4#

一种非常简单但幼稚的方法是只使用 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生态系统的其他成员,可能会有更好的结果。

相关问题