0% found this document useful (0 votes)
22 views12 pages

Sagar 16 PRGM PDF

Fortran programming language

Uploaded by

gsworld9896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views12 pages

Sagar 16 PRGM PDF

Fortran programming language

Uploaded by

gsworld9896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

C program on charging of capacitor

f(q)=v/r-q/(r*c)
open(3,file='r*c')
v=3.0
r=2.0
c=1.25
h=1.0
q0=0.0
t0=0.0
qfinal=q0
i=0
write(*,*)'i time charge'
write(3,*)i,t0,q0
7 i=i+1
s0=f(q0)
s1=f(q0+s0*h)
q1=q0+h*(s0+s1)/2.0
t0=t0+h
write(3,*)i,t0,q1
if(abs(qfinal-q1).ge.0.0001)then
q0=q1
qfinal=q0
go to 7
endif
stop
end

i time charge
1 1.00000000 0.00000000
2 2.00000000 1.20000005
3 3.00000000 2.01600003
4 4.00000000 2.57087994
5 5.00000000 2.94819832
6 6.00000000 3.20477486
7 7.00000000 3.37924695
8 8.00000000 3.49788785
9 9.00000000 3.57856369
10 10.0000000 3.63342333
11 11.0000000 3.67072773
12 12.0000000 3.69609499
13 13.0000000 3.71334457
14 14.0000000 3.72507429
15 15.0000000 3.73305058
16 16.0000000 3.73847437
17 17.0000000 3.74216270
18 18.0000000 3.74467063
19 19.0000000 3.74637604
20 20.0000000 3.74753571
21 21.0000000 3.74832439
22 22.0000000 3.74886060
23 23.0000000 3.74922514
24 24.0000000 3.74947309
25 25.0000000 3.74964166
26 26.0000000 3.74975634
27 27.0000000 3.74983430
28 28.0000000 3.74988747
29 29.0000000 3.74992347
30 30.0000000 3.74994802
31 31.0000000 3.74996471
32 32.0000000 3.74997592

------------------
(program exited with code: 0)
Press return to continue
c program on discharging of capacitor
f(q)=-q/(r*c)
open(3,file='rc')
v=2.0
r=0.5
c=1.25
h=1.0
q0=3.0
t0=0.0
qfinal=0.0
i=0
write(*,*)'i time charge'
write(3,*)i,t0,q0
7 i=i+1
s0=f(q0)
s1=f(q0+s0*h)
q1=q0+h*(s0+s1)/2.0
t0=t0+h
write(*,*)i,t0,q0
if(abs(qfinal-q1).ge.0.00001)then
q0=q1
qfinal=q0
go to 7
endif
stop
end

i time charge
1 1.00000000 3.00000000
2 2.00000000 2.03999996
3 3.00000000 1.38720000
4 4.00000000 0.943296015
5 5.00000000 0.641441286
6 6.00000000 0.436180055
7 7.00000000 0.296602428
8 8.00000000 0.201689661
9 9.00000000 0.137148976
10 10.0000000 9.32613015E-02
11 11.0000000 6.34176880E-02
12 12.0000000 4.31240276E-02
13 13.0000000 2.93243378E-02
14 14.0000000 1.99405495E-02
15 15.0000000 1.35595743E-02
16 16.0000000 9.22051072E-03
17 17.0000000 6.26994716E-03
18 18.0000000 4.26356401E-03
19 19.0000000 2.89922347E-03
20 20.0000000 1.97147205E-03
21 21.0000000 1.34060101E-03
22 22.0000000 9.11608688E-04
23 23.0000000 6.19893894E-04
24 24.0000000 4.21527860E-04
25 25.0000000 2.86638970E-04
26 26.0000000 1.94914493E-04
27 27.0000000 1.32541856E-04
28 28.0000000 9.01284584E-05
29 29.0000000 6.12873555E-05
30 30.0000000 4.16754010E-05
31 31.0000000 2.83392728E-05

------------------
(program exited with code: 0)
c growth of current in LCR circuit
f(t0,q,ci)=(-1.0*q)/(al*c)-(r/al)*ci
c=1.0
r=0.2
al=1.0
q0=0.0
h=0.1
ci0=1.0
to=0.0
z0=ci0
tmax=15.0
i1=0
write(*,*)'n time current'
write(*,*)i1,t0,ci0
10 i1=i1+1
s0=z0
p0=f(t0,q0,z0)
p1=f(t0+h,q0+s0*h,z0+p0*h)
z1=z0+h*(p0+p1)/2.0
s1=z1
q1=q0+h*(s0+s1)/2.0
write(*,*)i1,t0,q1,z1
t0=t0+h
if(t0.le.tmax)then
z0=z1
q0=q1
goto 10
endif
stop
End

n time current
0 2.80259693E-45 1.00000000
1 2.80259693E-45 9.87600014E-02 0.975199997
2 0.100000001 0.194581896 0.941237807
3 0.200000003 0.286575377 0.898631513
4 0.300000012 0.373905689 0.847974479
5 0.400000006 0.455800831 0.789928079
6 0.500000000 0.531557918 0.725213587
7 0.600000024 0.600548804 0.654604077
8 0.700000048 0.662224770 0.578915596
9 0.800000072 0.716120481 0.498998225
10 0.900000095 0.761856735 0.415727139
11 1.00000012 0.799142778 0.329993278
12 1.10000014 0.827777147 0.242694318
13 1.20000017 0.847648144 0.154725552
14 1.30000019 0.858732998 6.69711903E-02
15 1.40000021 0.861096323 -1.97042674E-02
16 1.50000024 0.854887903 -0.104464136
17 1.60000026 0.840339303 -0.186507329
18 1.70000029 0.817760170 -0.265075535
19 1.80000031 0.787533402 -0.339459926
20 1.90000033 0.750110030 -0.409007132
21 2.00000024 0.706003428 -0.473124653
22 2.10000014 0.655782938 -0.531285524
23 2.20000005 0.600067079 -0.583032131
24 2.29999995 0.539516509 -0.627979577
25 2.39999986 0.474826634 -0.665817797
26 2.49999976 0.406720072 -0.696313381
27 2.59999967 0.335938901 -0.719310105
28 2.69999957 0.263236940 -0.734729171
29 2.79999948 0.189372063 -0.742568374
30 2.89999938 0.115098618 -0.742900491
31 2.99999928 4.11600247E-02 -0.735871315
32 3.09999919 -3.17183733E-02 -0.721696556
33 3.19999909 -0.102836125 -0.700658381
34 3.29999900 -0.171524107 -0.673101306
35 3.39999890 -0.237150550 -0.639427483
36 3.49999881 -0.299126506 -0.600091755
37 3.59999871 -0.356910884 -0.555595934
38 3.69999862 -0.410014838 -0.506482959
39 3.79999852 -0.458005518 -0.453330725
40 3.89999843 -0.500509322 -0.396745592
41 3.99999833 -0.537214398 -0.337355882
42 4.09999847 -0.567872465 -0.275805235
43 4.19999838 -0.592299998 -0.212745890
44 4.29999828 -0.610378921 -0.148832083
45 4.39999819 -0.622056186 -8.47135261E-02
46 4.49999809 -0.627343297 -2.10290700E-02
47 4.59999800 -0.626314759 4.15994376E-02
48 4.69999790 -0.619106114 0.102572933
49 4.79999781 -0.605911434 0.161320627
50 4.89999771 -0.586980164 0.217305109
51 4.99999762 -0.562613547 0.270026982
52 5.09999752 -0.533160746 0.319029063
53 5.19999743 -0.499014288 0.363900065
54 5.29999733 -0.460605383 0.404277772
55 5.39999723 -0.418398917 0.439851612
56 5.49999714 -0.372888088 0.470364779
57 5.59999704 -0.324589074 0.495615661
58 5.69999695 -0.274035364 0.515458703
59 5.79999685 -0.221772194 0.529804826
60 5.89999676 -0.168350905 0.538621128
61 5.99999666 -0.114323348 0.541930079
62 6.09999657 -6.02364354E-02 0.539808214
63 6.19999647 -6.62679970E-03 0.532384396
64 6.29999638 4.59842905E-02 0.519837320
65 6.39999628 9.70958024E-02 0.502392888
66 6.49999619 0.146231502 0.480321050
67 6.59999609 0.192944169 0.453932166
68 6.69999599 0.236819431 0.423573166
69 6.79999590 0.277479261 0.389623433
70 6.89999580 0.314584941 0.352490336
71 6.99999571 0.347839683 0.312604666
72 7.09999561 0.376990706 0.270415932
73 7.19999552 0.401830882 0.226387531
74 7.29999542 0.422199845 0.180991858
75 7.39999533 0.437984705 0.134705469
76 7.49999523 0.449120194 8.80042911E-02
77 7.59999514 0.455588341 4.13588844E-02
78 7.69999504 0.457417786 -4.77006286E-03
79 7.79999495 0.454682469 -4.99361269E-02
80 7.89999485 0.447500110 -9.37112719E-02
81 7.99999475 0.436030060 -0.135689750
82 8.09999466 0.420470983 -0.175491631
83 8.19999504 0.401058108 -0.212766066
84 8.29999542 0.378060102 -0.247194231
85 8.39999580 0.351775795 -0.278491765
86 8.49999619 0.322530657 -0.306410968
87 8.59999657 0.290672988 -0.330742508
88 8.69999695 0.256570041 -0.351316720
89 8.79999733 0.220603973 -0.368004501
90 8.89999771 0.183167860 -0.380717784
91 8.99999809 0.144661486 -0.389409602
92 9.09999847 0.105487317 -0.394073725
93 9.19999886 6.60464317E-02 -0.394743949
94 9.29999924 2.67345868E-02 -0.391492903
95 9.39999962 -1.20615885E-02 -0.384430617
96 9.50000000 -4.99682538E-02 -0.373702645
97 9.60000038 -8.66277814E-02 -0.359487951
98 9.70000076 -0.121702000 -0.341996491
99 9.80000114 -0.154875159 -0.321466476
100 9.90000153 -0.185856551 -0.298161477
101 10.0000019 -0.214382991 -0.272367269
102 10.1000023 -0.240220785 -0.244388640
103 10.2000027 -0.263167500 -0.214545950
104 10.3000031 -0.283053368 -0.183171630
105 10.4000034 -0.299742281 -0.150606692
106 10.5000038 -0.313132465 -0.117197156
107 10.6000042 -0.323156863 -8.32905471E-02
108 10.7000046 -0.329783022 -4.92324121E-02
109 10.8000050 -0.333012789 -1.53629258E-02
110 10.9000053 -0.332881629 1.79863423E-02
111 11.0000057 -0.329457521 5.04955612E-02
112 11.1000061 -0.322839767 8.18595663E-02
113 11.2000065 -0.313157260 0.111790590
114 11.3000069 -0.300566703 0.140020758
115 11.4000072 -0.285250455 0.166304350
116 11.5000076 -0.267414242 0.190419793
117 11.6000080 -0.247284681 0.212171391
118 11.7000084 -0.225106567 0.231390730
119 11.8000088 -0.201140136 0.247937784
120 11.9000092 -0.175658152 0.261701792
121 12.0000095 -0.148942977 0.272601753
122 12.1000099 -0.121283561 0.280586571
123 12.2000103 -9.29724798E-02 0.285635084
124 12.3000107 -6.43029436E-02 0.287755609
125 12.4000111 -3.55658978E-02 0.286985248
126 12.5000114 -7.04718567E-03 0.283389032
127 12.6000118 2.09751986E-02 0.277058661
128 12.7000122 4.82336842E-02 0.268111050
129 12.8000126 7.44735748E-02 0.256686747
130 12.9000130 9.94553119E-02 0.242948025
131 13.0000134 0.122956559 0.227076843
132 13.1000137 0.144774035 0.209272638
133 13.2000141 0.164725170 0.189750046
134 13.3000145 0.182649493 0.168736458
135 13.4000149 0.198409796 0.146469489
136 13.5000153 0.211892992 0.123194471
137 13.6000156 0.223010808 9.91618410E-02
138 13.7000160 0.231700122 7.46245533E-02
139 13.8000164 0.237923130 4.98355515E-02
140 13.9000168 0.241667166 2.50452403E-02
141 14.0000172 0.242944375 4.99067828E-04
142 14.1000175 0.241791084 -2.35648025E-02
143 14.2000179 0.238266960 -4.69177142E-02
144 14.3000183 0.232453942 -6.93425834E-02
145 14.4000187 0.224455029 -9.06358287E-02
146 14.5000191 0.214392781 -0.110609107
147 14.6000195 0.202407777 -0.129090890
148 14.7000198 0.188656837 -0.145927802
149 14.8000202 0.173311159 -0.160985813
150 14.9000206 0.156554312 -0.174151167
c solution of RL circuit
f(ci)=v/al-(r/al)*ci
v=4.0
r=2.0
al=1.0
h=0.1
ci0=0.0
t0=0.0
cifinal=ci0
i1=0
write(*,*)'n time current'
write(*,*)i1,t0,ci0
7 i1=i1+1
s0=f(ci0)
s1=f(ci0+s0*h)
ci1=ci0+h*(s0+s1)/2.0
t0=t0+h
write(*,*)i1,t0,ci1
if(abs(cifinal-ci1).ge.0.001)then
ci0=ci1
cifinal=ci1
go to 7
endif
stop
end

n time current
0 0.00000000 0.00000000
1 0.100000001 0.359999985
2 0.200000003 0.655200005
3 0.300000012 0.897264004
4 0.400000006 1.09575653
5 0.500000000 1.25852036
6 0.600000024 1.39198673
7 0.700000048 1.50142908
8 0.800000072 1.59117186
9 0.900000095 1.66476095
10 1.00000012 1.72510397
11 1.10000014 1.77458525
12 1.20000017 1.81515992
13 1.30000019 1.84843111
14 1.40000021 1.87571347
15 1.50000024 1.89808500
16 1.60000026 1.91642976
17 1.70000029 1.93147242
18 1.80000031 1.94380736
19 1.90000033 1.95392203
20 2.00000024 1.96221602
21 2.10000014 1.96901715
22 2.20000005 1.97459412
23 2.29999995 1.97916722
24 2.39999986 1.98291707
25 2.49999976 1.98599195
26 2.59999967 1.98851335
27 2.69999957 1.99058092
28 2.79999948 1.99227631
29 2.89999938 1.99366653
30 2.99999928 1.99480653
31 3.09999919 1.99574137

------------------
c program for least square fitting
DIMENSION X(10),Y(10)
PRINT*,'ENTER NUMBER OF POINT'
READ(*,*)N
WRITE(*,*)'ENTER,N,PAIR OF POINTS AS (X,Y)'
READ(*,*)(X(I),Y(I),I=1,N)
SX=0.0
SY=0.0
SXX=0.0
SXY=0.0
DO 10I=1,N
SX=SX+X(I)
SY=SY+Y(I)
10 CONTINUE
DEN=FLOAT(N)*SXX-SX*SX
A=(SY*SXX-SX*SXY)/DEN
B=(FLOAT(N)*SXY-SX*SY)/DEN
WRITE(*,*)'REGRESSION COEFFICIENT ARE'
WRITE(*,*)'INTERCEPT=',A,'SLOPE=',B
WRITE(*,*)'LEAST FITTING LINE COORDINATE:'
DO 40I=1,N
Y(I)=A+B*X(I)
WRITE(*,*)X(I),Y(I)
40 CONTINUE
STOP
END

ENTER NUMBER OF POINT


5
ENTER,N,PAIR OF POINTS AS (X,Y)
5,6
2,3
1,2
5,2
5,1
REGRESSION COEFFICIENT ARE
INTERCEPT= -0.00000000 SLOPE= 0.777777791
LEAST FITTING LINE COORDINATE:
5.00000000 3.88888884
2.00000000 1.55555558
1.00000000 0.777777791
5.00000000 3.88888884
5.00000000 3.88888884
c numerical integration by trapezoidal rule
f(x)=x**3
print*,"enter boundary values"
read(*,*)A,B
print*,"enter number of intervals"
read(*,*)N
H=(B-A)/N
S=f(A)+f(B)
do 10 I=1,N-1,1
X=A+I*H
S=S+2*f(X)

10 continue
result=S*(H/2.0)
print*,"result=",result
stop
end

enter boundary values


2,3
enter number of intervals
2
result= 16.5625000

C NUMERICAL INTEGRATION BY SIMPSON 1/3 RULE


F(X)=X*3/7
A=0
B=1
N=20
PRINT*,'Enter boundary values'
READ(*,*)A,B
PRINT*,'Number of intervals'
READ(*,*)N
H=(B-A)/N
D=4
S=F(A)+F(B)
Do 10 I=1,N-1,1
X=A+I*H
S=S+D*F(X)
D=6-D
10 CONTINUE
RESULT=S*(H/3.0)
PRINT*,'RESULT=',RESULT
Stop
End

Enter boundary values


2,3
Number of intervals
2
RESULT= 1.07142854

------------------
(program exited with code: 0)
Press return to continue
c program for rk4 method for 2nd order ordinary differential
equation
real x0,y0,y1,h,k1,k2,k3,k4
f(x,y,y1)=x*y**2
write(*,*)'input initial value of x,y,y1'
read(*,*)x0,y0,y1
write(*,*)'input value of x for which y and y1 is required'
read(*,*)x
write(*,*)'input value of h'
read(*,*)h
k1=h*f(x0,y0,y1)
k2=h*f(x0+h/2,y0+y1*h/2+k1*h/8,y1+k1/2)
k3=h*f(x0+h/2,y0+y1+h/2+k1*h/8,y1+k2/2)
k4=h*f(x0+h,y0+y1*h+k3*h/2,y1+k3)
write(*,*)'value of k1=',k1
write(*,*)'value of k2=',k2
write(*,*)'value of k3=',k3
write(*,*)'value of k4=',k4
y1=y1+(k1+2*k2+2*k3+k4)/6
y=y0+h*(y1+(k1+k2+k3)/6)
write(*,*)'the required value of y1=',y1
write(*,*)'the required value of y=',y
stop
end

input initial value of x,y,y1


1,2,3
input value of x for which y and y1 is required
5
input value of h
2
value of k1= 8.00000000
value of k2= 196.000000
value of k3= 256.000000
value of k4= 418176.000
the required value of y1= 69851.0000
the required value of y= 139857.328

------------------
(program exited with code: 0)
Press return to continue
A
c program for rk3 method for 1st order ordinary diff equation
real x0,y0,h,k1,k2,k3
f(x,y)=x+y
write(*,*)'input initial value of x and y'
read(*,*)x0,y0
write(*,*)'input value of x for which y is required'
read(*,*)x
write(*,*)'input value of h'
read(*,*)h
k1=h*f(x0,y0)
k2=h*f(x0+(h/2),y0+(k1/2))
k3=h*f(x0+h,y0+2*k2-k1)
write(*,*)'value of k1=',k1
write(*,*)'value of k2=',k2
write(*,*)'value of k3=',k3
y=y0+(k1+4*k2+k3)/6
write(*,*)'the required value of y=',y
stop
end

input initial value of x and y


2,3
input value of x for which y is required
4
input value of h
3
value of k1= 15.0000000
value of k2= 42.0000000
value of k3= 231.000000
the required value of y= 72.0000000
c program for newton raphson iteration method

real x
print*,"please insert the initial guess of the root of equation"
read(*,*)x
call ntrap(x)
print*,"the root of the equation is",x
end

real function f(x)


real x
f=x**2-2
end

real function fd(x)


real::x
fd=2+x
end

subroutine ntrap(x)
real f,fd
real error,tol,x
integer iteration
tol=0.0000001
iteration=0
10 error=-f(x)/fd(x)
x=x+error
iteration=iteration+1
if(abs(error).gt.tol)then
go to 10
endif
print*,"tolerance=",tol
print*,"iteration=",iteration
stop
end

please insert the initial guess of the root of equation


1.5
tolerance= 1.00000001E-07
iteration= 9
c gauss quadrature method
c formula used:i=(b-a)/2*w(i)*f(yi)
c two point quadrature method
write(*,*)'value of integral is='
a=0.0
b=1.0
w0=1.0
w1=1.0
y0=1/(1.732)
y1=-y0
c x=(b+a)/2+((b-a)/2)*y0
f1=1/(1+((b+a)/2+((b-a)/2)*y0)**2)
f2=1/(1+((b+a)/2+((b-a)/2)*y1)**2)
ai=((b-a)/2)*(w0*f1+w1*f2)
write(*,1)ai
1 format(1x,f10.5)
stop
end

value of integral is=


0.78688

------------------
(program exited with code: 0)
Press return to continue

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy