I first defined functions for dy/dt=y and dy/dt=t:
function dy=d(y):
dy=y
end
function ddy=dd(t):
ddy=t
end
And then I used ode45, respectively:
[t,y]=ode45('d',[1 10],1)
[t,y]=ode45('dd',[1 10],1)
which returns the following error: Error using d Too many input arguments.
My question is:
First things first: the docs on ode45
are on the mathworks website, or you can get them from the console by entering help ode45
.
The function you pass in needs to take two variables, y
then t
. As you noticed, with just one it would be impossible to distinguish a function of only y
from a function of only t
. The first argument has to be the independent, the second is the dependent.
Try defining your function as dy = d(t, y)
and ddy = dd(t, y)
with the same bodies.
one other note, while using a string representing the function name should work, you can use @d
and @dd
to reference the functions directly.