ODE45 & heaviside- [Inputs must be floats, namely single or double.]
2 views (last 30 days)
Show older comments
Hi!
I'm having problems with the code when solving differential equations by ode45.
The point is that I must enter singular functions from GUIDE:
u(t) -> Step. " ONLY THE HEAVISIDE FUNCTION ALLOWS ME"
Code:
vin=get(handles.editE,'String');
vin=strrep(vin,'u','heaviside');
t=(str2double(get(handles.editI,'String')):0.001:str2double(get(handles.editF,'String')));
tspan = [0 9];
vs=(str2double(get(handles.editPVI,'String')));
R=(str2double(get(handles.editR,'String')));
C=(str2double(get(handles.editC,'String')));
tau = R*C;
syms t;
NOW HERE I TRIED:
vin = eval (vin) -> not working.
vin = symfun (vin, t) -> not working.
syms vin -> not working.
.
f =@(t,v) vin/tau-v/tau; v0=0;
% works like this (literally the function):
% f =@(t,v) heaviside(t)/tau-v/tau; v0=0;
% [t,v] = ode45(f,tspan,v0)
But I can not put this function as such, since vin can be a step, pulse, ramp, an exponential function, etc ...
[t,v] = ode45(f,tspan,v0);
axes(handles.axesVc);
grid on
plot(t,v);
Somebody help me :(
0 Comments
Accepted Answer
Steven Lord
on 9 May 2018
The ode45 function cannot accept functions that return a sym object as the first input to ode45. You could use symbolic calculations inside the ODE function so long as what it returns is a column vector of data type single or double.
For two other approaches, you could use dsolve to try to solve the system of ODEs symbolically or you could use the odeFunction function to try to convert a symbolic expression into a function handle that is compatible with the numeric ODE solvers like ode45. See this page in the documentation for more information.
More Answers (0)
See Also
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!