Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

R-L circuit

Status
Not open for further replies.

milkypros

Technical User
Oct 25, 2009
11
An RL circuit is described by the first order differential equation: L.(dI(t)/dt)+R.I(t)=V(t) where V(t)=Vo.e^(-t/?). The total current I according to Taylor rule is described by the equation
I(i+1)=((1/(1+(h/d)))*I(i))+((h/d)/(1+(h/d))*(V(i+1)/R)). I wrote the program below but it seems that there is a problem i can't find since i am new to fortran. Can anyone help?

dimension t(0:30),I(0:30)
L=32.690*10**(-6) !(Henri)
R=10.998*10**(-3) !(Ohm)
V=0.212 !(volt)
?=6.6 !(time constant ?: msec)
d=L/R
t1=0 !(msec)
t2=8 !(msec)
t(0)=t1
I(0)=0 !I=current
n=80
h=(t2-t1)/n !h=?t
do i=0, n-1
t(i+1)=t(i)+h
I(i+1)=((1/(1+(h/d)))*I(i))+(((h/d)/(1+(h/d)))* (V(i+1)/R))
V=V*(exp(-t/?))
dI(t)=(V(t)-R*I(t))/L !current derivative
PL(t)=L*I(t)*dI(t) !inductive power
PR(t)=R*(I**2(t)) !ohmic power
Pv(t)=V(t).I(t) !power transmited from battery
end do
do i=0 , n
print*, t(i),I(i),dI(t),PL(t),PR(t),Pv(t)
end do
end
 
For example you try to use array element V(i+1), but you declared V as number V = 0.212
The same problem with
dI(t), PL(t), PR(t), Pv(t)
and maybe more...

It's not good write the whole program at once and then try to compile it. You should first write a basic portion of your program, then compile it and run and if it's working as you expected then add the other refinement and so on...
 
This is the basic portion for the program in order to calculate the J(i+1). it runs but it i only get zeros for the J(i) and i can't see why. What could cause this?

dimension t(0:100),V(0:100),J(0:100)
t1=0
t2=6.8
R=10.998
s=6.6
d=2.97
n=68
t(0)=t1
V(0)=212
J(0)=0
h=(t2-t1)/n
do i=1,n-1
t(i+1)=t(i)+h
end do
do i=0,n
V(i)=212*exp(-t(i)/s)
end do
do i=1,n-1
J(i+1)=((1/1+(h/d))*J(i))+(((h/d)/(1+(h/d)))*(V(i+1)/R))
print*,t(i),V(i),J(i)
end do
end
 
The problem is that Fortan assume implicitely, that that array J is an integer array - I, J, K are implicitely integers (read something about Fortran).
The best thing for you would be to use implicit none and declare all you variables explicitely.
Other thing is, that you have given t(0),V(0),J(0) and IMHO you shoud compute t(1),V(1),J(1)..., so your loops should be
do i=0,n-1 instead of do i=1,n-1.
So, here is something which seems to work better taht the previous:
Code:
[COLOR=#2e8b57][b]real[/b][/color] :: t([COLOR=#ff00ff]0[/color]:[COLOR=#ff00ff]100[/color]),V([COLOR=#ff00ff]0[/color]:[COLOR=#ff00ff]100[/color]),J([COLOR=#ff00ff]0[/color]:[COLOR=#ff00ff]100[/color])
t1[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]0[/color]
t2[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]6.8[/color]
R[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]10.998[/color]
s[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]6.6[/color]
d[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]2.97[/color]
n[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]68[/color]
t([COLOR=#ff00ff]0[/color])[COLOR=#804040][b]=[/b][/color]t1
V([COLOR=#ff00ff]0[/color])[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]212[/color]
J([COLOR=#ff00ff]0[/color])[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]0[/color]
h[COLOR=#804040][b]=[/b][/color](t2[COLOR=#804040][b]-[/b][/color]t1)[COLOR=#804040][b]/[/b][/color]n
[COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]0[/color],n[COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]1[/color]
  t(i[COLOR=#804040][b]+[/b][/color][COLOR=#ff00ff]1[/color])[COLOR=#804040][b]=[/b][/color]t(i)[COLOR=#804040][b]+[/b][/color]h
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color],n
  V(i)[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]212[/color][COLOR=#804040][b]*[/b][/color][COLOR=#008080]exp[/color]([COLOR=#804040][b]-[/b][/color]t(i)[COLOR=#804040][b]/[/b][/color]s)
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]0[/color],n[COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]1[/color]
   J(i[COLOR=#804040][b]+[/b][/color][COLOR=#ff00ff]1[/color])[COLOR=#804040][b]=[/b][/color](([COLOR=#ff00ff]1[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]1[/color][COLOR=#804040][b]+[/b][/color](h[COLOR=#804040][b]/[/b][/color]d))[COLOR=#804040][b]*[/b][/color]J(i))[COLOR=#804040][b]+[/b][/color](((h[COLOR=#804040][b]/[/b][/color]d)[COLOR=#804040][b]/[/b][/color]([COLOR=#ff00ff]1[/color][COLOR=#804040][b]+[/b][/color](h[COLOR=#804040][b]/[/b][/color]d)))[COLOR=#804040][b]*[/b][/color](V(i[COLOR=#804040][b]+[/b][/color][COLOR=#ff00ff]1[/color])[COLOR=#804040][b]/[/b][/color]R))
   [COLOR=#804040][b]print[/b][/color] [COLOR=#ff00ff]10[/color],t(i),V(i),J(i)
[COLOR=#804040][b]end do[/b][/color]

[COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color] ([COLOR=#008080]f4.2[/color], [COLOR=#008080]2X[/color] , [COLOR=#008080]f10.2[/color], [COLOR=#008080]2X[/color] , [COLOR=#008080]f10.2[/color])
[COLOR=#a020f0]end[/color]
Output
Code:
0.00      212.00        0.00
0.10      208.81        0.62
0.20      205.67        1.25
0.30      202.58        1.89
0.40      199.53        2.55
0.50      196.53        3.21
0.60      193.58        3.89
0.70      190.67        4.59
...       ...           ...
6.50       79.18      104.54
6.60       77.99      108.29
6.70       76.82      112.16
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top