Skip to main content

Add your description here

Project description

Show your work!

show-your-work is a Python module to help with writing solutions to physics problems with numerical answers. It relies on other modules to do most of the heavy lifting.

Motivation

When writing detailed example problems for a physics class, we often need to plug numerical values into an equation and compute a numerical result. show-your-work allows you to write an equation in latex, add numerical substitutions for each term in the equations, produce the latex of your equation with numerical values substituted in, and then evaluate the equation with the given numerical values.

It is especially handy when used with tools like compudoc.

From the doc/examples directory

% main.tex.cd
\documentclass[]{article}

\usepackage{siunitx}
\usepackage{physics}
\usepackage{graphicx}
\usepackage{fullpage}

\author{C.D. Clark III}
\title{show-your-work/compudoc example}

\begin{document}
\maketitle

% {{{
% from show_your_work import Expression, Equation
% import pint
% ureg = pint.UnitRegistry()
% Q_ = ureg.Quantity
% def Lx_filter(input,fmt=""):
%   text = fmt_filter(input,fmt+"Lx")
%   return text
% jinja2_env.filters["Lx"] = Lx_filter
% line_eq = Equation(r"\\v{y} = \\v{m}\\v{x} + \\v{b}")
% print(line_eq.latex)
% }}}
$$
{{ line_eq.latex }}
$$
This gives the relationship between a dependent variable $y$ on an independent variable $x$.
% {{{
% slope = 3
% y_intercept = 2
% val = 10
% }}}
For example, for a slope $m = {{slope}}$ and y-intercept $b = {{y_intercept}}$, the value for $y$ at $x = {{val}}$ would be
% {{{
% line_eq.rhs.add_substitution('m',slope)
% line_eq.rhs.add_substitution('b',y_intercept)
% line_eq.rhs.add_substitution('x',val)
% }}}
$$
{{ line_eq.latex_with_substitutions }} = {{line_eq.rhs.eval()}}
$$
% {{{
% kinematics_eq1 = Equation( r"\\v{x} = \\v{v} \\v{t} + \\v{x_0}", "meter")
% v = Q_(60,'mph').to("km/hr")
% t = Q_(40,'min')
% x0 = Q_(150,'yd').to("m")
% kinematics_eq1.rhs.add_substitution('v',v)
% kinematics_eq1.rhs.add_substitution('t',t)
% kinematics_eq1.rhs.add_substitution('x_0',x0)
% }}}
Now, when dealing with physical quantities, we will have to consider units. Take an example from kinematics. The
position of an object traveling at constant speed is given by the equation,
$$
{{kinematics_eq1.latex}},
$$
which is just the equation for a line with $v$ as the slope and $x0$ as the y-intercept. If a car is traveling at
$v = {{v|Lx}}$ and we didn't start the stop watch until we were {{x0|Lx}} out of town, the car's distance from town
after traveling for {{t|Lx}} would be:
$$
{{kinematics_eq1.latex_with_substitutions}} = {{kinematics_eq1.rhs.eval(Q_)|Lx}}
$$



\end{document}

This template file can be rendered to LaTeX with compudoc and then compiled to a PDF with latexmk:

$ compudoc main.tex.cd
$ latexmk main

which will give this PDF

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

show_your_work_utils-0.1.0.tar.gz (186.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

show_your_work_utils-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file show_your_work_utils-0.1.0.tar.gz.

File metadata

File hashes

Hashes for show_your_work_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8aa8ffddc55975ee70cc983ec829d596ea3d234c9020d90bb427431aa4a0bd58
MD5 39819c554aa99ed606bdc5f2f60c2d9a
BLAKE2b-256 a354a6e03a4d08626823bcb4585a58e3382788f2e68bc88faaa37b1d2a87098e

See more details on using hashes here.

File details

Details for the file show_your_work_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for show_your_work_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 740d09fbf94261f58c8230f5500bd01ea7df90af5506f43c7cb96082006e2e94
MD5 c7861ac8ac52891190352f36bb76d65e
BLAKE2b-256 48df4a1427c22a5e068a617bf7a31710177016b75aa3982023b490ffee1eb5dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page