MATLAB: Plotting Answers to dsolve

plot

Trying to get the answers to show up on plot
Code:
for w = 1.3, 1.5, 1.8, 1.9
dsolve('2*D2h + 8*h = 5*cos(w*t)')
figure; plot(w); axis equal; axis([0 40 0 40])
end
Doing this is giving me a plot but nothing is actually plotted on the graph.

Best Answer

Your function may be only a function of time (guessing here because you didn’t specifically state that in your code), however the the integrated function is of both ‘w’ and ‘t’, so if you want to plot it, you have to plot it as a function of both.
This works. I leave it to you to determine if it produces the results you want:
syms h(t) w
Dh(t) = diff(h);
h_sol = dsolve(2*diff(h,2) + 8*h == 5*cos(w*t), h(0) == 0, Dh(0) == 0); % Integrate
h_sol = simplify(h_sol, 'steps', 20); % Simplify
h_fun = matlabFunction(h_sol); % Create Anonymous Function
h_fun = @(t,w)(sin(t.*w.*(1.0./2.0)).^2.*5.0-sin(t).^2.*5.0)./(w.^2-4.0); % Copied & Pasted For Convenience
w = [1.3, 1.5, 1.8, 1.9];
t = linspace(0, 1, 25);
[W,T] = meshgrid(w,t);
figure(1)
meshc(T,W,h_fun(T,W))
grid on
xlabel('\bft')
ylabel('\bfw')
zlabel('\bfh(t,w)')
The meshgrid call is necessary if you want to calculate and plot it correctly.