The tag has no usage guidance.

learn more… | top users | synonyms

3
votes
3answers
54 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: ...
0
votes
1answer
26 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 works well but as I am new too coding it looks very messy and repetitive. I ...
5
votes
3answers
414 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
14 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 ...
1
vote
2answers
123 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
413 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 ...
0
votes
1answer
227 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 ...
26
votes
20answers
7k 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
100 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 ...
5
votes
3answers
514 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 ...
6
votes
5answers
321 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 ...
3
votes
1answer
787 views

basic division using variable and integer

I'm an extreme beginner in bash commands, and am 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 ...
3
votes
3answers
80 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
42 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
685 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 - ...
2
votes
2answers
2k 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
434 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
989 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, ...
3
votes
2answers
280 views

How do I convert my old PC to a data logging and presentation terminal?

Take an old PC (e.g. 1.8GHz P4 with 256MB RAM), install e.g. Ubuntu 10.04 LTS on it. Now go to your PIC or AVR based home project and hook up the thing. With only three connections and the onboard ...
1
vote
3answers
168 views

how to type linear algebra symbols

How do I type the symbols for linear algebra on Ubuntu? Are there any programs that use them? ( I understand this is trivial basket weaving. Whats the fastest way! )
2
votes
1answer
189 views

Illustrate the difference of two squares via the command line

So, after 10 years of wanting to study the book that Ramanujan relied upon for a lot of his early strides in mathematics, it's 2012, and the book is finally online. To celebrate, I want to go through ...
27
votes
9answers
11k views

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 ...
0
votes
1answer
109 views

Why does octave give different results for 9 ^ 1/2 and 9 ^ 0.5?

Lately I've been trying to brush up on the math I should have learned in high school. (I didn't pay much attention.) Regarding this, college entrance exams and octave make a great pair. This morning ...
12
votes
4answers
4k views

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) ...