Laplace with Heaviside step function solving with ode45

3 次查看(过去 30 天)
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

采纳的回答

Torsten
Torsten 2023-11-28
编辑:Torsten 2023-11-28
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

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