Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [math]

The tag has no usage guidance.

-1
votes
0answers
31 views

How to do operation math with number words shell script?

I want to read a file and inside the file have number words. I have to do operation math. but I dont know why my script doesn't work. Exemple : seven one minus six one the answer in the terminal : ...
1
vote
4answers
59 views

How can I feed a string to awk for the purpose of mathematical calculation?

#!/bin/sh -- expression_to_evaluate='12 + 3' printf '%s\n' "Arithemtic Expansion: $(( $expression_to_evaluate ))" printf '%s' 'bc: ' printf '%s\n' "$expression_to_evaluate" | bc printf '%s' 'awk: '...
-3
votes
2answers
91 views

What do comm and diff try to accomplish at input/output level?

Given two files, for each line in each file, how do comm and diff determine whether the line also occur in the other file? if it does, whether its occurrences in the two files are the same or ...
1
vote
5answers
1k views

$@ used in a loop for math

I am trying to write a Bash script that takes a list of numbers as command line arguments and then outputs the sum of those numbers. So the script would be run as script.sh 1 555 22 122 66 and would ...
1
vote
1answer
186 views

Error during static build of libvorbis and libmp3lame

I'm having trouble trying to build a static binary of ffmpeg - I've got almost the whole build working, with the exception of two libs - libvorbis and libmp3lame. These two libs are failing during ./...
1
vote
1answer
1k views

How to do math manipulation with variables in conky?

This is part of my conky code. conky.config = { alignment = 'top_right', background = true, color2 = '2ECC71', cpu_avg_samples = 2, default_color = 'FFFFFF', double_buffer = ...
0
votes
1answer
413 views

How to script an an exponential function that decrements the value of the exponent every iteration so that the exponent does not grow?

New to Linux and having problems getting this script to run. Been working on something to take large numbers and use the remainder (modulus) to store the result ( to save memory ). Using the bash ...
0
votes
1answer
224 views

Using seq and math to manipulate the last octet in an ip address to create a file

Ubuntu 16.04 GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu) We have to add ips to servers a few times a day. I find myself creating different variations of the same file according to the ...
-1
votes
1answer
143 views

Como calcular um número fatorial em Bash puro - (Ex.: 5!) [closed]

Trying to translate: What is a basic, elegant and fast way, to write factorial in Bash/in a shell script, purely. (Code) Please make suggestions. (Code) Tem outra alternativa mais básica/...
0
votes
1answer
37 views

Using gawk to alter columns after a line identifier

I have multiple drawing files in the format detailed below. I need to increase the value of a number in the area of the file below after the line BO. All values (in the sample below) that are 14.00 ...
0
votes
2answers
128 views

Hexadecimals to decimal $((0039))

I have a long file with values like this: 0030..0039 2194..2199 21A9..21AA 231A..231B 23E9..23F3 23F8..23FA 25AA..25AB I want to convert the hexadecimals to decimal format. I'm reading that you can ...
1
vote
4answers
573 views

Increment decimal values to next integer value

I want to increment the decimal value to next integer value through shell script. For example: i=**1.6** then I need to print i=**2** i=**1.00001** then I need to print i=**2** i=**1.00049** then ...
1
vote
1answer
455 views

Checking that a decimal number is in a range in bc

I've written this if, that is obviously not working, and I still can't manage to get over it: #LASTEFFECTIVEHASH if (( $(echo "$LASTEFFECTIVEHASHMINVAL < $LASTEFFECTIVEHASH < $...
2
votes
1answer
88 views

primality test binary

I'm generating numbers using a Java program (BigIntegers) and I want to know if there's a binary readily available that I could use to run primality tests on the numbers generated.... suppose I feed ...
2
votes
1answer
120 views

How to grep a pdf for math?

Is there any way to grep a pdf document (originally written in LaTeX) for the math "2^n" as in 2 to the power of n? I have pdfgrep but I don't know how you would use that to grep for math.
0
votes
2answers
50 views

BASH script to catch changes to a file greater than 150MB

Need some ideas here. I was using something along the lines of if $[$x-$y>1500] then etc.... to detect the size of the changes to a file. I've realized that won't work as the files sizes could ...
1
vote
1answer
493 views

Calculate LPAR CPU utilization (AIX)

I'm trying to calculate the CPU utilization of an LPAR but I get wrong results. I can see the utilization in the HMC Web Interface, but Id like to calculate it myself for own purposes. My test: I ...
11
votes
1answer
752 views

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....
3
votes
1answer
151 views

Start bc with pi defined

I would like to create an alias for bc that runs bc -l and specifies that pi=4*a(1). This way, I can start each session with pi already defined. What alias will do this?
0
votes
1answer
807 views

What is the difference between bcl and expr?

I know that both of them can do simple arithmetic. I'm wondering when it will be easier to use one versus the other. I know that expr evaluates an expression from its arguments, while bcl evaluates ...
0
votes
2answers
135 views

Trying to complete Project Euler #5, passes all syntax checks but doesn't work

trying to complete Project Euler #5. The code I have should logically work, and it passes ShellCheck, but gives no output for some reason. The code is below. Thanks and sorry if this should be in a ...
1
vote
0answers
40 views

To divide a a loop variable per se and save in another one to be used later

I am facing a problem with bash script: I have a set of variables 'i' that ranges from 3.31 up to 3.35. My script prints out, as a function of the variable 'i' some input file for geometrical ...
5
votes
1answer
2k views

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 ...
2
votes
1answer
59 views

Better Solution for Finding ID Groups (Permutations/Combinations)

My goal for this question is to find a more efficient solution to accomplish a task. I have a file containing rows of IDs, e.g.: 1001 1004 1005 1010 1006 1020 1002 1002 1005 1006 1001 1010 1020 1043 ...
-2
votes
3answers
66 views

How can I compute the sum of all i² for i between n and m?

How can I write a script to sum the squares of integers between two values n and m, meaning the sum of all i², where i runs from n to m?
0
votes
1answer
685 views

How to calculate the standard deviation for each row?

I have file of 61 columns; I would like to calculate the standard deviation (SD) for each row with ignoring the 1st column and print the results against the 1st column, please note that the number of ...
1
vote
2answers
438 views

How to print all subsets of a set? [duplicate]

How can I print all subsets of a set using bash script. like : {} , {1} ,‌{2} ,{1,2} for A={1,2} this is what I have already write but I always thinks there must be a better way also my script just ...
0
votes
1answer
38 views

negative values are being treated as positive in RHEL suddenly. Why?

For example: # [[ -24 > 0 ]] && echo "Hi" Hi Since yesterday, I found this weird behavior. What could be the reason?
1
vote
1answer
574 views

Why does the factor command produce nonsense on an RSA modulus?

Ok, so I think I may have found a flaw in... something. I honestly don't know. This is such a weird scenario. I was attempting to break very small asymmetric (RSA) encryption, just as a Proof of ...
2
votes
2answers
1k views

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.
1
vote
1answer
39 views

Mean and variance of words pronounced

I'm working on linguistics and am trying to calculate the average sentence length and how much this average varies. I worked to leave always one sentence per line For instance: La dernière fois ...
3
votes
2answers
313 views

How can I do basic calculations in a shell script?

I want to perform some mathematical operations in the shelll. For example: 5+50*3/20 + (19*2)/7 I tried: #!/bin/bash read equ echo "scale=3; $equ" | bc -l Expected output: 17.929 My output: ...
3
votes
3answers
114 views

A bc problem about long expression

I want to calculate an expression in shell. I use the following code: pi=$(echo "scale=10; 4*a(1)" | bc -l) i=3 d=`expr (1+c($pi*($i/10)+$pi))/2 | bc -l` But it says bad pattern: (1+c(3.1415926532*(...
0
votes
1answer
27 views

Maths revision program [closed]

I have created a program that will randomly select two numbers out of a range and ask a multiplication question from it. It looks very messy and repetitive. What I would like help with is "How would ...
7
votes
4answers
3k views

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 ...
1
vote
0answers
38 views

How do I use octave to find the numerical solutions to a system of non-linear equations?

I have the following set of equations: acos(x/250)=t acos(w/300)=u asin(y/250)=u asin(z/300)=t w-x=150 z-y=150 How do I solve this system of non-linear equations using octave? The only documentation ...
2
votes
2answers
934 views

How to add all values in an array

I have been stuck on this for way to long now. Tried googling and couldn't find what I was looking for. I simply need to add all the values in an array.(array called packets) I have gotten to the ...
1
vote
4answers
2k views

bash division of numbers in text file

I have two numbers in test.txt file, I would like a way to divide the second number by the first number and assign the result to a variable or file in a bash script that I can use. I have used awk "NR=...
0
votes
1answer
725 views

How do I add integer and floating numbers together to keep tally?

I'm just trying to do some simple math that is not turning out that simple. this is what I have tried so far and I have yet to find anything on the google net that combines integer and floating ...
34
votes
20answers
17k views

How do I print pi (3.14159)? [closed]

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.
2
votes
1answer
144 views

Mathematical processing on text file

I have 200 text files. Each text file contains one column of mathematical numbers (100k rows). I want to do some statistical processing on these data (finding the probit or quantile). I know the ...
6
votes
3answers
2k views

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 ...
8
votes
7answers
1k views

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 ...
4
votes
1answer
22k views

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 $...
3
votes
3answers
82 views

Script is stuck saying 1 response with 2 available: Math related

I have a script that tells the user the square footage of 2 rooms based on user input. I think I have that part done right. The problem I have is that I need to have the script say which room is ...
3
votes
1answer
67 views

How to calculate (weighted) majority over columns?

I have two files: the first one contains lines where the first column is an ID, and the remaining columns are votes, e.g. 3242 -1 1 -1 1 1 1 In a first step I want to calculate the majority for ...
4
votes
2answers
2k views

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 - ...
4
votes
2answers
5k views

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[*]}" )
0
votes
1answer
688 views

expr command used to work and stopped

I am on SunOS machine trying to get the date string of the past minute, yesterday I used this command I found on the internet expr `date +%Y%m%d%k%M` - 1 which is worked just fine and I saw the ...
3
votes
4answers
2k views

Round/truncate digit in string in zsh (or with external tool)

I'm trying to do an interface to bc so it can be used intuitively and without the annoyance of getting "stuck" in it. I haven't got around to test it that much, because I got stuck on another detail, ...