LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2011, 02:20 PM   #1
mamatu
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Rep: Reputation: Disabled
[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
Attached Thumbnails
Click image for larger version

Name:	2.jpg
Views:	15
Size:	253.0 KB
ID:	8713   Click image for larger version

Name:	5.jpg
Views:	9
Size:	253.4 KB
ID:	8714  
 
Old 12-28-2011, 03:27 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
1 members found this post helpful.
Old 12-29-2011, 10:48 AM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
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?
 
Old 12-29-2011, 05:57 PM   #4
mamatu
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can function subprograms have arrays?.spot the error mamatu Programming 10 12-30-2011 11:21 PM
subprograms for bash shell-script soujiro777 Linux - Newbie 4 02-22-2008 08:53 PM
g77 in gcc 4.1.0 not found only gfortran fortran 95 compiler! I need fortran 77. TheBrick Linux - Software 3 07-04-2007 06:39 AM
Gnu Fortran versus Intel Fortran tomatoefish Linux - Software 3 02-20-2006 01:31 PM
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration