Sponsored Content
Full Discussion: Maths with variables
Top Forums Shell Programming and Scripting Maths with variables Post 302388082 by DFr0st on Tuesday 19th of January 2010 10:38:43 AM
Old 01-19-2010
Maths with variables

Hello,
I'm trying to write a while loop for a decimal value in tcsh which I know can't be done. Instead I want my increments to be one order of magnitude too large and then divide it by 10 when I use the variable. However, I don't know how to divide my variable and set it as another.

Code:
set RI_min = 10
set RI_max = 30
set RI_inc = 1

# Run Flex2d for each RI
set RI = $RI_min
echo "Calculating flexure for:"
while ($RI <= $RI_max)

@ RI = $RI + $RI_inc

I then want to set PI to equal RI/10 to use PI in another program so my PI values will range from 1.0 to 3.0.
Thanks

Last edited by Scott; 01-19-2010 at 11:48 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with Maths

Heres a script i wrote as a bit of practise. What it does is insert a line in the middle of a file. The line being $1 and the file being $2 #!/bin/bash rm tempfile touch tempfile count=1 linenum= `wc -l < $2` if then echo $1 >> $2 else even=`expr "$linenum" % 2` if then... (3 Replies)
Discussion started by: Quesa
3 Replies

2. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

3. Shell Programming and Scripting

Perl - maths equation - need help

if input to the perl program is ' ( p * ((a+b) * (c+d))) + q ' it shuld give the output as ' pac + pad + pbc + pbd + q ' .can anyone suggest a way to do this ? (7 Replies)
Discussion started by: Anuj8584
7 Replies

4. Shell Programming and Scripting

Using IF statements with maths where the input is not an integer

Hi All I've made a few scripts which using GDAL extract the value of a pixel within a given raster. The purpose is to work out the combine value of every pixel. I thought there may have been an easier way to do this but alas! The code below extracts the pixel value at position X Y. The... (3 Replies)
Discussion started by: StudentFitz
3 Replies

5. Shell Programming and Scripting

Simple maths calculator loop.

Hi, I am trying to make a maths calculator that: 1. Prompts the user for a number. 2. Prompts the user for an operation (add, subtract, divide or multiply) 3. Prompts the user for a number. 4. Prompts the user for another operation (same as above) OR the option to get the result for the... (4 Replies)
Discussion started by: johnthebaptist
4 Replies

6. Shell Programming and Scripting

Maths in shell scripts

Hi, Need help on this. I need to increment a variable by 1 but retain as 2 characters. I am using expr to do additions: NEWSERIAL=`expr $SERIAL + 1` $SERIAL can range from 01-99. After adding "1", I need the result to be 2 characters, eg: 02+1 = 03. By default expr will truncate the... (4 Replies)
Discussion started by: vchee
4 Replies

7. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

8. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

9. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

10. Shell Programming and Scripting

Calculate the constant e to 14+ decimal places using integer maths.

Hi guys... I am loving this integer maths thing. 64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform. Using one of the 'Brothers' methods, URL inside the code. #!/bin/sh # # #!/usr/local/bin/dash # e_constant.sh # Brother's formula . #... (2 Replies)
Discussion started by: wisecracker
2 Replies
TGAMMA(3)						   BSD Library Functions Manual 						 TGAMMA(3)

NAME
tgamma, lgamma, gamma -- gamma and log of gamma SYNOPSIS
#include <math.h> double tgamma(double x); long double tgammal(long double x); float tgammaf(float x); double lgamma_r(double x, int *psigngam); long double lgammal_r(long double x, int *psigngam); float lgammaf_r(float x, int *psigngam); double lgamma(double x); long double lgammal(long double x); float lgammaf(float x); DESCRIPTION
tgamma() calculates the gamma function of x. lgamma() calculates the natural logorithm of the absolute value of the gamma function of x. gamma() is the same function as tgamma. Its use is deprecated. lgamma_r() is a thread-safe alternative to lgamma(). Instead of setting the global variable signgam, it stores the sign of Gamma(x) in the location pointed to by its second argument. In order to use the lgamma_r() function, define the macro _REENTRANT before including <math.h>. SPECIAL VALUES
tgamma(+-0) returns +-infinity and raises the "divide-by-zero" floating-point exception. tgamma(x) returns a NaN and raises the "invalid" floating-point exception if x is a negative integer. tgamma(-infinity) returns a NaN and raises the "invalid" floating-point exception. tgamma(+infinity) returns +infinity. tgamma(x) generates a domain error if x is a negative integer or if the result cannnot be respresented when x is 0. A range error may occur if the magnitude of x is too large or too small. lgamma(1) returns +0. lgamma(2) returns +0. lgamma(x) returns +infinity and raises the "divide-by-zero" floating-point exception if x is a negative integer or 0. lgamma(+-infinity) returns +infinity. lgamma(x) generates a range error if x is too large. A range error may occur if x is a negative integer or 0. NOTE
lgamma(x) and its variants have the (non-threadsafe) side-effect of setting the global variable signgam to +-1, equal to the sign of tgamma(x). lgamma_r(x, psigngam) instead sets the user-allocated integer pointed to by the psigngam argument. gamma() and gamma_r() are deprecated, and should not be used. The tgamma() function should be used instead. Note, however, that on some platforms, gamma() and gamma_r() historically computed the log of the Gamma function, instead of the Gamma function itself. When porting code from such platforms, it will be necessary to use lgamma() or lgamma_r() instead. SEE ALSO
math(3) STANDARDS
The tgamma() , and lgamma() functions conform to ISO/IEC 9899:2011. July 02, 2008
All times are GMT -4. The time now is 11:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy