How to find arcsin for a coulmn containg values?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find arcsin for a coulmn containg values?
# 1  
Old 09-04-2015
How to find arcsin for a coulmn containg values?

Hello everzone,

I have a column of values and i need to find arcsin for evry value in this column. I am very new to shell scripting and would be glad to receive any help regarding this. Also i want them to be saved in the next column.
Desired output:
Code:
#  #
a  arcsin(a)
b  arcsin(b)
c  arcsin(c)
d  arcsin(d)

Thanks,
Dinesh

Last edited by dinesh.n; 09-04-2015 at 04:43 AM..
# 2  
Old 09-04-2015
Hello Dinesh,

Could you please show the sample input too for your requirement. Also use code tags as per forum rules with your codes/same input.

NOTE: You can go through either forum rules or you can see a button in BAR while posting or replying to anyone named code.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-04-2015
Hello R. Singh,

Thanks for the info. I keep forgetting code tags. You can find a sample of my input file. Actually my original file will contain more then 50k lines in a column.
Code:
       
0.4       
2       
2.433105012       
2.433105012       
2.8       
3.12409987       
3.12409987       
3.687817783       
3.687817783       
4.4

I am able to calculate the arcsin using python script. But large part of my code is in shell and it would great if i am able to do the same using shell.

Thanks,
Dinesh.n

Last edited by dinesh.n; 09-04-2015 at 05:00 AM..
# 4  
Old 09-04-2015
Given that the domain of values for the arcsine function is -1 <= x <= 1 and most of your values are not in that range, I'm not sure why we should bother.

And, you haven't told us what operating system or shell you're using.

If you have a 1993 or later version of ksh on your system, the following is a simple way to do what you requested:
Code:
#!/bin/ksh
while read x
do	printf '%15.10f %15.10f\n' "$x" "$((asin(x)))"
done < file

which, with your sample input in file with blank lines removed, produces the output:
Code:
   0.4000000000    0.4115168461
   2.0000000000            -nan
   2.4331050120            -nan
   2.4331050120            -nan
   2.8000000000            -nan
   3.1240998700            -nan
   3.1240998700            -nan
   3.6878177830            -nan
   3.6878177830            -nan
   4.4000000000            -nan

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 09-04-2015
Hello R. Singh,

I want the value of inverse sin. Also i cant reply your mess since i have less then ten post made. Anyway i really apppreciate your effort.

Thanks,
Dinesh.n
# 6  
Old 09-04-2015
Hello Dinesh,

No problem, I requested you to post in actual post only not in message. Following may help you in same.
Code:
 awk '{print atan2($0, sqrt(1-$0 * $0))}' Input_file 2>/dev/null

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 09-04-2015
Hello Don Cragun,

Thats true you are right. I am sorry for wasting most of your time. My real value should be looking:

Code:
  -37.5    40.96950085
  -37.5    40.57708713
  -37.5    40.20572099
  -37.5    39.85599077
  -37.5    39.52847075
  -37.5     39.22371731
  -37.5     38.94226496
  -37.5    38.68462227
  -37.5    38.45126786

I want the first column to be divided by the second column and then i want to find arcsin for this values. For eg,
PHP Code:
arcsin($1/$2
. I am using red hat linux and my script are in "ksh".

Thanks,
Dinesh.n
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

2. Shell Programming and Scripting

Extract Lines Containg a Keyword

Hi , I have two files, say KEY_FILE and the MAIN_FILE. I am trying to read the KEY_FILE which has only one column and look for this column data in the MAIN_FILE to extract all the rows that have this key. I have written a script to do so, but somehow it is not returning all the rows ( It... (4 Replies)
Discussion started by: Sheel
4 Replies

3. Shell Programming and Scripting

find values between values in two different fields

Hi, I need help to find values between two different fields based on $6 (NUM) AND $1 (CD), within the same ID. The result should show the values between the NUMs which will be extracted from within $3 and $2 in data.txt file below. data.txt ex 139 142 Sc_1000004 ID 4 CD ... (2 Replies)
Discussion started by: redse171
2 Replies

4. UNIX for Dummies Questions & Answers

pattern containg ' search and replace

Hi guys I'm new to this forum so please help me in this I have a file where i need to replace a pattern value=' ' with the pattern value='abc' and moreover that abc value must be passed from some variable say i assign name=abc and use name as the value to replace instead of the direct string... (10 Replies)
Discussion started by: sundarj
10 Replies

5. Shell Programming and Scripting

replace value with double quotes of specific coulmn value in csv file

Hi, I am trying to replace a specific column values in a csv file with double quotes. Example: SNO,NAME,ZIPCODE,RANK 1,Robert,74538,12 2,Sam,07564,13 3,Kim, Ed,12345,14 Desired Output: SNO,NAME,ZIPCODE,RANK 1,Robert Ken,74538,12 2,Sam Mik,"07564",13 3,"Kim, Ed",12345,14 I... (3 Replies)
Discussion started by: techmoris
3 Replies

6. Shell Programming and Scripting

output nohup file containg the PID

Hi to everybody. Is it possible to nohup a process and redirect the output to a file containing the PID? E.g. if nohup filename > out.nohup associate the PID=8074 to filename, is it possible to call the output file something like out_8074.nohup instead of out.nohup? By this way it would... (0 Replies)
Discussion started by: plsrn
0 Replies

7. Shell Programming and Scripting

How to merge different coulmn of differnt files

hello gurus , i want to merge different column from two different file. file struture is below. file 1 ------- ~information is given Name class section A 5 b B 7 C D 8 A file 2 (10 Replies)
Discussion started by: rahul sharma11
10 Replies

8. Shell Programming and Scripting

Create Summary file containg information

Folks, I have multiple files in a folder containing some information (there is around 100 of them). What I would like to do would be able to import some of the information into a summary text file so that it will be easier to read a glance. The name of the files all start with the naming... (4 Replies)
Discussion started by: lodey
4 Replies

9. Shell Programming and Scripting

Paste coulmn wise

Hello, I need few clarification in types of paste command ussage in coulmn mode : In a directory i have few file distinguished as *.cpu *.vmem and *.mem and have coulmn entries like first cpu file 89576 89576 89576 89576 89576 89576 89576 second cpu file 46312 46312 46312 (3 Replies)
Discussion started by: er_aparna
3 Replies
Login or Register to Ask a Question