Sponsored Content
Top Forums Shell Programming and Scripting how can i find sqrt of a any number without using expr Post 302302421 by srinivas2828 on Tuesday 31st of March 2009 01:07:17 AM
Old 03-31-2009
how can i find sqrt of a any number without using expr

hi friends
can any body tell me how can i find sqrt of a any given number without using expr in bash shell
while i am doing i got some errors please take a look
and code is here
x=$((( ( sqrt($1) ) | bc )))
echo $x

Code:
[srinivas@localhost shell-lab]$ sh quadratic-eqn-roots.sh 9
quadratic-eqn-roots.sh: line 12: ( ( sqrt(9) ) | bc ): missing `)' (error token is "(9) ) | bc )")

 

10 More Discussions You Might Find Interesting

1. Programming

sqrt

Hi! when i'm trying to compile this lite example on my linux machine I'll get errors and i don't know why.. #include <stdio.h> #include <math.h> /* needed by sqrt() */ int main() { printf("%f", sqrt(10.0)); return (0); } this is the error: /tmp/cc33hNVHK.o: In function... (1 Reply)
Discussion started by: CreamHarry
1 Replies

2. Programming

sqrt is not find???

I was writing a simple program in linux, which includes sqrt function of c. I included the math.h. But when I use gcc to compile it, it gave an error message: /home/murat/tmp/ccOv9upo.o(.text+0x4b): In function `main': : undefined reference to `sqrt' collect2: ld returned 1 exit status I... (2 Replies)
Discussion started by: murataht
2 Replies

3. Shell Programming and Scripting

How to create SQRT function in catenate file

HI, I have a file which i catenate and using the fields in the file, I would like to get sqrt of it. I tried to man the function but it normally would need an echo as well as bc. What I am intending to find out is catenate a file where let say cat a.txt| awk ' { t= h*($3+$2); t=... (7 Replies)
Discussion started by: ahjiefreak
7 Replies

4. Shell Programming and Scripting

Find first digit in string using expr index

I have looked for hours for an answer, so I have decided to request your guidance. I want to substract the first number (series of digits) contained in a string. This string is the output of another command. The substring (number) can be located at any position inside the string. I want to... (4 Replies)
Discussion started by: jcd
4 Replies

5. Shell Programming and Scripting

PERL: Simple reg expr validate 6 digits number

Hi there! I'm trying to validate a simple 6 digits number with reg expr. I ONLY want 6 digits so when i type 7 digits the script should no validate the number. I've write this code: #!/usr/bin/perl while(<STDIN>){ if($_=~/\d{6}/){ print "Bingo!\n"; ... (2 Replies)
Discussion started by: BufferExploder
2 Replies

6. Programming

C Library reference error using sqrt() - will not compile.

This so basic that it should work.... Any ideas would be appreciared. Using a number directly in the sqrt allows it to compile. primrose > cat a.c #include <stdio.h> #include <math.h> int main(void) { double abcd=9; printf("%f\n",sqrt(abcd)); } primrose > gcc a.c Undefined first... (2 Replies)
Discussion started by: plastichead
2 Replies

7. UNIX for Dummies Questions & Answers

sqrt in bash

Hi, i have a the following script: #!/bin/bash a=3 b=9 let "c= b*a" let "d=sqrt $c " echo $d But when i execute the code, it gives me the an error saying: line 5: let: d=sqrt 27 : syntax error in expression (error token is "27 ") Can any body tell me what I'm doing wrong? (5 Replies)
Discussion started by: limadario
5 Replies

8. Shell Programming and Scripting

Find command - using regular expr

Hi, I would like to use find command to find file with a predefined extension for example find . modules/*.ksh *.lib I thought it's possible to use something like : find . modules/*. but it does not work. is there any other way? Thanks you (2 Replies)
Discussion started by: zam
2 Replies

9. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

10. Shell Programming and Scripting

Q: Is SQRT(n) possible in a POSIX compliant shell? A: Yes within limits.

Hi all... This is just a fun project to see if it is possible to get a square root of a positive integer from 1 to 9200000 to 6 decimal places on a 64 bit architecture machine. It is coded around dash and the results show the values from 0 to 10000. Complex numbers can easily be catered for by... (3 Replies)
Discussion started by: wisecracker
3 Replies
EQN(1)							      General Commands Manual							    EQN(1)

delim $$

NAME
eqn, neqn, checkeq - typeset mathematics SYNOPSIS
eqn [ -dxy ] [ -pn ] [ -sn ] [ -fn ] [ file ] ... checkeq [ file ] ... DESCRIPTION
Eqn is a troff(1) preprocessor for typesetting mathematics on a Graphic Systems phototypesetter, neqn on terminals. Usage is almost always eqn file ... | troff neqn file ... | nroff If no files are specified, these programs reads from the standard input. A line beginning with `.EQ' marks the start of an equation; the end of an equation is marked by a line beginning with `.EN'. Neither of these lines is altered, so they may be defined in macro packages to get centering, numbering, etc. It is also possible to set two characters as `delimiters'; subsequent text between delimiters is also treated as eqn input. Delimiters may be set to characters x and y with the command-line argument -dxy or (more commonly) with `delim xy' between .EQ and .EN. The left and right delimiters may be identical. Delimiters are turned off by `delim off'. All text that is neither between delimiters nor between .EQ and .EN is passed through untouched. The program checkeq reports missing or unbalanced delimiters and .EQ/.EN pairs. Tokens within eqn are separated by spaces, tabs, newlines, braces, double quotes, tildes or circumflexes. Braces {} are used for grouping; generally speaking, anywhere a single character like x could appear, a complicated construction enclosed in braces may be used instead. Tilde ~ represents a full space in the output, circumflex ^ half as much. Subscripts and superscripts are produced with the keywords sub and sup. Thus x sub i makes $x sub i$, a sub i sup 2 produces $a sub i sup 2$, and e sup {x sup 2 + y sup 2} gives $e sup {x sup 2 + y sup 2}$. Fractions are made with over: a over b yields $a over b$. sqrt makes square roots: 1 over sqrt {ax sup 2 +bx+c} results in $1 over sqrt {ax sup 2 +bx+c}$ . The keywords from and to introduce lower and upper limits on arbitrary things: $lim from {n-> inf} sum from 0 to n x sub i$ is made with lim from {n-> inf } sum from 0 to n x sub i. Left and right brackets, braces, etc., of the right height are made with left and right: left [ x sup 2 + y sup 2 over alpha right ] ~=~1 produces $left [ x sup 2 + y sup 2 over alpha right ] ~=~1$. The right clause is optional. Legal characters after left and right are braces, brackets, bars, c and f for ceiling and floor, and "" for nothing at all (useful for a right-side-only bracket). Vertical piles of things are made with pile, lpile, cpile, and rpile: pile {a above b above c} produces $pile {a above b above c}$. There can be an arbitrary number of elements in a pile. lpile left-justifies, pile and cpile center, with different vertical spacing, and rpile right justifies. Matrices are made with matrix: matrix { lcol { x sub i above y sub 2 } ccol { 1 above 2 } } produces $matrix { lcol { x sub i above y sub 2 } ccol { 1 above 2 } }$. In addition, there is rcol for a right-justified column. Diacritical marks are made with dot, dotdot, hat, tilde, bar, vec, dyad, and under: x dot = f(t) bar is $x dot = f(t) bar$, y dotdot bar ~=~ n under is $y dotdot bar ~=~ n under$, and x vec ~=~ y dyad is $x vec ~=~ y dyad$. Sizes and font can be changed with size n or size +-n, roman, italic, bold, and font n. Size and fonts can be changed globally in a docu- ment by gsize n and gfont n, or by the command-line arguments -sn and -fn. Normally subscripts and superscripts are reduced by 3 point sizes from the previous size; this may be changed by the command-line argument -pn. Successive display arguments can be lined up. Place mark before the desired lineup point in the first equation; place lineup at the place that is to line up vertically in subsequent equations. Shorthands may be defined or existing keywords redefined with define: define thing % replacement % defines a new token called thing which will be replaced by replacement whenever it appears thereafter. The % may be any character that does not occur in replacement. Keywords like sum ( sum ) int ( int ) inf ( inf ) and shorthands like >= (>=) -> (->), and != ( != ) are recognized. Greek letters are spelled out in the desired case, as in alpha or GAMMA. Mathematical words like sin, cos, log are made Roman automatically. Troff(1) four- character escapes like (bs () can be used anywhere. Strings enclosed in double quotes "..." are passed through untouched; this permits keywords to be entered as text, and can be used to communicate with troff when all else fails. SEE ALSO
troff(1), tbl(1), ms(7), eqnchar(7) B. W. Kernighan and L. L. Cherry, Typesetting Mathematics--User's Guide J. F. Ossanna, NROFF/TROFF User's Manual BUGS
To embolden digits, parens, etc., it is necessary to quote them, as in `bold "12.3"'. 2/22/74 EQN(1)
All times are GMT -4. The time now is 09:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy