Hi!
My question is quite simple. I'm supposed to perform some tiresome, iterative calculations in the form of simple procedural programming and print the results in a LaTeX document. Would it be possible to have LaTeX do such iterative calculations, or do I have to perform the calculations externally and then copy and paste them into my LaTeX document?
It would be much appreciated if you posted a link to a helpful manual/tutorial, should you know of any.
Thanks in advance
General ⇒ Calculations and procedural programming in LaTeX
Calculations and procedural programming in LaTeX
Last edited by eiterorm on Wed Oct 20, 2010 11:47 pm, edited 1 time in total.
Re: Calculations and procedural programming in LaTeX
Hi,
can you please explicit a little more the kind of calculations (including the type of variables involved, etc.) that you need to perform?
can you please explicit a little more the kind of calculations (including the type of variables involved, etc.) that you need to perform?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Calculations and procedural programming in LaTeX
The little specific nature of my question was quite intentional. If there are several ways to solve a procedural/iterative problem in LaTeX, I would appreciate to know more than one of them. I should have made it clearer, though, that the problems I'm talking about are not connected to creating graphics in LaTeX - at least not directly.
The procedural programming I was thinking about includes if statements, for loops, while loops, boolean comparisons, general nesting, defining variables. As of now, I was mostly thinking about performing numerical calculations, however, at a later time it might also be useful to be able to treat segments of text. So if you do know a way to treat segments of text, I'd be happy to know this as well.
The problem which made me start this thread is given below:
I was supposed to make a table in LaTeX, with the values of v_sat computed by the formula given in the example, for all integers of theta from -20 to 30. In the first column, I was to write the value of theta, and in the second column I was to write the value of v_sat. This problem is an iterative problem, and because the constants change when theta crosses zero, I could need an if statement. If LaTeX is capable of calculating a problem like this, it would be unnecessary to calculate it externally and then copy and paste the results into the LaTeX document.
However, this was a rather specific example, and I would like to be able to solve more general problems than this one, if possible. Is there a general way of solving problems as described in my first post, and the two first paragraphs of this post?
Thanks
The procedural programming I was thinking about includes if statements, for loops, while loops, boolean comparisons, general nesting, defining variables. As of now, I was mostly thinking about performing numerical calculations, however, at a later time it might also be useful to be able to treat segments of text. So if you do know a way to treat segments of text, I'd be happy to know this as well.
The problem which made me start this thread is given below:
I was supposed to make a table in LaTeX, with the values of v_sat computed by the formula given in the example, for all integers of theta from -20 to 30. In the first column, I was to write the value of theta, and in the second column I was to write the value of v_sat. This problem is an iterative problem, and because the constants change when theta crosses zero, I could need an if statement. If LaTeX is capable of calculating a problem like this, it would be unnecessary to calculate it externally and then copy and paste the results into the LaTeX document.
However, this was a rather specific example, and I would like to be able to solve more general problems than this one, if possible. Is there a general way of solving problems as described in my first post, and the two first paragraphs of this post?
Thanks
Calculations and procedural programming in LaTeX
For basic loops and conditionals, the ifthen or the xifthen packages could be useful.
Floating point operations could be performed using the fp package.
For integer arithmetics you have the intcalc package.
A review of the TeX book (only the "protected" code is available) and the TeX by Topic (you can download it) books could also shed some light on some aspects (and limitations) of programming in TeX.
Floating point operations could be performed using the fp package.
For integer arithmetics you have the intcalc package.
A review of the TeX book (only the "protected" code is available) and the TeX by Topic (you can download it) books could also shed some light on some aspects (and limitations) of programming in TeX.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Calculations and procedural programming in LaTeX
Useful they are indeed!
Thanks a lot!
Thanks a lot!