Questions tagged [math]

77 questions
45
votes
13 answers

Addition with 'sed'

I am trying to perform a mathematical operation with sed, but it continues to treat my variables as strings. The input is of this kind: $ echo 12 | sed 's/[0-9]*/&+3/' $ 12+3 I'd like to have 15 as output. I need to do the operation and replace its…
Luigi Tiburzi
  • 887
  • 3
  • 10
  • 13
39
votes
20 answers

How do I print pi (3.14159)?

What command could print pi for me? I want to specify how many digits it prints, I couldn't find anything online. I just want to be able to print pi.
DisplayName
  • 11,468
  • 20
  • 73
  • 115
13
votes
4 answers

Free Matlab equivalent for Linux

My collaborators are using Matlab to do some simulations. Is there an open source alternative I could use on Linux to run these scripts? It would need to be fairly closely compatible with the (1) matlab language (2) the *.fig files - saved plots.
Grzenio
  • 5,747
  • 12
  • 32
  • 41
13
votes
1 answer

How does printf round halves to the first decimal place?

I am testing two different implementations of printf on my system: printf (GNU coreutils) 8.26, and the version bundled with zsh 5.3.1. I am testing how half numbers are rounded, i.e. for 1.5, 2.5, 3.5, … 9.5. $ for i in {1..9}; do /usr/bin/printf…
Sparhawk
  • 19,561
  • 18
  • 86
  • 152
9
votes
3 answers

Linux bc defines PI as 99

I'm using bc in Ubuntu Linux. It has a pre-defined constant PI that's set to 99. Why does bc define PI to be 99 instead of 3.14159...?
Jim
  • 91
  • 1
  • 2
9
votes
1 answer

Why 'let' exits with code 1 when calculation result equals to 0?

I came across this question whose author had dealt with problem caused by: let x=1-1 exits with code 1. According to bash manual: If the last expression evaluates to 0, let returns 1; otherwise 0 is returned. (p. 56-57) I'm not so familiar with…
9
votes
1 answer

How to install R plotly in Debian?

I am studying data visualisation with Matrices, Eigen matrices and network graphs, and I am trying to visualise 1D ECG signal by network graphs. I feel the current tools ggnet2 and plotly may be insufficient, but I have not managed to completed the…
Léo Léopold Hertz 준영
  • 6,788
  • 29
  • 91
  • 193
9
votes
8 answers

Command line expression solver?

I'm looking for a Linux-compatible TTY-based calculator. For example: user@host:~$ calculate > 2 2 user@host:~$ calculate > 8*6-4 44 user@host:~$ calculate > 8*(6-4) 16 Is there anything like this that supports basic operations, some built-in…
Lucas Phillips
  • 449
  • 5
  • 11
8
votes
1 answer

Who decided the bc math library will define sine cosine and arctangent?

If you load the bc math library you get the trig functions s() and c() and a() which are sine, cosine, and arctangent respectively. Why these three functions? I know why it's those three from the mathematical perspective: it's because those are the…
Mike Pierce
  • 737
  • 1
  • 6
  • 23
8
votes
4 answers

Weird float rounding behavior with printf

I've read some answers on this site and found the printf rounding desirable. However when I used it in practice, a subtle bug led me to the following behavior: $ echo 197.5 | xargs printf '%.0f' 198 $ echo 196.5 | xargs printf '%.0f' 196 $ echo…
Hai Zhang
  • 185
  • 1
  • 8
7
votes
1 answer

basic division using variable and integer

I'm having trouble figuring out a basic division command. count = redis-cli llen domains; echo $count returns 1000 How can I echo $count/1000? I've tried different combinations of: echo `expr $count / 1000`; echo $count/1000; echo ($count /…
d-_-b
  • 1,167
  • 5
  • 18
  • 27
6
votes
2 answers

How can I round all numbers in a file?

How can I round all numbers in a file that countains several columns of numbers up to a certain precision? Can this be done with awk? A single line looks like this: text - 0.1655456615 - 0.158645 - 0.846554 - 0.85251 ## EDIT: '-' is a column…
MaVe
  • 339
  • 4
  • 12
6
votes
3 answers

Increment numbers inside strings by an offset

I want to search a text file for strings like these. [task0] [task1] ... [task1613] and increment each by a given offset, in this case by 3640. So, with the example I gave above, I'd get the following. [task3640] [task3641] ... [task5253] I want…
user61043
  • 63
  • 1
  • 3
4
votes
2 answers

How to sum a bash array of numbers (some in scientific notation)?

Since the following command using bc does not work for numbers in scientific notation, I was wondering about an alternative, e.g. using awk? sum=$( IFS="+"; bc <<< "${arrValues[*]}" )
MaVe
  • 339
  • 4
  • 12
4
votes
3 answers

Equation solver for the shell?

Is there an equation solver for the shell? For example, I enter input 1000=x^(1.02) and the shell solves for x.
Niklas Rosencrantz
  • 4,112
  • 6
  • 36
  • 58
1
2 3 4 5 6