MATLAB: Could someone please help me trouble shoot the following ode45 code. New to Matlab. Showing multiple errors. Thanks a lot

codeodeode45

ERRORS
Subscript indices must either be real positive integers or logicals.
Error in
Untitled3>@(t,x)[(d((((x(2)-x(1))/(dr*dr))+((x(2)-2*x(1)+((x(1)-(p*(cpo*((ap*exp(la.*t))+(1-ap)*exp(lb.*t)))*dr))/(1+(p*dr)))/(dr^2)))))-(kf*x(1)*((cgo-x(3)^2)))+kr*x(3));(d((((0-x(2))/(2*dr*dr))+((0-2*x(2)+x(1))/(dr^2))))-(kf*x(2)*((cgo-x(4)^2)))+kr*x(4));((kf*x(1)*((cgo-x(3)^2)))-kr*x(3));((kf*x(2)*((cgo-x(4)^2)))-kr*x(4))]
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Untitled3 (line 20)
[t,xa] = ode45(f,[0 80],[0 0 0 0]);
ap=0.27;
la=-1.9e-4;
lb=-7.4e-6;
cpo=1e-7;
cgo=1e-6;
d=1.3e-8;
p=5.7e-7;
kf=2.7e10;
kr=5.3e-5;
a=1e-3;
r=7.5e-3;
dr=65/3;
f = @(t,x) [(d((((x(2)-x(1))/(dr*dr))+((x(2)-2*x(1)+((x(1)-(p*(cpo*((ap*exp(la.*t))+(1-ap)*exp(lb.*t)))*dr))/(1+(p*dr)))/(dr^2)))))-(kf*x(1)*((cgo-x(3)^2)))+kr*x(3))
(d((((0-x(2))/(2*dr*dr))+((0-2*x(2)+x(1))/(dr^2))))-(kf*x(2)*((cgo-x(4)^2)))+kr*x(4))
((kf*x(1)*((cgo-x(3)^2)))-kr*x(3))
((kf*x(2)*((cgo-x(4)^2)))-kr*x(4))];
[t,xa] = ode45(f,[0 80],[0 0 0 0]);
end
end

Best Answer

In your function handle, you are indexing into the d variable with
f = @(t,x) [(d(etc...
But you have defined d as a scalar:
d=1.3e-8;
This is the root of your current problem. Maybe you meant this? (In two places)
f = @(t,x) [(d*(etc...
But even after making this change, I get NaN's for the result. So there are other issues.