Obvious code mistake which I cannot spot

Here is my code. I cannot make it run. Yes I am pretty new to the subject.
Is there some obvious error in the code?
Any help appreciated

clear; clc; close all;

global k1 k2 k3 k4 k5 K n

tmin=0; tmax=1.5;
S0=[0; 0];

params=[20, 5, 5,5,2,1,4;
10,4,5,5,3,1,3;
20,5,5,2,2,2,3];
function
for i=1:3
k1=params(i,1); k2=params(i,2); k3=params(i,3);
k4=params(i,4); k5=params(i,5); K=params(i,6) ; n=params(i,7);

[t,S] = ode45(@dsdt,[tmin tmax],S0);
S1=S(:,1);
S2=S(: , 2) ;
endfunction

figure %i set timwn
plot(t,S1,t,S2,’–’)
xlabel(‘time’)
ylabel(‘S’)
legend(‘S1’,‘S2’)
title(“k1=”+k1+", k2="+k2+", k3="+k3+", k4="+k4+", k5="+k5+", K="+K+", n="+n)

end

figure
for i=1:3 % Sxediazw xwro phasewn gia 3 set timwn
k1=params(i,1); k2=params(i,2); k3=params(i,3);
k4=params(i,4); k5=params(i,5); K=params(i,6) ; n=params(i,7);

[t,S] = ode45(@dsdt,[tmin tmax],S0);
S1=S(:,1);
S2=S(: , 2) ;

plot(S1,S2)
hold on

end
hold off
xlabel(‘S1’)
ylabel(‘S2’)
title(‘Phase Space’)
legend(‘1st set’, ‘2nd set’, ‘3d set’)

function Sdot=dsdt(t,S)
global k1 k2 k3 k4 k5 K n

s1=S(1);
s2=S(2);

sdot1=k1/(1+(s2/K)^n )-(k3+k5)s1;
sdot2=k5
s1-k4*s2+k2;

Sdot=[sdot1;sdot2];
end

ok, a couple things.

1 - have you tried stepping through your code line by line to find the first errors?

2 - octave doesnt play well with functions embedded in scripts (inline functions). best to make functions separate m-files. (referring to the dsdt function)

3 - I’m not sure why you have a nameless function at line 12. but you end the function before you end the for loop that’s in it. something’s not right there. I don’t think you need that function/endfunction statement at all.

4 - do you need to declare those variable as global? you probably don’t need to ‘redefine’ them again inside the dsdt function. since that’s your only function, it would probably be best to pass the k’s to it. I’m not a real programmer so I’m not sure why it might be an issue here, just relaying that people always tell me using globals to get around proper scoping can be bad.
nothing else is jumping out at me with a quick glance.

If I copy your code to an .m file and try to run it, I get the following error message:

parse error near line 12 of file D:\SVN\Octave\discourse_395.m

  syntax error

>>> function
             ^

The first function in your script doesn’t have a name…