Questions tagged [math]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
9 votes
3 answers
3k views

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...?
user avatar
  • 91
-1 votes
1 answer
69 views

average of nth line from mutiple files into one average master file

I have 3 files which contain 8 lines of numerical values and text. I'm trying to take the average of each rows across all three files and print a new file with those averages. The three example files ...
user avatar
0 votes
0 answers
20 views

Grip alternative with math rendering

I enjoy note-taking in Vim with Markdown, which I then convert to PDF. I don't do anything overly complex - just some basic headers, some code snippets, and some math formulae. I discovered grip that ...
user avatar
  • 155
0 votes
1 answer
45 views

How do you type a number with a bar symbol over it?

100 divided by 3 equals 33.3 bar. How can I put a bar symbol over the three like this: You'd think there would be 10 unicode characters dedicated to this, but I couldn't find them.
user avatar
  • 4,311
7 votes
1 answer
682 views

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 ...
user avatar
0 votes
1 answer
76 views

How do I convert these commands to work in a conky file?

What I am doing is working on a conky widget, and I am trying to get a voltage reading from the sensor chip on my motherboard to display it. I am getting a voltage reading and displaying it in the ...
user avatar
0 votes
0 answers
63 views

Why integer division is faster than bitwise shift in shell?

I'm comparing performance of bash and dash (default sh in Xubuntu 18.04). I expect sh to be faster than bash I expect bitwise shift to be faster than division operator. However, I'm getting ...
user avatar
8 votes
1 answer
309 views

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 ...
user avatar
0 votes
1 answer
28 views

any program with can show maths steps for simplifying algebra

I am looking for a program in linux or even a library which can show maths steps for simplifying algebra expressions Example: simplify 2(3x+5) step1: 2*3x + 2*5 step2: 6x + 2*5 solution: 6x + 10
user avatar
  • 235
0 votes
1 answer
53 views

select data conversion based on value range

I have a text file with 3 columns of data. However at random times in the various files there is a change in the in the observed unit from ppn to ppb resulting in the need of a conversion factor and ...
user avatar
0 votes
1 answer
28 views

How to keep blank data or assign missing data when recompiuting data for unit shift

I have a series of data files with format below. I have a script to read just the data to the needed units (ppm to ppb) thus the *1000 of column $3. The issue which I am running into when awk runs and ...
user avatar
0 votes
1 answer
158 views

If a sum equals zero how can I get awk to print another known value to the file

I have a numerous files in which I extract the total number of records and total number of missing files in order to compute data averages. I have numerous files where the number of missing records ...
user avatar
1 vote
1 answer
55 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 ...
user avatar
  • 187
0 votes
1 answer
27 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 ...
user avatar
0 votes
1 answer
90 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 ...
user avatar
  • 103
1 vote
3 answers
288 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....
user avatar
  • 199
1 vote
2 answers
371 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
user avatar
  • 454
2 votes
1 answer
123 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....
user avatar
1 vote
4 answers
867 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: '...
user avatar
-3 votes
2 answers
148 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 ...
user avatar
  • 89.7k
1 vote
5 answers
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 ...
user avatar
2 votes
1 answer
958 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 ./...
user avatar
2 votes
1 answer
4k 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 = ...
user avatar
0 votes
1 answer
2k 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 ...
user avatar
0 votes
1 answer
518 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 ...
user avatar
-1 votes
1 answer
220 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/...
user avatar
0 votes
1 answer
47 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 ...
user avatar
  • 3
0 votes
2 answers
507 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 ...
user avatar
1 vote
4 answers
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** ...
user avatar
1 vote
1 answer
765 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 < $...
user avatar
  • 358
2 votes
1 answer
375 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 ...
user avatar
  • 495
2 votes
1 answer
218 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.
user avatar
  • 323
0 votes
2 answers
63 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 ...
user avatar
1 vote
1 answer
933 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 ...
user avatar
  • 113
11 votes
1 answer
1k 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....
user avatar
  • 18.1k
3 votes
1 answer
355 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?
user avatar
  • 1,065
0 votes
1 answer
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 ...
user avatar
0 votes
2 answers
179 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 ...
user avatar
  • 217
1 vote
0 answers
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 ...
user avatar
  • 11
9 votes
1 answer
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 ...
user avatar
2 votes
1 answer
107 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 ...
user avatar
  • 195
-2 votes
3 answers
102 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?
user avatar
  • 11
0 votes
1 answer
1k 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 ...
user avatar
1 vote
2 answers
800 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 ...
user avatar
0 votes
1 answer
40 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?
user avatar
  • 693
1 vote
1 answer
674 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 ...
user avatar
3 votes
3 answers
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.
user avatar
2 votes
1 answer
66 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'...
user avatar
3 votes
2 answers
324 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: ...
user avatar
  • 562
3 votes
3 answers
186 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*(...
user avatar
  • 219