- #1
Amany Gouda
- 29
- 0
I tried to calculate the cubic root by using the method that are exist in Numerical receipes 77 but I got no answer and I don't know my mistake .
Also, I tried by using Cardino method but Also I couldn't success to get an answer.
Can any read my codes and tell me where is my errors or provide me with more ideas.
first code:
The second code:
(mentor note: code edited to remove bolding and to use code tags)
Also, I tried by using Cardino method but Also I couldn't success to get an answer.
Can any read my codes and tell me where is my errors or provide me with more ideas.
first code:
Fortran:
! this program is made by using numerical receipes book version 77.
2 !------------------------------------------------------------------
3 program main
4 implicit none
5 real*8::Q,R,Theta,b,c,d
6 real*8,parameter::pi=3.14
7 complex*8::z1,z2,z3,x1,x2,x3
8 print*,'b,c,d'
9 read*,b,c,d
10
11 Q=((b**2)-(3*c))/9
12 R=((2*(b**3))-(9*b*c)+(27*d))/54
13
14
15 Theta=acos(R/(sqrt(Q**3)))
16
17 x1=-2*(sqrt(Q))*(cos(Theta/3))-(b/3)
18 x2=-2*(sqrt(Q))*(cos((Theta+2*pi)/3))-(b/3)
19 x3=-2*(sqrt(Q))*(cos((Theta-2*pi)/3))-(b/3)
20
21
22 print*,'x1=',x1,'x2=',x2,'x3=',x3
23
24
25 z1= sqrt(x1)
26 z2= sqrt(x2)
27 z3= sqrt(x3)
28
29
30 print*,' z1,z2,z3',z1,z2,z3
31 end program
Fortran:
! this program is made to used for calculating the cardino method for the our system parameters.
2 !-----------------------------------------------------------------------------------------------
3 program main
4 Implicit none
5 Integer::i,a
6 real*8,dimension (100):: Il,Il2,a0,omega,nominator,dominator
7 real*8,dimension(100)::f,lamda,kk,sum0,sum1,b,c,d,cardino3,Delta3
8 real*8,parameter::mass_ratio=0.00870
9 complex*8,dimension(100)::z1,z2,z3
10
11 a=1
12 Il=0.0
13 Il2=0.0
14 sum0=0.0
15 sum1=0.0
16
17 do i =1,100
18
19 Il(i)=sum0(i)+0.1
20
21 omega(i)=2.359*Il(i)
22 nominator=2-omega(i)
23 dominator=1-omega(i)
24 f(i)=nominator(i)/dominator(i)
25 lamda(i)=sqrt(f(i))
26 kk(i)=1/lamda(i)
27
28 Il2(i)=sum1(i)+0.001
29 a0(i)=0.68*Il2(i)
30
31 sum0=Il(i)
32 sum1=Il2(i)
33
34
35 print*,'Il=',Il(i)
36 print*,'Tl2=',Il2(i)
37 print*,'omega=',omega(i)
38 print*,'a0=',a0(i)
39 print*,'lamda=',lamda(i)
40 print*,'kk=',kk(i)
41
42 call eqn_parameter(omega(i),a0(i),kk(i),b(i),c(i),d(i))
43
44 print*,'b=',b(i)
45 print*,'c=',c(i)
46 print*,'d=',d(i)
47
48 call cardino_method(a,b(i),c(i),d(i),cardino3(i),Delta3(i))
49
50 print*,' carino_solution',cardino3(i)
51 print*,'Delta0=',Delta3(i)
52
53 call fsub(cardino3(i),b(i),Delta3(i),z1(i),z2(i),z3(i))
54
55
56 print *, "Omega1_square= ",z1(i)
57 print *, "Omega2_square= ",z2(i)
58 print *, "Omega3_square= ",z3(i)
59
60
61 end do
62 end program
63
64
65 subroutine eqn_parameter(x,t,s,f1,f2,f3)
66 implicit none
67 real*8,dimension(100),intent(in)::x,t,s
68 real*8,dimension(100),intent(out)::f1,f2,f3
69 real*8,dimension(100)::bb,cc1,cc2,cc3,dd
70
71 bb=-(2.0+x)
72 cc1=2.0*x
73 cc2=2.0*s*t*0.00870
74 cc3=(1.0d0+cc1-cc2)
75 dd=-(x+cc2)
76
77 end subroutine eqn_parameter
78
79
(mentor note: code edited to remove bolding and to use code tags)
Last edited by a moderator: