From: Scott Leipprandt on
I'm trying to write a working ODE45 function for my differential equations class and keep getting an error using ==> times, matrix dimensions must agree

I'm guessing there may be some other errors in the code as I am not completely comfortable with using ODE45 yet.

any help would be appreciated.

The code calling the function is here:
%% Set Parameters
close all
clc
clear all
global e_0 k a mu1 mu2 T;
% Set parameter values %
e_0 = .002;
k = 8;
a = .15;
mu1 = .2;
mu2 = .3;
% Set period T and simulation duration dur
T = 100;
dur = 500;
%% Run the simulation and plot the data
[t,v] = ode45 ('system_template',0:0.2:dur,[0,0]); % This runs the simulation

-----------------------------------------------------------------
the ODE45 function is here and is where the errors are occurring:

function [vprime] = system_template(t,v)

%% Import global parameters
global e_0 k a mu1 mu2 T;
%% Set stimulation by periodicity
if (mod (t,T) >= 10.0) && (mod (t,T) <= 13.0)
stim = 0.25;
else
stim = 0.0;
end
%% ODEs
vprime(1,1) = stim - k*v*(v-a)*(v-1)+v*h; %% ODE for dv/dt %%
vprime(2,1) = (e_0+(mu1*h)/(v+mu2))*(-h-k*v*(v-a-1)); %% ODE for dh/dt %%


thanks again for any possible help
From: Scott Leipprandt on
in response to my previous post, I was able to fix the errors by substituting v(1) for v and v(2) for h in the vprime equations in the ODE45 function. (wasn't aware this was needed earlier)