Borrar filtros
Borrar filtros

Laplace with Heaviside step function solving with ode45

3 visualizaciones (últimos 30 días)
Tashanda Rayne
Tashanda Rayne el 28 de Nov. de 2023
Comentada: Tashanda Rayne el 28 de Nov. de 2023
I dont understand why I keep getting an error, can you please explain to me why and how I can fix this?
syms s t Y
f = heaviside(t-1)- heaviside(t-2);
X = laplace(f);
Sol = X ./(s^2+3*s+2);
sol = symfun(ilaplace(Sol),t);
pretty(sol)
/ exp(2 - 2 t) 1 \ / exp(4 - 2 t) 1 \ heaviside(t - 1) | ------------ - exp(1 - t) + - | - heaviside(t - 2) | ------------ - exp(2 - t) + - | \ 2 2 / \ 2 2 /
tspan = [0 5];
ic = [0 0];
fn = @(t,Y) [Y(2); (heaviside(t-1)- heaviside(t-2) - 3*Y(2) - 2* Y(1))];
[t,Y] = ode45(fn,tspan,ic);
Index exceeds the number of array elements. Index must not exceed 1.

Error in indexing (line 968)
R_tilde = builtin('subsref',L_tilde,Idx);

Error in solution>@(t,y)[Y(2);(u-Y(3)-3*Y(2)-2*Y(1))] (line 12)
fn = @(t,y) [Y(2); (u - Y(3) - 3*Y(2) - 2* Y(1))];

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
hold on
plot(t,y(:,1))
fplot(sol, [0 5])
grid on
xlabel('x')
ylabel('y')
legend('Ode45' ,'Solved' )
hold off

Respuesta aceptada

Torsten
Torsten el 28 de Nov. de 2023
Editada: Torsten el 28 de Nov. de 2023
You try to access Y(3), but you have only two differential equations for Y(1) and Y(2), I guess.
And the "Y" must be "y" because your list of inputs is t and y, not t and Y.
And ode45 is a numerical solver - it does not accept symbolic inputs like your "u".
  3 comentarios
Torsten
Torsten el 28 de Nov. de 2023
fplot(sol(t), [0 5])
instead of
fplot(sol, [0 5])

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by