codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
% Header, overrides base % Make sure that the sphinx doc style knows who it inherits from. \def\sphinxdocclass{article} % Declare the document class \documentclass[letterpaper,10pt,english]{d:/Anaconda/lib/site-packages/sphinx/texinputs/sphinxhowto} % Imports \usepackage[utf8]{inputenc} \DeclareUnicodeCharacter{00A0}{\\nobreakspace} \usepackage[T1]{fontenc} \usepackage{babel} \usepackage{times} \usepackage{import} \usepackage[Bjarne]{d:/Anaconda/lib/site-packages/sphinx/texinputs/fncychap} \usepackage{longtable} \usepackage{d:/Anaconda/lib/site-packages/sphinx/texinputs/sphinx} \usepackage{multirow} \usepackage{amsmath} \usepackage{amssymb} \usepackage{ucs} \usepackage{enumerate} % Used to make the Input/Output rules follow around the contents. \usepackage{needspace} % Pygments requirements \usepackage{fancyvrb} \usepackage{color} % ansi colors additions \definecolor{darkgreen}{rgb}{.12,.54,.11} \definecolor{lightgray}{gray}{.95} \definecolor{brown}{rgb}{0.54,0.27,0.07} \definecolor{purple}{rgb}{0.5,0.0,0.5} \definecolor{darkgray}{gray}{0.25} \definecolor{lightred}{rgb}{1.0,0.39,0.28} \definecolor{lightgreen}{rgb}{0.48,0.99,0.0} \definecolor{lightblue}{rgb}{0.53,0.81,0.92} \definecolor{lightpurple}{rgb}{0.87,0.63,0.87} \definecolor{lightcyan}{rgb}{0.5,1.0,0.83} % Needed to box output/input \usepackage{tikz} \usetikzlibrary{calc,arrows,shadows} \usepackage[framemethod=tikz]{mdframed} \usepackage{alltt} % Used to load and display graphics \usepackage{graphicx} \graphicspath{ {figs/} } \usepackage[Export]{adjustbox} % To resize % used so that images for notebooks which have spaces in the name can still be included \usepackage{grffile} % For formatting output while also word wrapping. \usepackage{listings} \lstset{breaklines=true} \lstset{basicstyle=\small\ttfamily} \def\smaller{\fontsize{9.5pt}{9.5pt}\selectfont} %Pygments definitions \makeatletter \def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax% \let\PY@ul=\relax \let\PY@tc=\relax% \let\PY@bc=\relax \let\PY@ff=\relax} \def\PY@tok#1{\csname PY@tok@#1\endcsname} \def\PY@toks#1+{\ifx\relax#1\empty\else% \PY@tok{#1}\expandafter\PY@toks\fi} \def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{% \PY@it{\PY@bf{\PY@ff{#1}}}}}}} \def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}} \expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} \expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf} \expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} \expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit} \expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}} \expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}} \expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}} \expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}} \expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}} \expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} \expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} \expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}} \expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \def\PYZbs{\char`\\} \def\PYZus{\char`\_} \def\PYZob{\char`\{} \def\PYZcb{\char`\}} \def\PYZca{\char`\^} \def\PYZam{\char`\&} \def\PYZlt{\char`\<} \def\PYZgt{\char`\>} \def\PYZsh{\char`\#} \def\PYZpc{\char`\%} \def\PYZdl{\char`\$} \def\PYZhy{\char`\-} \def\PYZsq{\char`\'} \def\PYZdq{\char`\"} \def\PYZti{\char`\~} % for compatibility with earlier versions \def\PYZat{@} \def\PYZlb{[} \def\PYZrb{]} \makeatother %Set pygments styles if needed... \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867} \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969} \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502} \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0} \newenvironment{ColorVerbatim} {\begin{mdframed}[% roundcorner=1.0pt, % backgroundcolor=nbframe-bg, % userdefinedwidth=1\linewidth, % leftmargin=0.1\linewidth, % innerleftmargin=0pt, % innerrightmargin=0pt, % linecolor=nbframe-border, % linewidth=1pt, % usetwoside=false, % everyline=true, % innerlinewidth=3pt, % innerlinecolor=nbframe-bg, % middlelinewidth=1pt, % middlelinecolor=nbframe-bg, % outerlinewidth=0.5pt, % outerlinecolor=nbframe-border, % needspace=0pt ]} {\end{mdframed}} \newenvironment{InvisibleVerbatim} {\begin{mdframed}[leftmargin=0.1\linewidth,innerleftmargin=3pt,innerrightmargin=3pt, userdefinedwidth=1\linewidth, linewidth=0pt, linecolor=white, usetwoside=false]} {\end{mdframed}} \renewenvironment{Verbatim}[1][\unskip] {\begin{alltt}\smaller} {\end{alltt}} % Help prevent overflowing lines due to urls and other hard-to-break % entities. This doesn't catch everything... \sloppy % Document level variables \title{CSMATH-hw1} \date{April 02, 2014} \release{} \author{Unknown Author} \renewcommand{\releasename}{} % TODO: Add option for the user to specify a logo for his/her export. \newcommand{\sphinxlogo}{} % Make the index page of the document. \makeindex % Import sphinx document type specifics. % Body % Start of the document \begin{document} \maketitle % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}1{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{o}{\PYZpc{}}\PY{k}{pylab} \PY{n}{inline} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{alltt}Populating the interactive namespace from numpy and matplotlib \end{alltt} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}2{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{k+kn}{from} \PY{n+nn}{scipy} \PY{k+kn}{import} \PY{n}{optimize} \PY{k}{as} \PY{n}{opt} \PY{k}{def} \PY{n+nf}{lossFunc}\PY{p}{(}\PY{n}{p}\PY{p}{,} \PY{n}{y}\PY{p}{,} \PY{n}{x}\PY{p}{,} \PY{n}{lamb}\PY{p}{)}\PY{p}{:} \PY{n}{y}\PY{o}{=}\PY{n}{asarray}\PY{p}{(}\PY{n}{y}\PY{p}{)} \PY{n}{x}\PY{o}{=}\PY{n}{asarray}\PY{p}{(}\PY{n}{x}\PY{p}{)} \PY{n}{f}\PY{o}{=}\PY{n}{poly1d}\PY{p}{(}\PY{n}{p}\PY{p}{)} \PY{k}{return} \PY{n}{hstack}\PY{p}{(}\PY{p}{(}\PY{n}{y}\PY{o}{\PYZhy{}}\PY{n}{f}\PY{p}{(}\PY{n}{x}\PY{p}{)}\PY{p}{,} \PY{n}{asarray}\PY{p}{(}\PY{n}{p}\PY{p}{)}\PY{o}{*}\PY{p}{(}\PY{n}{lamb}\PY{o}{/}\PY{l+m+mf}{2.}\PY{p}{)}\PY{o}{*}\PY{o}{*}\PY{l+m+mf}{0.5}\PY{p}{)}\PY{p}{)} \PY{k}{def} \PY{n+nf}{convenience}\PY{p}{(}\PY{n}{degree}\PY{p}{,} \PY{n}{n}\PY{p}{,} \PY{n}{regular}\PY{o}{=}\PY{n+nb+bp}{False}\PY{p}{,} \PY{n}{lamb}\PY{o}{=}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{:} \PY{l+s+sd}{ur\PYZsq{}\PYZsq{}\PYZsq{}} \PY{l+s+sd}{ 一个便利函数,指定需要的多项式拟合曲线次数 degree, 以及生成的带噪声点个数 n, } \PY{l+s+sd}{ 画拟合曲线, 不返回值} \PY{l+s+sd}{ } \PY{l+s+sd}{ PARAMS} \PY{l+s+sd}{ \PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}} \PY{l+s+sd}{ degree: 多项式次数} \PY{l+s+sd}{ n: 加噪声采样点个数} \PY{l+s+sd}{ } \PY{l+s+sd}{ RETURNS} \PY{l+s+sd}{ \PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}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s}{\PYZsq{}}\PY{p}{,} \PY{n}{lw}\PY{o}{=}\PY{l+m+mi}{2}\PY{p}{,} \PY{n}{label}\PY{o}{=}\PY{l+s}{\PYZsq{}}\PY{l+s}{polynomial fit}\PY{l+s}{\PYZsq{}}\PY{p}{)} \PY{n}{legend}\PY{p}{(}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}3{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{l+s}{\PYZsq{}}\PY{l+s}{3次多项式拟合 10 点}\PY{l+s}{\PYZsq{}} \PY{n}{convenience}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{10}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{center} \includegraphics[max size={\textwidth}{\textheight}]{CSMATH-hw1_files/CSMATH-hw1_2_0.png} \par \end{center} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}4{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{l+s}{\PYZsq{}}\PY{l+s}{9次多项式拟合 10 点}\PY{l+s}{\PYZsq{}} \PY{n}{convenience}\PY{p}{(}\PY{l+m+mi}{9}\PY{p}{,} \PY{l+m+mi}{10}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{center} \includegraphics[max size={\textwidth}{\textheight}]{CSMATH-hw1_files/CSMATH-hw1_3_0.png} \par \end{center} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}5{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{l+s}{\PYZsq{}}\PY{l+s}{9次多项式拟合 15 点}\PY{l+s}{\PYZsq{}} \PY{n}{convenience}\PY{p}{(}\PY{l+m+mi}{9}\PY{p}{,} \PY{l+m+mi}{15}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{center} \includegraphics[max size={\textwidth}{\textheight}]{CSMATH-hw1_files/CSMATH-hw1_4_0.png} \par \end{center} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}6{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{l+s}{\PYZsq{}}\PY{l+s}{9次多项式拟合 100 点}\PY{l+s}{\PYZsq{}} \PY{n}{convenience}\PY{p}{(}\PY{l+m+mi}{9}\PY{p}{,} \PY{l+m+mi}{100}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{center} \includegraphics[max size={\textwidth}{\textheight}]{CSMATH-hw1_files/CSMATH-hw1_5_0.png} \par \end{center} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}7{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{l+s}{\PYZsq{}}\PY{l+s}{引入正则化, 9次多项式拟合 10 点}\PY{l+s}{\PYZsq{}} \PY{n}{convenience}\PY{p}{(}\PY{l+m+mi}{9}\PY{p}{,} \PY{l+m+mi}{10}\PY{p}{,} \PY{n}{regular}\PY{o}{=}\PY{n+nb+bp}{True}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{center} \includegraphics[max size={\textwidth}{\textheight}]{CSMATH-hw1_files/CSMATH-hw1_6_0.png} \par \end{center} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}8{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \PY{l+s}{\PYZsq{}}\PY{l+s}{引入正则化, 9次多项式拟合 10 点}\PY{l+s}{\PYZsq{}} \PY{n}{convenience}\PY{p}{(}\PY{l+m+mi}{9}\PY{p}{,} \PY{l+m+mi}{10}\PY{p}{,} \PY{n}{regular}\PY{o}{=}\PY{n+nb+bp}{True}\PY{p}{,} \PY{n}{lamb}\PY{o}{=}\PY{n}{np}\PY{o}{.}\PY{n}{e}\PY{o}{*}\PY{o}{*}\PY{o}{\PYZhy{}}\PY{l+m+mi}{18}\PY{p}{)} \end{Verbatim} \vspace{-0.2\baselineskip} \end{ColorVerbatim} % If the first block is an image, minipage the image. Else % request a certain amount of space for the input text. \needspace{4\baselineskip} % Add document contents. \begin{InvisibleVerbatim} \vspace{-0.5\baselineskip} \begin{center} \includegraphics[max size={\textwidth}{\textheight}]{CSMATH-hw1_files/CSMATH-hw1_7_0.png} \par \end{center} \end{InvisibleVerbatim} % Make sure that atleast 4 lines are below the HR \needspace{4\baselineskip} \vspace{6pt} \makebox[0.1\linewidth]{\smaller\hfill\tt\color{nbframe-in-prompt}In\hspace{4pt}{[}{]}:\hspace{4pt}}\\* \vspace{-2.65\baselineskip} \begin{ColorVerbatim} \vspace{-0.7\baselineskip} \begin{Verbatim}[commandchars=\\\{\}] \end{Verbatim} \vspace{0.3\baselineskip} \end{ColorVerbatim} \renewcommand{\indexname}{Index} \printindex % End of document \end{document}
Private
[
?
]
Run code
Submit