Differential equation, problem with heaviside

1 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2014-8-24
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.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2014-8-26
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.

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by