[fortran query]can functions subprograms have arays?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[fortran query]can functions subprograms have arays?
i have been given a question(which i have attached,named 2 and 5).i am having problems in the code..please someone help me with the corrections
here is what i have done
Code:
CODE
!hello..this is a questions of newton iteration
!in this i need to generate the first 10 roots of the given equation F=theeta*(1/(1-(a*h/sigma)))
!as you can see that the equation is a function of theeta and i also been given an equation for theeta
! theeta=(1-1/(((n-0.5)**2)*(3.142**2)*(k**2)))*3.142*(n-0.5)
!annd now you can see that theeta is a function of n..that is the number of roots..for for the first root.i have n=1 and so on..10
!also i need to have the derivative of the function because it will be needed for the newton iteration
!DF=1/(cos(theeta**2)) as u c that it depends on theeta as well
! so u see that i need to have the roots(theeta) for each value of n..and all these values of rooots need to be stored in an array
!then having done all this..these values of roots will be needed to calculate the values of the fnal equation which i have ommited for now
! i have made three function subprograms for these equations that i have mentioned.and this subroutine..but i am getting errors and warnings
!please make corrections and add comments for identification so that i can know my mistakes
PROGRAM NEWTON
real theeta(10),f(100),df(100),eps
theeta(1)=0.1
EPS=0.00001
CALL NEWT(theeta,X,EPS)
STOP
END
!-------------------------------------------------!
SUBROUTINE NEWT(theeta,X,EPS)
real theeta(10),f(100),df(100)
integer L
do L=1,10
X=theeta(L)-(F(theeta(L))/DF(theeta(L)))
DO WHILE(ABS(X-theeta(L)) .GT. EPS)
theeta(L)=X
X=theeta(L)-(F(theeta(L))/DF(theeta(L)))
END DO
end do
RETURN
END
!--------------------------------
function theeta(n)
integer n(10)
real k,a,h,sigma,theeta
dimension theeta(10)
a=0.1
h=23.0
sigma=46.0
k=1-(a*h/sigma)
do i=1,10
theeta(i)=(1-1/(((i-0.5)**2)*(3.142**2)*(k**2)))*3.142*(i-0.5)
end do
return
end
!-------------------------------------------------------------------------
FUNCTION F(theeta)
real a,h,sigma,f(9),theeta(9)
integer m
a=0.1
h=23.0
sigma=46.0
do m=2,10
F(m)=theeta(m)*(1/(1-(a*h/sigma)))
enddo
WRITE(6,10)theeta,F
10 FORMAT(22X,F16.7,4X,F16.7)
RETURN
END
!-------------
FUNCTION DF(theeta)
real df(9),theeta(9)
integer j
do j=2,10
DF(j)=1/(cos(theeta(j)**2))
end do
RETURN
END
Certainly, subprograms can have arrays. They're local variables, of course, allocated on the runtime stack, but there's nothing exceptional about that.
It sounds to me like you've gotten yourself fairly confused, after whacking on this program for a while. Maybe the best thing to do is to print the whole thing out on paper, then sit down with a pencil and a legal pad and work out your thoughts. First, what do you want the program to do. Then, what does the program as-written actually do? Finally, reconcile the two. Get away from the computer for a while; get away from the screen.
I'm confused. You seem to be trying to declare array-valued functions, but then use the result as a single real value. Do theeta, f and df return arrays or single values?
hello people.. almost done with it..but having a problem which i have highlighted in BOLD..
and the other thing is that the problem requires me to plot a graph of Tcenter vs time ,t
how to do this?.
i have attached the question paper for your reference..
thank you
Code:
DIMENSION THEETA(10),DF(10),F(10),c(10),b(10),t(10),x1(10),z(10),sum_1(10), Tcenter(10),r(10)
REAL K,THEETA,DF,F,c,b,sum_1,x,z,T0, Tcenter,alpha,r
integer t,y,p,j,l,m
A = .1
H = 23.
SIGMA = 46.
Alpha=0.000012
K = 1.-(A*H/SIGMA)
EPS = .0001
T0=250.0+273.0
DO N=1,10
!
! First calculate THEETA value
!
RN = N
THEETA(N)=(1.-1./(((RN-0.5)**2)*(3.142**2)*(K**2)))*3.142*(RN-0.5)
!
! Then using that THEETA value -- get derivative
! conversion of degrees into radians
r(n)=theeta(n)*3.142/180
DF(N) = 1./COS(r(N)**2)
!
! Then using that same THEETA value -- get F
!
F(N) = r(N)*(1./K)
!hence r is the value of angle in radians,df the derivative and f the function
print*,r(n),df(n),f(n)
END DO
!
! The make next loop here to get closure on a root, since you got all
! 10 values for F,DF, etc.
!
!--------------------------------------------------
!---------------------------------------
!now here is where i am having problems and because of this it only executes upto the above results of r ,df and f and then the fortran stops responding
!what i want is that for EVERY vallue of r there would be a number of iterations and i should therefore get the root from the newtons formula for each value of r and i also want to know how many iterations where there for each value of r
! so for example if for a value of r of 1.511102e-02 there were ..lets say...4 iterations and athe result..that is..the root ..was 0.0015
!but i think there is something wrong with this do loop..please help identify and correct
m=0
do l=1,10
10 m=m+1
x=r(l)-(f(r(l))/df(r(l)))
if(abs(x-r(l)).lt.eps) goto 20
r(l)=x
goto 10
20 x1(l)=x
print *,'The Root is',x1(l),'valu',m
end do
!-----------------------------------------------------------------
do p=1,10
C(p)=(4*sin(x1(p)))/(2*(x1(p))-sin(2*(x1(p))))
B(p)=(x1(p)*alpha**2)/(a**2)
print*,c(p),b(p)
end do
do i=0,9
t(i)=i*60
print*,t(i)
enddo
do j=1,10
y=j-1
z(j)=-(b(j)*t(y))
sum_1(j)=(C(j)*z(j))
Tc(j)=T0*((a*h)/(sigma))*sum_1(j)
print*,sum_1(j)
end do
end
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.