Plotting System of Equations in MATLAB

Click For Summary

Discussion Overview

The discussion revolves around plotting systems of equations in MATLAB, focusing on how to visualize multiple equations using the software. Participants share code snippets and techniques related to plotting, as well as their experiences with MATLAB's plotting functions.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses a need for guidance on plotting systems of equations in MATLAB and requests examples or tutorials.
  • Another participant provides a code snippet demonstrating how to plot a single equation using a vector for x and calculating y based on that vector.
  • A different participant mentions they were already familiar with the basic plot command but were unaware that multiple equations could be plotted simultaneously.
  • Further suggestions include using the 'hold on' command to plot multiple equations on the same figure without overwriting previous plots.

Areas of Agreement / Disagreement

Participants generally agree on the methods for plotting in MATLAB, but there is no consensus on the best approach for plotting multiple equations, as different techniques are suggested without resolution.

Contextual Notes

Some assumptions about the familiarity with MATLAB commands and syntax are present, and there may be limitations in the provided code snippets regarding the handling of different types of equations or more complex systems.

Who May Find This Useful

This discussion may be useful for individuals learning to use MATLAB for plotting mathematical functions, particularly those interested in visualizing systems of equations.

FrogPad
Messages
801
Reaction score
0
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 :)
 
Physics news on Phys.org
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?
 
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:
 
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.
 

Similar threads

Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
43K
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K