Understanding Palm's MatLab 7 Plot Function

  • Context: MATLAB 
  • Thread starter Thread starter wildman
  • Start date Start date
  • Tags Tags
    Function Matlab Plot
Click For Summary
SUMMARY

The discussion focuses on the use of the plot function in Palm's "Introduction to MatLab 7 for Engineers," specifically in the context of solving a second-order differential equation related to pendulum motion. The user inquires about the syntax xa(:,1) in the plot command, which selects the first column of the solution matrix xa that contains angle data over time. The explanation clarifies that xa is a matrix where each row corresponds to time and contains both angle and angular velocity, thus necessitating the use of (:,1) to isolate the angle for plotting.

PREREQUISITES
  • Understanding of second-order differential equations
  • Familiarity with MATLAB 7 syntax and functions
  • Knowledge of matrix operations in MATLAB
  • Basic concepts of pendulum dynamics
NEXT STEPS
  • Explore MATLAB's ode function for solving ordinary differential equations
  • Learn about MATLAB matrix indexing and manipulation techniques
  • Study the dynamics of pendulum motion and its mathematical modeling
  • Investigate advanced plotting techniques in MATLAB for data visualization
USEFUL FOR

Students, engineers, and researchers who are learning MATLAB for engineering applications, particularly those interested in solving differential equations and visualizing dynamic systems.

wildman
Messages
29
Reaction score
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
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?
 
Thank you very much. It makes perfect sense. I will learn MATLAB yet!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
3K