Hello!
I'm trying to plot the follow second degree ODE:
x''(t) = a (1-x^2) x'(t) - x(t) with the following code;
a = 0.9;
t = 0:0.01:15; % t =< t =< 15
initial_x = 0.2; % x_0 = 0.2
initial_dxdt = 0; % x'(0) = 0
[t,x] = ode45( @rhs, t, [initial_x initial_dxdt] );
plot(t,x(:,1));
xlabel('t');ylabel('x');
Where rhs is
function dxdt=rhs(t,x)
a = 0.9;
dxdt_1 = x(2); % first derivative of x = x_1
dxdt_2 = a.*(1-x(1).^2).*x(2)-x(1); % second derivative of x = x_2
dxdt=[dxdt_1; dxdt_2];
end
And I recieve the following errors:
  • "Undefined function 'rhs' for input arguments of type 'double'."
  • 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);
I do not know why my rhs function errors when the input arguments are in the form of a double? I'm thinking the following two errors are related errors since the rhs isn't returning anything to the ODE.

Antworten (1)

Star Strider
Star Strider am 2 Dez. 2017

0 Stimmen

Note that rhs (link) is a funciton in the Symbolic Math Toolbox. If you have the Toolbox, the easiest option is to rename your function ‘ode_rhs’ or a name that does not conflict with a MATLAB function name.
If that is not the problem, you either have to save your ODE to its own file as rhs.m on the MATLAB search path, or run it and the ode45 call in a separate function file. See the documentation on What Is the MATLAB Search Path? (link) for details on where to put it.
Your code runs for me without error.

Gefragt:

am 2 Dez. 2017

Beantwortet:

am 2 Dez. 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by