Latex 绘制函数图像

39 篇文章 5 订阅
30 篇文章 8 订阅

前言

又是关于机器学习那本书里的插图问题,里面有一些函数图形。现在看看怎么使用latex把它们画出来。
这就是《机器学习》周志华,第98页的两个函数图像,貌似树上的坐标轴是不正确的,第二张图的横坐标应该扩大10倍,才有那种效果。

使用到的包:

\usepackage{tikz}

示例代码:

\documentclass[11pt,UTF8]{ctexart}
\usepackage{tikz}
\begin{document}
    \begin{figure}
    \begin{tikzpicture}
    \draw[->](-1.2,0)--(1.2,0)node[left,below,font=\tiny]{$x$};
    \draw[->](0,-0.2)--(0,1.2)node[right,font=\tiny]{$y$};
    \foreach \x in {-1,0,1}{\draw(\x,0)--(\x,0.05)node[below,outer sep=2pt,font=\tiny]at(\x,0){\x};}
    \foreach \y in {1}{\draw(0,\y)--(0.05,\y)node[left,outer sep=2pt,font=\tiny]at(0,\y){\y};}
    \draw[color=red, thick,smooth,domain=0:1]plot(\x,1);
    \draw[color=red, thick,smooth,domain=-1:-0.02]plot(\x,0);
    \draw[color=red,smooth]circle(0.02);
    \end{tikzpicture}
    \end{figure}

\end{document}

运行结果:
这里写图片描述
表达式:

sgn(x)={1,x0;0,x<0;

示例代码:

\documentclass[landscape, 12pt]{ctexart}
\usepackage{tikz}
\begin{document}
	\begin{figure}
	\begin{tikzpicture}
	\draw[->](-1.2,0)--(1.2,0)node[left,below,font=\tiny]{$x$};
	\draw[->](0,-0.2)--(0,1.2)node[right,font=\tiny]{$y$};
	\draw[dashed](-1.2,1)--(1.2,1);
	\foreach \x in {-1,-0.5,0,0.5,1}{\draw(\x,0)--(\x,0.05)node[below,outer sep=2pt,font=\tiny]at(\x,0){\x};}
	\foreach \y in {0.5,1}{\draw(0,\y)--(0.05,\y)node[left,outer sep=2pt,font=\tiny]at(0,\y){\y};}
	\draw[color=red ,domain=-1.2:1.2]plot(\x,{1/(1+(e^(-1*(\x))))});
	\end{tikzpicture}
	\end{figure}
\end{document}

运行结果:

这里写图片描述
表达是

sigmoid(x)=11+ex

  • 4
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值