# Gustav Wihlstrand

@GustavW (1) • Nils Ericsonsgymnasiet
invalid syntax

@JustARatherRidi
Yeah I wrote that expression "unfactorized", and then it worked. Of course it was something stupid like that. Thanks for checking the code!

invalid syntax

@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" ?

invalid syntax

@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=R0
F=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])

invalid syntax

@15adilw Thanks for the quick response. The weird thing is that a colon generates the invalid syntax message. Without the colon the print-thing gets the error.

invalid syntax

@Vandesm14
import matplotlib as mpl
import numpy as np
from matplotlib import pyplot as plt

R0= int(input("Ange antalet kaniner från början"))
F0=int(input("Ange antalet rävar från början"))

t0=0
tf=50

k1=2 #födslar kaniner
k2=0.01 #parameter för hur ofta rävar och kaniner möts
k3=0.8 #parameter för rävars död
k4=0.0002
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=R0
F=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 k in range(1, n)
print (t[k], F[k])

invalid syntax