#!/usr/bin/env python3from sympy import pprint, symbols, sin, cos, log, Derivative, plot
print('5.')
print('(a)')
x, a, b = symbols('x, a, b')
f = a * cos(log(x)) + b * sin(log(x))
d1 = Derivative(f, x, 1).doit()
d2 = Derivative(f, x, 2).doit()
eq = x ** 2 * d2 + x * d1 + f
for o in [eq, eq.expand()]:
pprint(o)
print()
print('(b)')
n = symbols('n', integer=True, nonnegative=True)
for n inrange(5):
g = x ** n * Derivative(f, x, n)
for o in [g, g.doit()]:
pprint(o)
print()
p = plot(*[Derivative(f.subs({a: 2, b: 3}), x, n).doit() for n inrange(5)],
(x, 0.1, 10.1),
ylim=(-5, 5),
show=False,
legend=True)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color inzip(p, colors):
o.line_color = color
p.show()
p.save('sample5.png')
0 コメント:
コメントを投稿