Step 3: Plotting

Let's visualize our results by making a plot of the mass position x vs. time using the steps shown in the video below.


Create Professional-Looking Plot

We'll make a few tweaks to the plot to prettify it and make it look more professional. We'll do this using the following template.

figure(1); %Create figure #1
clf; %Clear current figure
h=plot( , ,' ');
set(h,'LineWidth',2); %Set linewidth for curve
set(gca,'Box','on','LineWidth',2,...
   'FontName','Helvetica',...
   'FontSize',14); %Set axis properties
xlabel('');
ylabel('');
title('');
axis square; %Make axis box square


The following video shows you how to implement this template.


Note that we use the variable h for the plot handle in the above video. But we have also used h for the time step. Oops! In this case, this doesn't cause an error since plotting occurs at the end. But it'd be better to call the plot handle, say, hplot in your code.

We next change the axis limits from the default using the axis function so that our curve fills up more of the plot area.


Add Analytical Solution to Plot

First, we form the necessary arrays from the analytical solution.


Second, we add a curve corresponding to the analytical solution to our figure.


Lastly, we add a legend to label the curves.



Go to Step 4: Function Creation

Go to all MATLAB Learning Modules

  • No labels