Calculations within Matrix Tikz
How can I tell tikz to make a calculation within a matrix. The same syntax outside does not work within as is shown in this MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]| {f(3)}3\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
This outputs
tikz-pgf tikz-matrix tikz-calc
add a comment |
How can I tell tikz to make a calculation within a matrix. The same syntax outside does not work within as is shown in this MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]| {f(3)}3\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
This outputs
tikz-pgf tikz-matrix tikz-calc
2
Replace{f(3)}
in the matrix by{pgfmathparse{f(3)}pgfmathprintnumber{pgfmathresult}}
or, which seems more appropriate,{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}
?
– marmot
12 hours ago
@Marmot. I was just going to try that! Thank Marmot! Yes it works.
– MathScholar
12 hours ago
add a comment |
How can I tell tikz to make a calculation within a matrix. The same syntax outside does not work within as is shown in this MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]| {f(3)}3\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
This outputs
tikz-pgf tikz-matrix tikz-calc
How can I tell tikz to make a calculation within a matrix. The same syntax outside does not work within as is shown in this MWE:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]| {f(3)}3\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
This outputs
tikz-pgf tikz-matrix tikz-calc
tikz-pgf tikz-matrix tikz-calc
asked 12 hours ago
MathScholarMathScholar
78629
78629
2
Replace{f(3)}
in the matrix by{pgfmathparse{f(3)}pgfmathprintnumber{pgfmathresult}}
or, which seems more appropriate,{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}
?
– marmot
12 hours ago
@Marmot. I was just going to try that! Thank Marmot! Yes it works.
– MathScholar
12 hours ago
add a comment |
2
Replace{f(3)}
in the matrix by{pgfmathparse{f(3)}pgfmathprintnumber{pgfmathresult}}
or, which seems more appropriate,{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}
?
– marmot
12 hours ago
@Marmot. I was just going to try that! Thank Marmot! Yes it works.
– MathScholar
12 hours ago
2
2
Replace
{f(3)}
in the matrix by {pgfmathparse{f(3)}pgfmathprintnumber{pgfmathresult}}
or, which seems more appropriate, {pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}
?– marmot
12 hours ago
Replace
{f(3)}
in the matrix by {pgfmathparse{f(3)}pgfmathprintnumber{pgfmathresult}}
or, which seems more appropriate, {pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}
?– marmot
12 hours ago
@Marmot. I was just going to try that! Thank Marmot! Yes it works.
– MathScholar
12 hours ago
@Marmot. I was just going to try that! Thank Marmot! Yes it works.
– MathScholar
12 hours ago
add a comment |
1 Answer
1
active
oldest
votes
I'll be happy to remove this if you want to remove your question, or feel it is not appropriate.
documentclass{article}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]|
{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
2
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473511%2fcalculations-within-matrix-tikz%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'll be happy to remove this if you want to remove your question, or feel it is not appropriate.
documentclass{article}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]|
{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
2
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
add a comment |
I'll be happy to remove this if you want to remove your question, or feel it is not appropriate.
documentclass{article}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]|
{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
2
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
add a comment |
I'll be happy to remove this if you want to remove your question, or feel it is not appropriate.
documentclass{article}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]|
{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
I'll be happy to remove this if you want to remove your question, or feel it is not appropriate.
documentclass{article}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{matrix,calc}
usetikzlibrary{intersections}
begin{document}
begin{center}
begin{tikzpicture}[scale=.8, declare function={f(x)=1/ln(2)*ln(x);}]
draw[step=1.0,gray,thin,dotted] (-.5,-3) grid (8.5,4);
draw [-latex] (-.5,0) -- (8.5,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-3.5) -- (0,4) node [left] {$y$};
foreach x/xtext in {1/1,2/2,3/3,4/4,5/5,6/6}
draw[xshift=x cm] (0pt,3pt) -- (0pt,0pt)
node[below=2pt,fill=white,font=normalsize]
{$xtext$};
foreach y/ytext in {-2/-2,-1/-1, 1/1,2/2,3/3}
draw[yshift=y cm] (2pt,0pt) -- (-2pt,0pt)
node[left,fill=white,font=normalsize]
{$ytext$};
draw[name path=curve,domain=.17:8.5,samples=200,variable=x,red,<->,thick]
plot ({x},{f(x)});
draw[fill=red,red] (1,{f(1)}) circle (3pt) node {};
draw[fill=red,red] (2,{f(2)}) circle (3pt) node {};
draw[fill=red,red] (4,{f(4)}) circle (3pt) node {};
draw[fill=red,red] (8,{f(8)}) circle (3pt) node {};
draw[fill=red,red] (.5,{f(.5)}) circle (3pt) ;
draw[fill=red,red] (.25,{f(.25)}) circle (3pt) node {$$};
node at (3.5,3.5) [text=red,fill=white] {$f(x)=log_{2} x, text{or} 2^{y}=x$};
matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},draw,inner
sep=0pt,ampersand replacement=&] (mat1)
at (-5,0){
|[fill=green!40!gray,text width=15mm]| x, text{or} 2^{y} & |
[fill=green!40!gray,text width=11mm]| f(x) \
|[text width=15mm]| 1 & |[text
width=11mm]| 0\
|[text width=15mm]| 2
& |[text width=11mm]| 1\
|[text width=15mm]| 4
& |[text width=11mm]| 2\
|[text width=15mm]| 8
& |[text width=11mm]|
{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}\
|[text width=15mm]| frac{1}{2}
& |[text width=11mm]| -1\
|[text width=15mm]| frac{1}{4}
& |[text width=11mm]| -2\
};
end{tikzpicture}
end{center}
end{document}
answered 12 hours ago
marmotmarmot
97.6k4112216
97.6k4112216
2
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
add a comment |
2
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
2
2
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
no it is okay to leave. It may be helpful to someone else!
– MathScholar
12 hours ago
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473511%2fcalculations-within-matrix-tikz%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Replace
{f(3)}
in the matrix by{pgfmathparse{f(3)}pgfmathprintnumber{pgfmathresult}}
or, which seems more appropriate,{pgfmathparse{f(8)}pgfmathprintnumber{pgfmathresult}}
?– marmot
12 hours ago
@Marmot. I was just going to try that! Thank Marmot! Yes it works.
– MathScholar
12 hours ago