Differential equation, problem with heaviside

2 views (last 30 days)
Emilijan
Emilijan on 24 Aug 2014
Answered: Star Strider on 26 Aug 2014
I wrote an application in matlab r2011 containing a function used to solve a system of differential equations with ode45. Now, I'm trying to run the same application in matlab r2013. The application fails and I do not know why. I came so far to identify that something with using heaviside made the application fail. The message I get is:
Error using odearguments (line 111) Inputs must be floats, namely single or double.
//Edit I made a simpler version of the application that looks like this:
% This application works in MatLab R2011
% but does not work in MatLab R2013a
% What am I missing?
% function Ex_heaviside
clc; clear all;
[t,y]=ode45(@SystEquDiff,[0 20],[1]);
plot(t,y); grid on;
function dy=SystEquDiff(t,y)
% Does anyone know why this function does not work
% when I substitute this expression:
dy=[0.0325*y];
% with this one?
%dy=[0.0325*y*heaviside(t-10)];
  1 Comment
Star Strider
Star Strider on 24 Aug 2014
Post your ODE function and relevant parts of your code (that call ode45 and define your initial conditions and any parameters you pass to it). Also, describe what you want to do.
If it worked before, there might be a work-around to get it to work in R2013.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 26 Aug 2014
If I remember correctly, the heaviside function has only ever existed in the Symbolic Math Toolbox.
You can implement it with this code:
SystEquDiff = @(t,y) 0.0325*y*[0.5*(t==10) + (t>10)];
[t,y] = ode45(SystEquDiff, [0 20], 1);
figure(1)
plot(t,y)
grid
I used an anonymous function for ‘SystEquDiff’ but it it otherwise the same as your original function.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!