Run-time error M6201: math -log: DOMAIN error

In summary, the conversation discusses a run-time error that occurred while executing a Fortran program. The error is related to the domain of the log function and may be caused by zero or negative values in the input data. The code for the program is also included and the person seeking help is advised to insert WRITE statements to identify where the issue is occurring.
  • #1
js6201
7
0
Hi all,
I am facing the problem while executing my fortran (77) program.
please help me how to fix it.
As I understood, the error means that the domain of log function has included zero values or negative values...But I could not understand...In my case... there are no zero or negative values...ㅜㅜ...

Homework Statement


run-time error M6201: math -log: DOMAIN error

Homework Equations


4th-order runge-kutta method
Ordinary differential equation

I attached the fortran source code below...
[ /CODE ]

Program Runge

REAL t, dt, dt2, beta, sd0
REAL k1(20000), k2(20000), k3(20000), k4(20000)
REAL D(20000), m1(20000), m2(20000), m3(20000), m4(20000)
REAL rat(20000), fc(20000)
integer i

open(unit=1,file="input",form="formatted",status="unknown")
read(1,*) n0d,t0,tf,gk,c
read(1,*) sd0,denp,kadot,kbdot,visB1

t=t0
dt=(tf-t0)/n0d
H=dt/6.d0
dfc=2000E-6
beta=dlog10(2.d0/3.d0)/log10(dfc/sd0)
D(1)=sd0
m1(1)=0.0
m2(1)=0.0
m3(1)=0.0
k1(1)=0.0
k2(1)=0.0
k3(1)=0.0
k4(1)=0.0
fc(1)=3.0*((D(1)/sd0)**beta)
rat(1)=beta*log(D(1)/sd0)+1

i=2

DO WHILE (i. le. n0d)

rat(i)=beta*log(D(i-1)/sd0)+1.0
fc(i)=3.0*(D(i-1)/sd0)**(beta)

k1(i)=(gk*(sd0**beta)/rat(i))*((kadot/3)*(c/denp)*((sd0)**
& (fc(i)-3))*(D(i-1)**(-fc(i)+4-beta))-(kbdot/3)*((visB1)**0.5)*
& (sd0**(-1.0+(1/3)*fc(i)))*(D(i-1)**(2-beta-fc(i)/3))*((D(i-1)
& -sd0)**1.0))

m1(i)=real(D(i-1)+k1(i)/2.0d0)

k2(i)=(gk*(sd0**beta)/rat(i))*((kadot/3)*(c/denp)*((sd0)**
& (fc(i)-3))*(m1(i)**(-fc(i)+4-beta))-(kbdot/3)*((visB1)**0.5)*
& (sd0**(-1.0+(1/3)*fc(i)))*(m1(i)**(2-beta-fc(i)/3))*((m1(i)
& -sd0)**1.0))

m2(i)=real(D(i-1)+k2(i)/2.0d0)

k3(i)=(gk*(sd0**beta)/rat(i))*((kadot/3)*(c/denp)*((sd0)**
& (fc(i)-3))*(m2(i)**(-fc(i)+4-beta))-(kbdot/3)*((visB1)**0.5)*
& (sd0**(-1.0+(1/3)*fc(i)))*(m2(i)**(2-beta-fc(i)/3))*((m2(i)
& -sd0)**1.0))

m3(i)=real(D(i-1)+k3(i))

k4(i)=(gk*(sd0**beta)/rat(i))*((kadot/3)*(c/denp)*((sd0)**
& (fc(i)-3))*(m3(i)**(-fc(i)+4-beta))-(kbdot/3)*((visB1)**0.5)*
& (sd0**(-1.0+(1/3)*fc(i)))*(m3(i)**(2-beta-fc(i)/3))*((m3(i)
& -sd0)**1.0))

D(i)=real(D(i-1)+H*(k1(i)+2*(k2(i)+k3(i))+k4(i)))

open(unit=1000,file="flocsize",form="formatted",status="unknown")
open(unit=2000,file="result",form="formatted",status="unknown")

write(1000,*) t, m1(i), m2(i), m3(i), D(i)
write(2000,*) i, k1(i), k2(i), k3(i), k4(i)
write(*,*) i, D(i)

i=i+1
t=t+dt

END DO
END
 
Last edited:
Physics news on Phys.org
  • #2
When posting source code, please use [ CODE ] [ /CODE ] tags (without the spaces) to enclose the code to preserve the original spacing.

You may think you have no zeros or negative values, but your code disagrees. You are reading input data from files, so it's impossible to tell where the problem might be occurring.

The best I can recommend is that you inserts WRITE statements in your code before each line where a LOG or DLOG function is executed and print out the values of the arguments being supplied to these functions.

When reporting errors, compilers and runt-time units sometimes include line numbers where the error occurred. It's always helpful to include this information with any request for help.
 

FAQ: Run-time error M6201: math -log: DOMAIN error

What does "Run-time error M6201: math -log: DOMAIN error" mean?

This error message indicates that there is an issue with a mathematical calculation involving logarithms. Specifically, the calculation may be trying to take the logarithm of a number that is not a valid input for the function, resulting in a "DOMAIN error."

What causes this error to occur?

This error can occur for a few different reasons. One common cause is attempting to take the logarithm of a negative number, which is not a valid input for the logarithm function. It can also occur if the input is zero or if the calculation results in an overflow.

How can I fix this error?

To fix this error, you will need to identify the specific calculation causing the issue and make sure that the inputs are valid for the logarithm function. This may involve adjusting the inputs or using a different formula or function to achieve the desired result. Additionally, you may need to check for potential overflow or divide-by-zero situations in your code.

Can this error be prevented?

Yes, this error can be prevented by carefully checking your input values before performing any calculations involving logarithms. You can also use conditional statements or error handling to catch potential issues and avoid the error from occurring.

Is it safe to ignore this error?

No, it is not safe to ignore this error. Ignoring the error may lead to incorrect results or unexpected behavior in your program. It is important to identify and address the cause of the error to ensure the accuracy and reliability of your code.

Similar threads

Replies
5
Views
2K
Replies
5
Views
2K
Replies
6
Views
9K
Replies
15
Views
2K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
7
Views
3K
Back
Top