Filter löschen
Filter löschen

Laplace with Heaviside step function solving with ode45

3 Ansichten (letzte 30 Tage)
Tashanda Rayne
Tashanda Rayne am 28 Nov. 2023
Kommentiert: Tashanda Rayne am 28 Nov. 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

Akzeptierte Antwort

Torsten
Torsten am 28 Nov. 2023
Bearbeitet: Torsten am 28 Nov. 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 Kommentare
Torsten
Torsten am 28 Nov. 2023
fplot(sol(t), [0 5])
instead of
fplot(sol, [0 5])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by