MATLAB Help

  • MATLAB
  • Thread starter FrogPad
  • Start date
  • #1
809
0

Main Question or Discussion Point

Maybe not the proper place to post... but it seems like physics forums is going through some type of "crazy" change right now. Anyways... I'm having trouble finding a website with directions on how to plot a system of equations in MATLAB. If anyone has a basic M-file they could show me, or a tutorial... that'd be really awesome! Thanks for the help :)
 

Answers and Replies

  • #2
enigma
Staff Emeritus
Science Advisor
Gold Member
1,750
13
Code:
x=[-5:.1:5]; % x is a vector containing the numbers -5, -4.9, -4.8, ..., 4.9, 5. Semicolon means don't display to screen
y=4x.^3 - 2x.^2 - 12; % The '.'^ raises each element of the vector to the power listed. 
                                % If you just did ^ it would do matrix multiplication which doesn't work unless the matrix is square.

plot(x,y,'r*') % Plot variable X on the horizontal axis, y on the vertical, and display the points as red stars
Is that what you wanted, or did you need something more?
 
  • #3
809
0
Actually, I already knew about the plot command. What I didn't know is that you can plot multiple equations with it.

t1=0:.1:10;
t2=10:.1:20;
y1=t1.*1;
y2=t2./t1;

plot(t1,y1,'r-',t2,y2,'r2-',...

But thanks for the reply :smile:
 
  • #4
enigma
Staff Emeritus
Science Advisor
Gold Member
1,750
13
Ah, ok.

You can also skip the 'xxx' and have it automatically assign the colors.

Another way to do it is to hold the plot like so:

Code:
figure(1)

plot(x1,y1)

hold on

plot(x2,y2)
plot(x3,y3)

hold off
You can also simply type 'hold' to toggle it.
 

Related Threads on MATLAB Help

  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
7
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
3
Views
4K
  • Last Post
Replies
6
Views
7K
  • Last Post
Replies
9
Views
3K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
6
Views
2K
Top