Taking 1/7 power of a variable

In summary: Yes, Pascal has separate names for the two division operations as you say. However, it's worth noting that C++ does not have this distinction and instead uses the names 'div' and '/'.I use integer division often. This operation and the modulus operation are useful in converting days to weeks and days, ounces to pounds and ounces, making change, and many other applications.Doesn't Pascal have separate names for the two division operations? 'div' for integer and '/' for floating-point IIRC. That makes the distinction more obvious and let's you choose between the two where appropriate.
  • #1
abdulsulo
14
0
Hello there. I am trying to take a power of 1/7 of one variable but as a default it gives me 1 similar to if I was taking power of 0. How can I solve this problem. Thanks
 
Technology news on Phys.org
  • #2
What exactly did you write? I suspect that the 1/7 is being treated as an integer operation and rounded to 0.
 
  • Like
Likes abdulsulo
  • #3
Fortran:
Do I=2,N,1
X1=(Yr(I)/R)
X2=X1**(1/7)
Ua(I)=Um*X2
END DO

X1 and X2 are both double precision. I decided to divide the equation and take power but still it didn't work for me.
On first iteration I am giving you the values of variables there;
R=0.05
Um=2
Yr= 2.85E-05

Whatever I do it gives X1**(1/7) as 1 which is not correct.
 
  • #4
DrClaude said:
What exactly did you write? I suspect that the 1/7 is being treated as an integer operation and rounded to 0.
Your hint gave me an idea and I think I solved the problem. I put 1./7. to the equation and problem solved. Didn't notice it would roll it down to 0. Thank you very much.
 
  • #5
In the expression (1/7), since both 1 and 7 are integers, it is treated as an integer operation, and the result is returned as an integer, namely 0. Try (1.d0/7.d0) instead.
 
  • Like
Likes abdulsulo
  • #6
In addition to Fortran, the language used in the example of this thread, programming languages such as C and C++ also exhibit the same behavior of distinguishing between integer division and floating point division. As DrClaude already said, when both operands are integer values, the type of division that is performed is integer division. In this case, 1/7 is evaluated as 0. If one or both operands are a floating point type, then floating point division is performed.

The most commonly used CPUs for personal computers these days are those produced by Intel and AMD. Both types of CPU have one op code for integer division (DIV) and another for floating-point division (FDIV), which gives more precise results, but takes longer to calculate. Compilers for Fortran and C and C++ choose the type of division to perform based on the code you write.
 
  • Like
Likes abdulsulo
  • #7
This is by far the most common error made when you write your first fortran program from scratch followed by:

1) implicit/explict variable naming conventions where variables starting with i thru n are integers and all others are reals unless you say otherwise with explicit statements.

2) format statement errors where the description is too small for displaying the number.

3) for free-form fortran typing a C in column 1 created a comment line so you had to make sure that "character" or "common" statements were indented otherwise you got all sorts of compile-time errors.

I added all of these to my personal collection of errors made list more than forty years ago give or take but more take than give.

and there are many more subtle ones too.
 
  • Like
Likes abdulsulo
  • #8
If I ever designed a programming language, floating point division would be the default behavior. I do not recall the last time I actually used integer division.
 
  • #9
rumborak said:
If I ever designed a programming language, floating point division would be the default behavior. I do not recall the last time I actually used integer division.
I use integer division often. This operation and the modulus operation are useful in converting days to weeks and days, ounces to pounds and ounces, making change, and many other applications.
 
Last edited:
  • #10
Doesn't Pascal have separate names for the two division operations? 'div' for integer and '/' for floating-point IIRC. That makes the distinction more obvious and let's you choose between the two where appropriate. I wonder why more languages don't do this, except for their age and backwards-compatibility issues (e.g. Fortran, C, probably C++).
 
  • Like
Likes rumborak
  • #11
I think you got the answer right there, backwards compatibility. Or rather, most programming languages, the time they were introduced, tried to do a few things differently, but at the same time tried to make it easy for programmers to switch over. So, they stuck with non-essential stuff like that.
 

1. What does it mean to take 1/7 power of a variable?

Taking 1/7 power of a variable means raising the variable to the 1/7th power or finding the seventh root of the variable. This is a mathematical operation that involves finding the number that, when multiplied by itself seven times, gives the original variable.

2. How do you calculate the 1/7 power of a variable?

To calculate the 1/7 power of a variable, you can use a calculator or perform the calculation manually. If using a calculator, enter the variable, press the exponent button, and then enter 1/7. If performing the calculation manually, you can use the rule of exponents which states that x^(a/b) = (b√x)^a. In this case, the seventh root of the variable is taken first, and then it is raised to the first power.

3. What is the significance of taking 1/7 power of a variable?

The significance of taking 1/7 power of a variable depends on the context in which it is used. In mathematics, it can help to simplify expressions and solve equations. In science, it can help to find the relationship between variables and make predictions. In finance, it can help to calculate interest rates and growth rates.

4. Can you take 1/7 power of a negative variable?

Yes, you can take 1/7 power of a negative variable. However, the result will depend on whether the exponent is odd or even. If the exponent is odd, the result will also be negative. If the exponent is even, the result will be positive. For example, (-2)^1/7 = -1.139 and (-2)^2/7 = 1.067.

5. Is there a difference between taking 1/7 power and taking the seventh root of a variable?

No, taking 1/7 power and taking the seventh root of a variable are essentially the same operation. The only difference is in notation, where taking the 1/7 power is represented by using an exponent, and taking the seventh root is represented by using the radical symbol (√).

Similar threads

  • Programming and Computer Science
Replies
5
Views
365
  • Programming and Computer Science
Replies
4
Views
329
Replies
9
Views
3K
  • Programming and Computer Science
7
Replies
235
Views
9K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
4
Views
870
  • Introductory Physics Homework Help
Replies
1
Views
772
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Precalculus Mathematics Homework Help
Replies
4
Views
1K
Back
Top