-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.tex
66 lines (54 loc) · 1.63 KB
/
3.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
\documentclass[12pt, a4paper, addpoints]{exam}
\usepackage{amsmath} % For mathematical symbols
\usepackage{multicol} % For multi-column layout
\usepackage{pgfmath} % For math parsing and calculations
% Define the \expandbinomials command
\newcommand{\expandbinomials}[4]{%
% Compute intermediate terms (A, B, C)
\pgfmathparse{#1*#3} \let\A\pgfmathresult % A = a*c
\pgfmathparse{#1*#4 + #2*#3} \let\B\pgfmathresult % B = a*d + b*c
\pgfmathparse{#2*#4} \let\C\pgfmathresult % C = b*d
% Ensure A, B, and C are numeric values
\pgfmathparse{int(\A)} \let\A\pgfmathresult
\pgfmathparse{int(\B)} \let\B\pgfmathresult
\pgfmathparse{int(\C)} \let\C\pgfmathresult
% Correctly handle the signs
\ifnum\A>0 \def\signA{} \else \def\signA{-} \fi % No leading +, only - if negative
\ifnum\B>0 \def\signB{+} \else \def\signB{-} \fi
\ifnum\C>0 \def\signC{+} \else \def\signC{-} \fi
% Print the entire expression in math mode
\[
\signA
\ifnum\A=1
x^2
\else
\pgfmathprintnumber{\A}x^2
\fi
\ifnum\B=0
\else
\signB
\ifnum\absB=1
x
\else
\pgfmathprintnumber{\absB}x
\fi
\fi
\ifnum\C=0
\else
\signC\pgfmathprintnumber{\absC}
\fi
\]
}
\begin{document}
\begin{questions}
\LARGE
\question Factor the following quadratic expressions.
\setlength{\columnsep}{50pt}
\begin{multicols}{2}
\begin{parts}
\part \expandbinomials{1}{1}{11}{5} % This should output 11x^2 + 16x + 5
\part \expandbinomials{7}{11}{1}{1} % This should output 7x^2 + 18x + 11
\end{parts}
\end{multicols}
\end{questions}
\end{document}