
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  CSCE 150A -- Problem Solving Using Computers
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[pdftex]{beamer}

\input{beamerPreamble}
\usepackage[T1]{fontenc}
%\usepackage{tikz}\text
%\usetikzlibrary{shapes.callout}

\title[CSCE150A]{Computer Science \& Engineering 150A\\
    Problem Solving Using Computers -- Laboratory}
\subtitle{Lecture 04 - Math Functions}

\author[~]{Shuai Xie\vskip 1\baselineskip (Adapted from Derrick Stolee, Lin Liu \& Shuai Xie )} %

\date{Spring 2010}
%\usepackage{listings}
\usepackage{multicol}
\begin{document}
%\lstset{language=C}
\begin{frame}
  \titlepage
  \begin{center}
     \vfill
     \email{sxie@cse.unl.edu}
  \end{center}
\end{frame}


\section{Review}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Review: \texttt{printf, varial data type}}
  \framesubtitle{~}

\texttt{gcc -o hi hello.c}\\
\texttt{./hi}\\
\vskip 1\baselineskip
\texttt{printf("format string", variable list);}\\

\vskip 1\baselineskip

	\begin{center}
	\begin{tabular}[h]{c|c}
		Placeholder & Variable Type\\
		\hline
		\texttt{\%d} & \texttt{int}\\
		\hline
		\texttt{\%f} & \texttt{double}\\
		\hline
		\texttt{\%c} & \texttt{char}\\
	\end{tabular}\end{center}
\texttt{\%.10f$-$$-$output 10 digits after the decimal point.}\\	
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Preview-Input: \texttt{scanf}}
  \framesubtitle{~}

\begin{itemize}
	\item \texttt{scanf("format string", \texttt{\&}variables...););}
	\begin{itemize}
		\item Use the same as $\texttt{printf}$, except for \texttt{\&} before variables.
		\[\text{\texttt{scanf("\%d \%lf", \&myInt, \&myDouble);}}\]
		\item Be sure to define variables ahead of time!
		\item Remember to keep the same format string when input.	\end{itemize}
\end{itemize}
\vskip 1\baselineskip

	\begin{center}
	\begin{tabular}[h]{c|c}
		Placeholder & Variable Type\\
		\hline
		\texttt{\%d} & \texttt{int}\\
		\hline
		\texttt{\%lf} & \texttt{double}\\
		\hline
		\texttt{\%c} & \texttt{char}\\
	\end{tabular}\end{center}

\end{frame} %-------------------------------------------------------------|

\section{Basic tools}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Basic tools: \texttt{Unix shortcut key}}
  \framesubtitle{~}
\vskip 1\baselineskip
\texttt{Tab key $-$$-$ to complete a partially typed filename.}\\
\vskip 1\baselineskip
\texttt{ArrowUp key $-$$-$ to find the previously inputted command.}\\
\vskip 1\baselineskip
\texttt{Paste source code $-$$-$ copy in browser, right click in pico.}\\
\vskip 1\baselineskip
\texttt{Ctrl \& c $-$$-$ to stop current command.}\\
\end{frame} %-------------------------------------------------------------|



\section{Math Functions}

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Math: Operations}
  \framesubtitle{~}

	\large

 \begin{itemize}
 	\item $=$ \qquad Set a value
\[\text{\texttt{int myVariable = 50;}}\]
	\item $+$ , $-$ , $*$ , $/$
\[\text{\texttt{a = b + c;\qquad a = b - c;}}\]
\[\text{\texttt{a = b * c;\qquad a = b / c;}}\]
	\item $\%$ \qquad Remainder
\[\text{\texttt{remain = E \% F;} }\]
	Be careful of rounding!  When in doubt, use doubles.\\
	Or, use $25.0$, $-1.0$, (add $.0$) when using integer literals
\end{itemize}
\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Preview-Math: Mathematical Formula}
  \framesubtitle{~}

	\large

	\vskip 1\baselineskip
\begin{tabular}[h]{cc}
	Math Expression & C Code \\
	\hline
	$\frac{ab}{1-c}$ & \texttt{(a * b) / (1 - c)}\\
	$x^2+2y+1$ & \texttt{x * x + 2 * y + 1}\\
\end{tabular}
	
	\vskip 1\baselineskip
-- Watch order of operations!

\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Math: Functions}
  \framesubtitle{~}

	\large

\begin{multicols}{1}
	\texttt{abs(x)} \\
	\texttt{fabs(x)} \\
	\texttt{sin(x)} \\
	\texttt{cos(x)} \\
	\texttt{pow(x,y)} \\
	\texttt{sqrt(x)} \\
    \texttt{ceil(x)} \\
    \texttt{floor(x)} \\

	\end{multicols}
	
	
\begin{itemize}
  \item \#include $<$math.h$>$
  \item gcc -lm -o pow pow.c
  \item  
  \item On Page:121 of the Textbook
\end{itemize}	

\vspace{2in}
\end{frame} %-------------------------------------------------------------|

\begin{frame} %-----------------------------------------------------------|
  \frametitle{Math: Compound Functions}
  \framesubtitle{~}

	\large

\begin{tabular}[h]{cc}
	Math Expression & C Code \\
	\hline
	$3\sin(x-1)$ & \texttt{3.0 * sin(x-1)}\\
	$\left|\frac{1}{\sqrt{1-x^2}}\right|$ & \texttt{fabs(1.0/sqrt(1-pow(x,2)))}\\
\end{tabular}

\vspace{2in}
\end{frame} %-------------------------------------------------------------|



\end{document}
