MATLAB: Incorrect use of ‘=’ operator. To assign a value to a variable, use ‘=’. To compare values for equality, use ‘==’.

incorrect use of '=' operator. to assign a value to a variableMATLABuse

Asking for help.
ERROR "Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='."
I already followed instruction above but another happened
ERROR 2: Illegal use of reserved keyword "for".
This is my code.
clc;
clear;
%dx/dt=ax-bxy Predator
%dy/dt=-cy+dxy prey
%constants as stated on the problem
a = 1.2;
b = 0.6;
c = 0.8;
d = 0.3;
%Defining the functions
%z[x,y]<=z(1,:)= y z(2,:)=x
f=@(t,z)[ ...
+a*z(2)-b*z(2)*z(1)
-c*z(1)+d*z(2)*z(1)
fx==@(t,x,y) a*x - b*x*y;
fy==@(t,x,y) -c*y + d*x*y;
%Initial Conditions
t(1)=0; %time
% x(1)=2; %predator
% y(1)=1; %prey
z(:,1)=[1,2];
%step size
h = 0.001;
tfinal = 30;
N = 1000;
%Loop
for i=1:N
Update time
t(i+1)=t(i)+h;
%update for z
k1=f(t(i), z(:,i));
k2=f(t(i)+h/2, z(:,i)+h/2*k1);
k3=f(t(i)+h/2, z(:,i)+h/2*k2);
k4=f(t(i)+h, z(:,i)+h *k3);
z(:,i+1)=y(:,i) +h/6*(k1+ 2*k2 +2*k3 +k4);
end
%plotting
figure(1)
clf(1)
plot(t,y(1,:))
hold on
plot(t,y(2,:))
xlabel('Time')
ylabel('Populations')
hold off
Thank you and have a nice day

Best Answer

The actual problem starts on this line:
f=@(t,z)[ ...
because your code is missing the matching ]
Using = was correct.
Note that you should use colon or linspace to generate t, rather than the inefficient method that you use now.