Breaking a Loop in TikzTikZ: Cropping the Bounding BoxNested foreach loop in TikZMake tikzpicture white on...
Is there some relative to Dutch word "kijken" in German?
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
Is casting an attack cantrip from a wand an "attack action made with a magic weapon"?
What is the in-universe cost of a TIE fighter?
How can animals be objects of ethics without being subjects as well?
How do you funnel food off a cutting board?
Strange Sign on Lab Door
Does Improved Divine Strike trigger when a paladin makes an unarmed strike?
Does static make a difference for a const local variable?
What kind of hardware implements Fourier transform?
Disable the ">" operator in Rstudio linux terminal
Why doesn't "auto ch = unsigned char{'p'}" compile under C++ 17?
Would these multi-classing house rules cause unintended problems?
What is this metal M-shaped device for?
Typing Amharic inside a math equation?
Why did other German political parties disband so fast when Hitler was appointed chancellor?
Dilemma of explaining to interviewer that he is the reason for declining second interview
Can I write a book of my D&D game?
Solubility of a tribasic weak acid
Why is working on the same position for more than 15 years not a red flag?
A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?
Can I become debt free or should I file for bankruptcy? How do I manage my debt and finances?
Why does String.replaceAll() work differently in Java 8 from Java 9?
Explain the objections to these measures against human trafficking
Breaking a Loop in Tikz
TikZ: Cropping the Bounding BoxNested foreach loop in TikZMake tikzpicture white on blackTikZ scaling graphic and adjust node position and keep font sizeTikZ/ERD: node (=Entity) label on the insideTikZ: incrementing a foreach loopTikZ: Drawing an arc from an intersection to an intersectionLine up nested tikz enviroments or how to get rid of themCommutative diagram with curve connecting between nodesMisunderstanding tikz foreach loop
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,8}
ifnumX<5
{draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
else
ifnumX=8
fi
fi
fi
fi
fi
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
This produces an error but outputs:
I am trying to use an existing program written by Marmot to create
tikz-pgf foreach
add a comment |
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,8}
ifnumX<5
{draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
else
ifnumX=8
fi
fi
fi
fi
fi
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
This produces an error but outputs:
I am trying to use an existing program written by Marmot to create
tikz-pgf foreach
2
The error goes away if you move the firstifnum
into the group:{ifnumX<5
nstead ofifnumX<5{
.
– marmot
3 hours ago
@Marmot yes its working now
– MathScholar
3 hours ago
add a comment |
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,8}
ifnumX<5
{draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
else
ifnumX=8
fi
fi
fi
fi
fi
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
This produces an error but outputs:
I am trying to use an existing program written by Marmot to create
tikz-pgf foreach
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,8}
ifnumX<5
{draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
else
ifnumX=8
fi
fi
fi
fi
fi
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
This produces an error but outputs:
I am trying to use an existing program written by Marmot to create
tikz-pgf foreach
tikz-pgf foreach
asked 3 hours ago
MathScholarMathScholar
1,04129
1,04129
2
The error goes away if you move the firstifnum
into the group:{ifnumX<5
nstead ofifnumX<5{
.
– marmot
3 hours ago
@Marmot yes its working now
– MathScholar
3 hours ago
add a comment |
2
The error goes away if you move the firstifnum
into the group:{ifnumX<5
nstead ofifnumX<5{
.
– marmot
3 hours ago
@Marmot yes its working now
– MathScholar
3 hours ago
2
2
The error goes away if you move the first
ifnum
into the group: {ifnumX<5
nstead of ifnumX<5{
.– marmot
3 hours ago
The error goes away if you move the first
ifnum
into the group: {ifnumX<5
nstead of ifnumX<5{
.– marmot
3 hours ago
@Marmot yes its working now
– MathScholar
3 hours ago
@Marmot yes its working now
– MathScholar
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Do you want something like this?
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,N}
{ifnumX<5 %<-level 1
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1 %<-level 2
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0 %<-level 3
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt %<-level 4
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
fi %<-level 4
fi %<-level 3
fi %<-level 2
else
ifnumX=N %<-level 2
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+4*4/N,{f(1+LastX*4/N)/2}) -- (1+LastX*4/N,{f(1+LastX*4/N)/2})
node[midway,font=hugebfseries]{dots};
fi %<-level 2
fi %<-level 1
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 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%2f477314%2fbreaking-a-loop-in-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
Do you want something like this?
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,N}
{ifnumX<5 %<-level 1
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1 %<-level 2
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0 %<-level 3
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt %<-level 4
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
fi %<-level 4
fi %<-level 3
fi %<-level 2
else
ifnumX=N %<-level 2
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+4*4/N,{f(1+LastX*4/N)/2}) -- (1+LastX*4/N,{f(1+LastX*4/N)/2})
node[midway,font=hugebfseries]{dots};
fi %<-level 2
fi %<-level 1
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 hours ago
add a comment |
Do you want something like this?
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,N}
{ifnumX<5 %<-level 1
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1 %<-level 2
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0 %<-level 3
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt %<-level 4
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
fi %<-level 4
fi %<-level 3
fi %<-level 2
else
ifnumX=N %<-level 2
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+4*4/N,{f(1+LastX*4/N)/2}) -- (1+LastX*4/N,{f(1+LastX*4/N)/2})
node[midway,font=hugebfseries]{dots};
fi %<-level 2
fi %<-level 1
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 hours ago
add a comment |
Do you want something like this?
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,N}
{ifnumX<5 %<-level 1
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1 %<-level 2
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0 %<-level 3
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt %<-level 4
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
fi %<-level 4
fi %<-level 3
fi %<-level 2
else
ifnumX=N %<-level 2
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+4*4/N,{f(1+LastX*4/N)/2}) -- (1+LastX*4/N,{f(1+LastX*4/N)/2})
node[midway,font=hugebfseries]{dots};
fi %<-level 2
fi %<-level 1
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
Do you want something like this?
documentclass{article}
usepackage{tikz}
begin{document}
foreach N in {8}
{begin{tikzpicture}[scale=1.2,declare function={f(x)=((1/3)*(x)^(3)-3*
(x)^(2)+8*x-3;},
lnode/.style={fill=white,font=normalsize,inner sep=0pt,text height=1.5em}]
pgfmathtruncatemacro{M}{1}
coordinate (start) at (.8,{f(.8)});
foreach X [remember=X as LastX (initially 0)] in {1,2,3,4,...,N}
{ifnumX<5 %<-level 1
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+LastX*4/N,0pt) coordinate (xX);
ifnumX=1 %<-level 2
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt) coordinate (xX)
node[anchor=north east,xshift=2pt,lnode] {$a=x_{X}$};
else
pgfmathtruncatemacro{itest}{mod(X,M)}
ifnumitest=0 %<-level 3
pgfmathsetmacro{dist}{4-LastX*4/N}
ifdimdist cm>5pt %<-level 4
draw (1+LastX*4/N,3pt) -- (1+LastX*4/N,0pt)
node[anchor=north,lnode] {$x_{X}$};
fi %<-level 4
fi %<-level 3
fi %<-level 2
else
ifnumX=N %<-level 2
draw[fill=orange!40!white] (1+LastX*4/N,0) rectangle (1+X*4/N,{f(1+LastX*4/N)});
draw[red,fill=red] (1+LastX*4/N,{f(1+LastX*4/N)}) circle (1.4pt) ;
path (1+4*4/N,{f(1+LastX*4/N)/2}) -- (1+LastX*4/N,{f(1+LastX*4/N)/2})
node[midway,font=hugebfseries]{dots};
fi %<-level 2
fi %<-level 1
}
draw (5,3pt) -- (5,0pt)
node[anchor=north west,xshift=-2pt,lnode]{$b$};
%draw (1,3pt) -- (1,0pt)
% node[anchor=north west,xshift=-2pt,lnode]{$a$};
node at (5.3,5) [text=red] {$f(x)$};
coordinate (end) at (5.05,{f(5.05)});
draw (5,3pt) -- (5,0pt) node[anchor=north west,xshift=-2pt,lnode]{$b$};
draw (5,0)--(5,{f(5)});
draw [-latex] (-0.5,0) -- (6,0) node (xaxis) [below] {$x$};
draw [-latex] (0,-0.5) -- (0,5) node [left] {$y$};
draw[domain=.5:5.3,samples=200,variable=x,red,<->,thick] plot ({x},{f(x)});
node at (5.3,5) [text=red] {$f(x)$};
end{tikzpicture}}
end{document}
edited 3 hours ago
answered 3 hours ago
marmotmarmot
105k4124236
105k4124236
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 hours ago
add a comment |
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 hours ago
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 hours ago
this looks great. I will look at the code later today . Again thanks for your help. I knew what to but this level of if else statements was difficult.
– MathScholar
2 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%2f477314%2fbreaking-a-loop-in-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
The error goes away if you move the first
ifnum
into the group:{ifnumX<5
nstead ofifnumX<5{
.– marmot
3 hours ago
@Marmot yes its working now
– MathScholar
3 hours ago