recentpopularlog in

kme : math   174

« earlier  
Arithmetic expressions [Bash Hackers Wiki]
Should note that return value is always decimal, and that you can use 'printf' to format the result in another base, e.g.,
<code class="language-bash">printf "%o\n" $(( 0777 & 0066 ))
# result: 66</code>
bash  expansion  arithmeticexpansion  math  needshelp  shellscripting 
10 weeks ago by kme
linux - bash + arithmetic calculation with bash - Unix & Linux Stack Exchange
Since arithmetic expansion only does integer division, the proposed answer uses AWK, passing in values as variables, with '/dev/null' as the input file, and the math in a 'BEGIN' block.
bash  awk  shellscripting  floatingpoint  math  tipsandtricks  solution 
10 weeks ago by kme
Builtin Bash any base to decimal conversion – Phoxis
Bash has an interesting builtin feature to convert from any base to decimal, which is a part of bash's arithmetic evaluation features. In this post i will quickly introduce you with this feature. Arithmetic Expansion To allow arithmetic evaluation of an expression and substitution of the result bash has the following construct. For example The…
bash  shellscripting  math  calculator  numericconversion  base64  base8  base10  tipsandricks 
10 weeks ago by kme
software recommendation - Any command line calculator for Ubuntu? - Ask Ubuntu | https://askubuntu.com/
Another possible solution is to add a simple function for Bash's builtin arithmetic. Put this in your .bashrc file to try:
<code class="language-bash">
=() {
echo "$(($@))"
}
</code>
math  calculator  bash  commandline  bashrc  essential 
december 2018 by kme
num-utils homepage | http://suso.suso.org/
This is OK, except 'cut -f1 | paste -sd+ | bc -l' does the same thing.
unix  bash  shellscripting  math  utility 
november 2018 by kme
python numpy machine epsilon - Stack Overflow | https://stackoverflow.com/

An easier way to get the machine epsilon for a given float type is to use np.finfo():

<code class="language-python">print(np.finfo(float).eps)
# 2.22044604925e-16

print(np.finfo(np.float32).eps)
# 1.19209e-07</code>


Also interesting, but I wonder why this works:

Another easy way to get epsilon is:
<code class="language-python">
In [1]: 7./3 - 4./3 -1
Out[1]: 2.220446049250313e-16
</code>
python  float  floatingpoint  math  solution 
may 2018 by kme
[Solved] How to insert floor / ceiling symbols? (View topic) • Apache OpenOffice Community Forum | https://forum.openoffice.org/
To insert floor brackets, type lfloor <?> rfloor directly in the Commands window.
To insert ceiling brackets, type lceil <?> rceil directly in the Commands window.
To insert scalable floor brackets, type left lfloor <?> right rfloor directly in the Commands window.
To insert scalable ceiling brackets, type left lceil <?> right rceil directly in the Commands window.
libreoffice  openoffice  math  equation  specialcharacter  symbol  solution 
january 2018 by kme
Qalculate! - the ultimate desktop calculator
This actually does decent time calculations (12:15 + 8:30 is ?).
timeanddate  calculator  math  gtk  cli  commandline  solution 
november 2017 by kme
algebra precalculus - How to find the inverse of a piecewise function - Mathematics Stack Exchange
You have y=x when 0≤x≤1 and y=x−1 when 2<x≤3, which is to say when 1<y≤2 since y=x−1. And the inverse function is obtained by switching x and y. So when 0≤y≤1 the inverse value is y, while when 1<y≤2 the inverse value is y+1.
algebra  math  inversefunctions  dammitbrain 
april 2017 by kme
Using MathJax with Jekyll - Stack Overflow


If you have sufficient control over the publishing process (e.g. you are running Jekyll yourself), an easy solution is to switch the markdown parser to one that supports TeX. For example, using kramdown:

gem install kramdown

Change the markdown line in _config.yml to

markdown: kramdown

and add something like

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

to _layouts/default.html. Now you can simply mark any mathematics in your posts with $$.
mathjax  latex  math  typesetting  jekyll  solution 
april 2017 by kme
bit manipulation - What are bitwise shift (bit-shift) operators and how do they work? - Stack Overflow
As you can see, the digits have shifted to the left by one position, and the last digit on the right is filled with a zero. You might also note that shifting left is equivalent to multiplication by powers of 2. So 6 << 1 is equivalent to 6 * 2, and 6 << 3 is equivalent to 6 * 8. A good optimizing compiler will replace multiplications with shifts when possible.
c  cplusplus  devel  bitshift  math  binary  dammitbrain  solution 
december 2016 by kme
Bash command to sum a column of numbers - Stack Overflow

Using existing file:

paste -sd+ infile | bc

Using stdin:

<cmd> | paste -sd+ | bc

Edit: With some paste implementations you need to be more explicit when reading from stdin:

<cmd> | paste -sd+ - | bc


Also:
Well, that would be easier with awk: awk 'END { print s } { s += $8 }' infile :)
unix  math  shellscripting  commandline  solution 
december 2016 by kme
python - How do you get the magnitude of a vector in Numpy? - Stack Overflow
The function you're after is numpy.linalg.norm. (I reckon it should be in base numpy as a property of an array -- say x.norm() -- but oh well).

import numpy as np
x = np.array([1,2,3,4,5])
np.linalg.norm(x)

You can also feed in an optional order for which norm you want. Say you wanted the 1-norm:

np.linalg.norm(x,order=1)
linearalgebra  numpy  python  math  library  solution 
october 2016 by kme
Shell command to sum integers, one per line? - Stack Overflow
awk '{s+=$1} END {print s}' mydatafile


Alternatively:

Paste typically merges lines of multiple files, but it can also be used to convert individual lines of a file into a single line. The delimiter flag allows you to pass a x+x type equation to bc.

paste -s -d+ infile | bc
shellscripting  shell  math  bash  awk  solution 
april 2016 by kme
l'Hospital's rule symbol • Math & Science • LaTeX Community - http://www.latex-community.org/
\documentclass{report}
\usepackage{amsmath}

\newcommand*\Heq{\ensuremath{\overset{\kern2pt H}{=}}}

\begin{document}

\[ a\Heq b \]

\end{document}
math  latex  typesetting  solution 
october 2015 by kme
LaTeX help 1.1 - Spacing in Math Mode [http://www.emerson.emory.edu/]
In a math environment, LaTeX ignores the spaces you type and puts in the spacing that it thinks is best. LaTeX formats mathematics the way it's done in mathematics texts. If you want different spacing, LaTeX provides the following four commands for use in math mode:

\; - a thick space
\: - a medium space
\, - a thin space
\! - a negative thin space
latex  mathmode  math  typesetting  solution 
april 2015 by kme
The Simpsons' secret formula: it's written by maths geeks | Television & radio | The Guardian
This prank was planted into the episode by David S Cohen, who later changed his name to David X Cohen, in part to reflect his love of algebra. Cohen joined the writing team of The Simpsons soon after completing a masters degree in computer science at the University of California, Berkeley. While working on "The Wizard of Evergreen Terrace", Cohen took a break in order to write a computer program that would scan through values of x, y, z, and n until it found a pseudo-solution to Fermat's equation.

As soon as the episode aired, Cohen patrolled the online message boards to see if anybody had noticed his fake equation. He eventually spotted a posting that read: "I know this would seem to disprove Fermat's last theorem, but I typed it in my calculator and it worked. What in the world is going on here?"
math  simpsons  tv  culture  nerdery 
february 2015 by kme
linux - How do I test if a variable is a number in bash? - Stack Overflow
I use this:

"$var" -eq "$var"

as in:

#!/bin/bash

var=a

if [ "$var" -eq "$var" ] 2>/dev/null; then
echo number
else
echo not a number
fi


Another option:
re='^[0-9]+$'
if ! [[ $yournumber =~ $re ]] ; then
echo "error: Not a number" >&2; exit 1
fi
bash  math  bourneshell  solution  shellscripting 
november 2014 by kme
if statement - How do I test for NaN in Javascript? - Stack Overflow
NaN's are unusual: they are not equal to anything, even themselves. You need to use isNaN(inbperr) to tell whether a value is a NaN or not.
javascript  math  newbie  solution 
may 2014 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read