Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28499 Discussions

Simple Console Application Calculation in Fortran

kaffee46
Beginner
978 Views
Hi Guys,

what i want to do is to calculate the hardness of an steel after quenching with an simple
Fortran Console Application. Unfortunately i dont know how to write my formula in Fortran:



33307-HJ-Formel.jpg


This is my Fortran-Code so far:
[fortran]-----------------------------------------------------------------------------------------------------
program Calculation implicit none DOUBLE PRECISION:: HV ! HV=Hardness after tempering REAL:: HVQ, Temp, time ! HVQ=Hardness after Quenching, Temp=Temperature, time=time Print *, 'Please enter HVQ'; READ *, HVQ Print *, 'Please enter the temperature'; READ *, Temp Print *, 'Please enter the time'; READ *, time HV=HVQ-139,24(.....) ???? Print *, HV end program Calculation [/fortran]
-----------------------------------------------------------------------------------------------------

Can anybody help me with the integration of this formula?
The result has to be double precision, thats why i have chosen double precision for HV - i hope this is correct.

Thanks a lot!!!!
Marco
0 Kudos
18 Replies
Arjen_Markus
Honored Contributor I
978 Views

You will need to change "139,24" to "139.24" - Fortran, like most programming languages, uses the
decimal period (.) to separate fractions, not a comma.

Furthermore, the integral as I read it can be solved analytically. That will give you a formula you
can readily implement:

- exponentiation (2 to the power 4 for instance): 2.0**4 (or 2.0**4.0)

- the exponential function: exp(x)

That should get you started.

Regards,

Arjen

0 Kudos
mecej4
Honored Contributor III
978 Views
Fortran has no built-in capability for evaluating integrals, and I don't see why this post is appropriate for this forum.

The integral that you displayed, however, has a trivial explicit formula, and the whole expression can be easily evaluated with a calculator that has the standard transcendental functions.
0 Kudos
kaffee46
Beginner
978 Views
Thanks a lot for your quick answers. I tried to implement the fortran code, but is doesnt work...
Is anybody able to give me the fortran code of this function?
0 Kudos
kaffee46
Beginner
978 Views
This is my Fortran Code:
[fortran]HV=HVQ-139.24*(Temp*exp(33.21*Temp)*time**(Temp-1.0))**4.4867*10**(-5)[/fortran]

Unfortunately i am receiving an run-time error (see picture).



Wrong Code?!

Thanks
marco
0 Kudos
Arjen_Markus
Honored Contributor I
978 Views

Well, the message is quite clear: the exp() function has gotten an argument that leads to a result
that is too large to represent.

What is the value of the variable Temp (temperature)?

Are the variables defined as double precision (you need to use double precision constants too: 33.21d0 is one way to achieve that).

If that is the case, then you will need to rework the mathematical formula you are implementing to reduce the magnitude of the various intermediate results. That is not all that difficult (and check the integral - you have used the integrand, not the integral)

And 4.4867*10**(-5) can be more conveniently written as: 4.4867d-05 - right now it is actually turning out to be: 4.4867. The reason is that 10 to the power -5 is 1/100000 --> 0, as 10 is an integer.
The notation 4.4867d-05 (or 4.4867e-05 for single precision) is a very common one.

Regards,

Arjen

0 Kudos
kaffee46
Beginner
978 Views
Temperature and time have to be entered in Kelvin and seconds.
500C = 773K, 24 minutes = 1440 seconds.
In an calculation example Temp=773K, time=1440 sec, HVQ=849.
The result for HV should be around 400.

Do you think that i translated the function correctly into fortran:
HV=HVQ-139.24*(Temp*exp(33.21*Temp)*time**(Temp-1.0))**4.4867*10**(-5)

(I disregarded the integration...)

I will check your proposals...thanks!!
0 Kudos
Arjen_Markus
Honored Contributor I
978 Views
As the values for temperature and time lead to very large numbers, consider doing some of the
computations logarithmically first:

exp( ( log(Temp) + 33.21*Temp + ... ) * 4.4867d-5 )

Regards,

Arjen
0 Kudos
anthonyrichards
New Contributor III
978 Views
Where did you get this formula from? Are you sure you have copied it correctly? Clearly 33.21*Temperature as the exponent will rapidly exceed its permitted maximum value for temperatures>25 degrees, since 10**365=e**840 = e**(33.21*25.3).

Anyway, you have specified an Integral, so it must be evaluated at a number of values of the independant variable (assumed here to be time) between its minimum (0?) and a given maximum value and the sum computed. The method of integration and time steps chosen to give the most accurate result will depend on the shape of the graph of the integrand as a function of the independant variable.
0 Kudos
mecej4
Honored Contributor III
978 Views
Try this, which has the integration result written explicitly and the expression rearranged to avoid overflow:

[fxfortran]      program hvqev
      implicit none
      double precision HVQ,t,tt,HV
      HVQ=849
      t=1440
      tt=773
      HV=HVQ-139.24d0*exp(33.21d0*4.4867D-5*tt)*t**(tt*4.4867D-5)
      write(*,*)HV
      end
[/fxfortran]
0 Kudos
kaffee46
Beginner
978 Views
Thanks a lot for your help so far!

Yes, the function is correct, i checked it again. I copied it from an old book for steel treatment.
The result of mecej4 is 282, the result of the book for the given values should be around 400....

There is a integral because there is the pissibility to calciulate the tempering with a temperature periodically changing according to a sinosodial function in time. But in my case this is unimportant becsause i do have only
a fix temperature and a fix time.

So any ideas why the result is not 400 :-) ?
0 Kudos
kaffee46
Beginner
978 Views
.............................
0 Kudos
anthonyrichards
New Contributor III
978 Views
If the formula you gave is correct and Temperature T is constant, the integral is easy and Mecej4's function is correct and the answer is indeed approximately 282. If you want an answer near 400, you need to either change the time to 1.72 seconds, or change the temperature to 644.5 degrees, or use a different formula.
0 Kudos
Steven_L_Intel1
Employee
978 Views
Is this a school assignment?
0 Kudos
kaffee46
Beginner
978 Views
It is part of a diploma thesis...

I checked again the formula, it is correct. The result should as per my book be 400, if the temperature is 773 and the time 1440 sec. I dont know why the result is 282...

Marco
0 Kudos
mecej4
Honored Contributor III
978 Views
I deplore the use of dimensionally inhomogeneous formulae such as the one that you seem to trust, because they are valid only when the input quantities are expressed in a specific set of units. Therefore, such a formula with no explicit list of the proper units given is a worthless/suspicious formula.

Checking a formula for correctness involves more than mere lexical comparison with the printed paper. Once in a while, one needs to spend the time to rederive the formula from fundamental principles.

I dont know why the result is 282.

Nor should you expect anyone in this forum to tell you why it should not. In fact, the formula that you gave has only one possible result, and that result has been confirmed for you by at least two people. The answer to the mathematical question is, therefore, complete -- at least until you advance valid mathematical counterarguments.

Given that you have not quoted any references, and given that the disputed result is far off-topic, most people here probably do not care whether the result is 282 or 400 or something else.

One expects a higher level of understanding and stronger logical reasoning from a diploma candidate than has been shown in this thread.


0 Kudos
anthonyrichards
New Contributor III
978 Views
The formula is dimensionally weird too - raising a quantity with dimension Time to a power with dimension Temperature implies a non-physical source, possibly a fit to a curve.
0 Kudos
mecej4
Honored Contributor III
978 Views
That's exactly one of the points I attempted to make. Specifically, the exponent in the integrand is T - 1. That makes no sense at all, since 1 K or 1 C has no physical significance regarding the hardening of, say, steel.

On the other hand, if this is a non-dimensional version of (T-T_0)/T_0, with T_0 an established transformation temperature, it may make physical sense, but T_0 has to be listed!
0 Kudos
kaffee46
Beginner
978 Views
Thanks for all your answers and critics. The questions was from beginning on to build a little Fortran application with the formula i gave to you and with the help of the Forum it worked - thanks for that.
I think therefore my questions was not off-topic.

Why the result is 282 and not 400 is another topic, this is correct, mecej4.

But again, thanks for your help!
0 Kudos
Reply