Questions tagged [math]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
43 views

bash: set the value from log as a variable [duplicate]

I have a log file consiste of 240 float digits in the following format: 5.4 5.1 5.2 5.4 5.4 4.9 5.0 5.2 5.5 5.3 5.6 5.4 5.1 5.3 5.3 5.1 5.2 .. 4.8 Accesing to this log file in bash environment I need ...
0
votes
1answer
18 views

I have a data set with postive negative values computing LN in awk using if statement conditions

I have large datasets in where the natural log (LN) is being computed. However, there is many cases where there are negative values and awk is kicking out a warning line for each occurrence and will ...
0
votes
1answer
65 views

Bash math: off-by-one or error calculating if a number is divisible by another number

I used the solution from this answer in a script I'm working on, but it doesn't seem to be working for me. I'm on Bash 5. Here's a simplified test case, I would expect the do_thing function to be ...
1
vote
3answers
97 views

Fitting a equation to a set of data

I have a set of data: 1.12158 0.42563 0.07 1.12471 0.42112 0.07 1.12784 0.41685 0.07 1.13097 0.41283 0.07 1.13409 0.40907 0.07 1.13722 0.40556 0.07 1.14035 0.40231 0.07 1.14348 0.39933 0.07 1.1466 0....
1
vote
2answers
208 views

Does shell maths run in a subshell?

When I perform a simple math operation in #!/bin/sh, does that create a subshell? E.g., addition=$(( 1 + 1 )) The syntax would suggest a subshell, but I couldn't find anything on this
2
votes
1answer
87 views

Gnuplot Precission

Does anyone know whether there is a way to run gnuplot with quadruple arithmetic precision? E.g. When you want to plot a line and you want to subtract a value like "2....
1
vote
4answers
490 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
114 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
2k 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 ...
2
votes
1answer
663 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
3k 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
1k 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
422 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
186 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
45 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
342 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
1k 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** ...
1
vote
1answer
641 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
275 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
172 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
58 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
811 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 take ...
11
votes
1answer
935 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
296 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
2k 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
165 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
47 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 ...
9
votes
1answer
4k 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
71 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
90 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
993 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
652 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
39 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
631 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 ...
3
votes
3answers
2k 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
59 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 qu'...
3
votes
2answers
319 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
148 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
28 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 ...
8
votes
4answers
5k 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
42 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
1k 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 ...
2
votes
4answers
3k 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
881 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 ...
37
votes
20answers
22k 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
164 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
3k 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
2k 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
40k 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
83 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 ...