Cody

# Problem 44934. Plot Damped Sinusoid

Solution 2128389

Submitted on 14 Feb 2020 by Jiahang Li
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
clf; t = linspace(0,15,400); y = exp(-0.5*t).*cos(2*pi.*t); m = plot_cos(y, t); assert(abs(m - (-0.781239288889930)) <= 1e-4) h = findobj(gcf, 'Type', 'Line'); if length(h) == 2 assert(isequal([h.Color], [1 0 0 0 0 1]), 'Check plot colors') assert(strcmp([h.LineStyle], 'none--'), 'Check the line style') assert(strcmp([h.Marker],'*none'), 'Check marker type') assert(isequal([h.YData],[m, y]), 'Check plotted data') elseif length(h) == 1 assert(isequal([h.Color], [0 0 1]),'Check plot colors') assert(strcmp([h.LineStyle], '--'), 'Check the line style') assert(strcmp([h.Marker],'*'),'Check marker type') assert(isequal([h.YData],y),'Check plotted data' ) assert(isequal([h.MarkerEdgeColor], [1 0 0]),'Check plot colors') assert(isequal([h.MarkerIndices], 14),'Check marker location') elseif length(h)>2 disp('There may be too many plots on the figure.') else disp('No plot found.') end

z = function_handle with value: @(x)y m = -0.7812 h = Line with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×400 double] YData: [1×400 double] ZData: [1×0 double] Show all properties

2   Pass
clf; t = linspace(2,5,100); y = exp(-0.5*t).*cos(2*pi.*t); m = plot_cos(y, t); assert(abs(m - (-0.287376348726584)) <= 1e-4) h = findobj(gcf, 'Type', 'Line'); if length(h) == 2 assert(isequal([h.Color], [1 0 0 0 0 1]), 'Check plot colors') assert(strcmp([h.LineStyle], 'none--'), 'Check the line style') assert(strcmp([h.Marker],'*none'), 'Check marker type') assert(isequal([h.YData],[m, y]), 'Check plotted data') elseif length(h) == 1 assert(isequal([h.Color], [0 0 1]),'Check plot colors') assert(strcmp([h.LineStyle], '--'), 'Check the line style') assert(strcmp([h.Marker],'*'),'Check marker type') assert(isequal([h.YData],y),'Check plotted data' ) assert(isequal([h.MarkerEdgeColor], [1 0 0]),'Check plot colors') assert(isequal([h.MarkerIndices],17 ),'Check marker location') elseif length(h)>2 disp('There may be too many plots on the figure.') else disp('No plot found.') end

z = function_handle with value: @(x)y m = -0.2874 h = Line with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties h = Line with properties: Color: [0 0 1] LineStyle: '--' LineWidth: 0.5000 Marker: '*' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1×100 double] YData: [1×100 double] ZData: [1×0 double] Show all properties