Differential equation, problem with heaviside
조회 수: 9 (최근 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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!