Problem making it past line 8 - no error given

Im currently running into an issue once I hit line eight where it refuses to move past that point and im unsure as to why as it doesnt give an error, freeze, or crash. It just indefinetly keeps loading on that line. Im using release R2026a and have tried it in a previous 2025 version as well and had the same issue. Any help / explanation on how to fix it is welcome. Thanks in advance!
syms y(t)
eq = 8*diff(y, t, 3) - diff(y, t) == cos(20*t) + sin(2*t)
cond = [y(10) == 50, subs(diff(y), t, 0) == 0, subs(diff(y, t, 2), t, 0) == 0]
solone = dsolve(eq, cond)
cond2 = [y(10) == 15, subs(diff(y), t, 0) == 0, subs(diff(y, t, 2), t, 0) == 3]
soltwo = dsolve(eq, cond2)
trange = linspace(-10, 20, 1000);
y1 = subs(solone, t, trange)
y2 = subs(soltwo, t, trange)
hold on
figure
plot(trange, y1, 'b-', 'LineWidth', 1)
plot(trange, y2, 'r:', 'LineWidth', 1)
hold off
xlabel('time = t');
ylabel('y(t)')
title('solution of the equation')
ylim([-150 200])
legend('y(10)=50, y''(0)=0, y''''(0)=0', 'y(10)=15, y''(0)=0, y''''(0)=3')

 Accepted Answer

It's probably just taking a very long time to compute the symbolic solution at each value of trange. One option, shown below, is to convert the solutions into vpa expressions and then substitute the trange values into the result. Another option might be convert the solutions into anonymous functions with matlabFunction and compute the solutions in double precision. Another option may be to use fplot to try to plot solone and soltwo directly over the desired range.
Also, the hold command should come after creating the figure.
syms y(t)
eq = 8*diff(y, t, 3) - diff(y, t) == cos(20*t) + sin(2*t)
eq(t) = 
cond = [y(10) == 50, subs(diff(y), t, 0) == 0, subs(diff(y, t, 2), t, 0) == 0]
cond(t) = 
solone = dsolve(eq, cond)
solone = 
cond2 = [y(10) == 15, subs(diff(y), t, 0) == 0, subs(diff(y, t, 2), t, 0) == 3]
cond2(t) = 
soltwo = dsolve(eq, cond2)
soltwo = 
trange = linspace(-10, 20, 1000);
vpa(solone)
ans = 
y1 = subs(vpa(solone), t, trange);
y2 = subs(vpa(soltwo), t, trange);
%hold on
figure
hold on
plot(trange, y1, 'b-', 'LineWidth', 1)
plot(trange, y2, 'r:', 'LineWidth', 1)
hold off
xlabel('time = t');
ylabel('y(t)')
title('solution of the equation')
ylim([-150 200])
legend('y(10)=50, y''(0)=0, y''''(0)=0', 'y(10)=15, y''(0)=0, y''''(0)=3')

2 Comments

Genuinely thank you so much for the help! I was losing hope on getting it to work and even tried letting it run for an hour which didnt get it to load either.
You're quite welcome. If you're going to continue using the Symbolic Math Toolbox longer term you may want to explore some or all of the other suggested options to add more tools to your toolbox. Good luck.

Sign in to comment.

More Answers (1)

It is not taking a long time to compute the symbolic solution at each t: it is taking a long time to display the symbolic solution at each t.
You coded
y1 = subs(solone, t, trange)
which does not end in a semi-colon, so it is a request to display all 1000 symbolic results.

2 Comments

Good point. As usual.
syms y(t)
eq = 8*diff(y, t, 3) - diff(y, t) == cos(20*t) + sin(2*t)
eq(t) = 
cond = [y(10) == 50, subs(diff(y), t, 0) == 0, subs(diff(y, t, 2), t, 0) == 0]
cond(t) = 
solone = dsolve(eq, cond)
solone = 
cond2 = [y(10) == 15, subs(diff(y), t, 0) == 0, subs(diff(y, t, 2), t, 0) == 3]
cond2(t) = 
soltwo = dsolve(eq, cond2)
soltwo = 
trange = linspace(-10, 20, 1000);
y1 = subs(solone, t, trange);
y2 = subs(soltwo, t, trange);
figure
plot(trange, y1, 'b-', 'LineWidth', 1)
hold on
plot(trange, y2, 'r:', 'LineWidth', 1)
hold off
xlabel('time = t');
ylabel('y(t)')
title('solution of the equation')
ylim([-150 200])
legend('y(10)=50, y''(0)=0, y''''(0)=0', 'y(10)=15, y''(0)=0, y''''(0)=3')
Warning: Graphics acceleration hardware is unavailable. Graphics quality and performance might be diminished. See MATLAB System Requirements.

Sign in to comment.

Products

Release

R2026a

Tags

Asked:

on 15 Sep 2026 at 23:42

Commented:

about 16 hours ago

Community Treasure Hunt

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

Start Hunting!