필터 지우기
필터 지우기

Laplace with Heaviside step function solving with ode45

조회 수: 3 (최근 30일)
Tashanda Rayne
Tashanda Rayne 2023년 11월 28일
댓글: Tashanda Rayne 2023년 11월 28일
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
Torsten
Torsten 2023년 11월 28일
fplot(sol(t), [0 5])
instead of
fplot(sol, [0 5])

댓글을 달려면 로그인하십시오.

추가 답변 (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