GeneralPassing "values" to equations

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
rockstar1707
Posts: 27
Joined: Wed Jan 17, 2007 12:35 pm

Passing "values" to equations

Post by rockstar1707 »

The idea is the following. I'm writing a report with rather complicated equations which depend on the same parameters. So, I would like to be able to write equations in a way that I can change the value of those parameters only once, and all subsequent equations, which depend on that parameter, would update appropriately.

===============================================

An example:

Code: Select all

eq1 = a + b
eq2 = a^2 + 2 \cdot a
eq3 = b^4 - a^b
So, if i assume that "a = 1" and "b = 2", I have to change all the equations like:

Code: Select all

eq1 = 1 + 2
eq2 = 1^2 + 2 \cdot 1
eq3 = 2^4 - 1^2
This is easy if we have few equations, but really tedious if we have many of them. The usual report usually looks like:

Code: Select all

eq1 = a + b = 1 + 2 = 3
so it would be great, if I can write something like:

Code: Select all

eq1 = a + b = \val{a} + \val{b} = \val{result}
and somewhere before this equation I define

Code: Select all

\val{a} = 1
\val{b} = 2
\val{result} = 3
One option would be to declare new command for each value, like:

Code: Select all

\newcommand{\val_a}{1}
\newcommand{\val_b}{2}
\newcommand{\val_result}{3}
but we're really limited with the names (the above example actually doesn't work, because underscores are not allowed in command names - thus, I would have to write it like \vala, \valb, \valresult, which is really unclear).

Is there some package which provide something like this? Or if there is some other way to realize this?

Thank you for your answers.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply