1
invalid syntax
GustavW (1)

Hi everyone.
I get "invalid syntax" on this:
for i in range(1, n)
print (t[i], F[i])
..where t, F and n of course are defined. Why the error message?

You are viewing a single comment. View All
Answered by JustARatherRidi (188) [earned 5 cycles]
View Answer
1
MATTHEWBECHTEL (121)

Did you define them correctly?

1
GustavW (1)

@MATTHEWBECHTEL I'm beginning to think I haven't. Here are the relevant parts of the program. It's a numerical solution to Lotka-volterra equations, using Euler.

n=200
dt=(tf-t0)/(n-1) #tidssteg
t=np.linspace(t0, tf, n) #tidsarray

R=np.zeros([n]) #Skapa array för kaniner och rävar
F=np.zeros([n])

R[0]=R0
F[0]=F0

for i in range(1,n):
R[i]=R[i-1]+dt(k1R[i-1]-k2R[i-1]F[i-1])
F[i]=F[i-1]+dt(-k3F[i-1]+k4R[i-1]F[i-1]

for i in range(n):
print (t[i], F[i])

1
MATTHEWBECHTEL (121)

I don’t know what Lotka-volterra equations or [email protected] is. And yeah, you should probably define those variables.

1
GustavW (1)

@MATTHEWBECHTEL It's just some first order differential equations, and Euler is a numerical method of solving them. F and t are defined arrays. The error implies that the program doesn't understand the print command. If something was undefined, wouldn't that generate another error, like "undefined blabla" ?