Understanding Palm's MatLab 7 Plot Function

In summary, the conversation discusses the use of MATLAB to solve a second order differential equation and create a plot. The solution to the differential equation is straightforward, but there is confusion about the use of the plot function and the selection of data from the solution matrix. The expert explains that the plot function is used to graph the angle versus time, and the colon notation is used to select the desired data from the solution matrix. This conversation highlights the use of MATLAB and its capabilities for solving complex equations and creating visual representations of data.
  • #1
wildman
31
4
I am looking at Palm's "Introduction to MatLab 7 for Engineers" page 511. The problem involves solving a Second Order Diff Equation. The solution to the diff equation is straight forward. What I am wondering is what Plam is doing in the plot function?

[tex] \ddot{\Theta} + \frac {g} {l} sin \Theta = 0 [/tex]

His answer is below:

in the m file pendul:

function xdot = pendul(t,x)
global g L
xdot = [x(2); -(g/L)*sin(x(1))];

in the m file example8_6_1

global g L
g = 9.81;
L = 1;
[ta, xa] = ode('pendul', [0,5], [0.5,0]);
plot(ta,xa(:,1), xlabel('Time (s)'), ylabel('Angle(rad)')

Question:

In the plot(ta,xa(:,1) what is the (:,1)? What is he doing? And why couldn't he just put an xa without the (:,1)?
 
Physics news on Phys.org
  • #2
In this example X is a vector containing [x , xdot], so the solution xa is a matrix whose rows are [x(ta), xdot(ta)] where ta changes in each row. So xa looks like
[x(t1) xdot(t1)
x(t2) xdot(t2)
x(t3) xdot(t3) ]
and so on. He wants to plot the angle x versus time, so you select the first column of the solution matrix xa. This is done by xa(:,1), where the colon : indicates that you want all of the rows, and the 1 indicates you want the first column. If you wanted to plot the angular velocity versus time you would write plot(ta,xa(:,2)). Does that make sense?
 
  • #3
Thank you very much. It makes perfect sense. I will learn MATLAB yet!
 

Related to Understanding Palm's MatLab 7 Plot Function

1. What is MatLab 7 Plot Function?

MatLab 7 Plot Function is a tool used in the MatLab software for creating graphs and visual representations of data. It allows users to customize and manipulate various aspects of the graph, such as axes, labels, and colors.

2. How do I use MatLab 7 Plot Function?

To use MatLab 7 Plot Function, you need to first import your data into the software. Then, you can use the plot function to create a graph by specifying the data points and any desired customization options. The resulting graph will be displayed in a new figure window.

3. What types of plots can be created with MatLab 7 Plot Function?

MatLab 7 Plot Function can create various types of plots, such as line plots, scatter plots, bar graphs, histograms, and more. It also has the capability to create 3D plots and animations.

4. Can I save my plots created with MatLab 7 Plot Function?

Yes, you can save your plots as image files or in other formats such as PDF or EPS. You can also save the entire figure including the plot and any other elements, such as legends and titles.

5. Is MatLab 7 Plot Function difficult to learn?

MatLab 7 Plot Function can be relatively easy to learn for those with a basic understanding of programming and data visualization. There are also many online resources and tutorials available to help users learn and improve their skills with the tool.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
497
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
587
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top