- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is anybody able to give me the fortran code of this function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
computations logarithmically first:
exp( ( log(Temp) + 33.21*Temp + ... ) * 4.4867d-5 )
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 :-) ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page