Reputation: 11
function dy = g2(x, y)
dy = -0.1 * y;
ym = ode45('g2', 0, 5, 4)
end
I receive the following message:
g2(0.5,4) Error using odearguments (line 83) The last entry in tspan must be different from the first entry.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in g2 (line 9) ym = ode45('g2', 0, 5, 4);
I might add that this one works well:
function dy = g1(x, y)
dy = 3 * x ^ 2;
ym = ode45('g1', 2, 4, 0.5)
end
Upvotes: 1
Views: 1013
Reputation: 8281
I am not understanding what you are trying to do, however I will give you an example.
Usually your functions are defined at the bottom and you call ODE like that :
t=linspace(0,7,1000);
initial_value_for_y = 0;
[t,y] = ode45(@myfunction, t, initial_value_for_y);
function dy = myfunction(t, y)
dy = exp(-t);
end
so in the first line we define a vector for time using linspace. at the second line we set the initial value of our integration the third line calls ODE45 with a function handle, the time span and an initial value
the rest of the lines are for the definition of your function
My concern for now is that you question is not clear. Instead of asking "why isn't it working", tell us what you are trying to achieve.
Upvotes: 2