如果 f′(a) 存在,则称 f 在 a 处是可微(differentiable)的。 如果 f 在一个区间内的每个数上都是可微的,则此函数在此区间中是可微的。导数 f′(x) 解释为 f(x) 相对于 x 的瞬时(instantaneous)变化率。 所谓的瞬时变化率是基于 x 中的变化 h,且 h 接近 0。
举例:u=f(x)=3x2−4x:
deff(x):return3 * x ** 2-4 * x
defnumerical_lim(f,x,h):return (f(x+h)-f(x)) / h
h = 0.1for i in range(5):
print(f'h={h:.5f}, numerical limit={numerical_lim(f, 1, h):.5f}')
h *= 0.1
%matplotlib inline
import numpy as np
from IPython import display
from matplotlib import pyplot as plt
defuse_svg_display(): display.set_matplotlib_formats('svg')
defset_figsize(figsize=(3.5, 2.5)): use_svg_display()
plt.rcParams['figure.figsize'] = figsize
defset_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend):"""设置matplotlib的轴""" axes.set_xlabel(xlabel)
axes.set_ylabel(ylabel)
axes.set_xscale(xscale)
axes.set_yscale(yscale)
axes.set_xlim(xlim)
axes.set_ylim(ylim)
if legend:
axes.legend(legend)
axes.grid()
defplot(X, Y=None, xlabel=None, ylabel=None, legend=None, xlim=None,
ylim=None, xscale='linear', yscale='linear',
fmts=('-', 'm--', 'g-.', 'r:'), figsize=(3.5, 2.5), axes=None):"""绘制数据点"""if legend isNone:
legend = []
set_figsize(figsize)
axes = axes if axes else plt.gca()
# 如果X有一个轴,输出Truedefhas_one_axis(X):return (hasattr(X, "ndim") and X.ndim == 1or isinstance(X, list)
andnot hasattr(X[0], "__len__"))
if has_one_axis(X):
X = [X]
if Y isNone:
X, Y = [[]] * len(X), X
elif has_one_axis(Y):
Y = [Y]
if len(X) != len(Y):
X = X * len(Y)
axes.cla()
for x, y, fmt in zip(X, Y, fmts):
if len(x):
axes.plot(x, y, fmt)
else:
axes.plot(y, fmt)
set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend)
x = np.arange(0, 3, 0.1)
plot(x, [f(x), 2 * x - 3], 'x', 'f(x)', legend=['f(x)', 'Tangent line (x=1)'])
C:\Users\Administrator\AppData\Local\Temp\ipykernel_9800\3988637146.py:7: DeprecationWarning: `set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()` display.set_matplotlib_formats('svg')
偏导数
设 y=f(x1,x2,...xn) 是一个具有 n 个变量的函数,y 关于第 i 个参数 xn 的偏导数为:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2020-04-18 Sphinx + GitHub + ReadtheDocs 创建电子书