Basic matlab help with plotting

In summary, the conversation discusses a problem with writing a MATLAB program to plot concentration vs distance for an oxygen sag curve from two different BOD sources in a river. The equation being used is given and the speaker is seeking help from someone experienced with MATLAB. They are instructed to specify points for x and make sure the brackets in the equation are correct. The issue is eventually resolved.
  • #1
tomg10000
3
0
Hi,

I am trying to write a short MATLAB program that plots concentration vs distance (oxygen sag curve from two different bod sources in a river). I know the equation I am using is:

C= Cs - [(kd*Mo)*(exp(-x*kr/u)-exp(-x*ka/u))/(Q*ka-kr)] - (Cs-Co)*exp(-x*ka/u) - [(kd*Mo)*(exp(-(x-L)*kr/u)-exp(-(x-L)*ka/u))/(Q*ka-kr)].

Its very long and I am having trouble getting it to work in MATLAB form.
Can someone used to MATLAB give me some hints how to make this work?

I know how to execute a plot by plot(x,C) but the equation is giving me trouble.

Any help would be greatly appreciated.
Thanks.
 
Physics news on Phys.org
  • #2
I'm going to assume everything in there except x is a constant. First, you have to specify what points you want to use for x. For example, you could do:

x = linspace(0,1,100)

In a nutshell, this defines x as 100 points between 0 and 1. After this, you can type:

C= Cs - [(kd*Mo)*(exp(-x*kr/u)-exp(-x*ka/u))/(Q*ka-kr)] - (Cs-Co)*exp(-x*ka/u) - [(kd*Mo)*(exp(-(x-L)*kr/u)-exp(-(x-L)*ka/u))/(Q*ka-kr)]

plot(x,C)

If that still doesn't work, I don't know. Without knowing what all of these letters are, it's close to impossible to debug what you're doing.
 
  • #3
thanks, i got it working, just needed to correct some bracketing.
 

1. How do I plot a basic graph in Matlab?

To plot a basic graph in Matlab, you can use the plot function. This function takes in a set of x-coordinates and y-coordinates as inputs and plots them on a graph. For example, if you want to plot the points (1,2), (3,4), and (5,6), you can use the command plot([1,3,5],[2,4,6]).

2. How can I customize the appearance of my plot in Matlab?

Matlab offers a variety of options for customizing the appearance of your plot. Some commonly used commands include xlabel and ylabel for labeling the axes, title for adding a title, and legend for adding a legend. You can also change the color, line style, and markers of your plot using the Color, LineStyle, and Marker properties, respectively.

3. How do I save my plot as an image file in Matlab?

To save your plot as an image file in Matlab, you can use the saveas function. This function takes in the handle of the figure you want to save and the desired file name and format as inputs. For example, if you want to save your plot as a PNG file named "myplot", you can use the command saveas(gcf, 'myplot.png').

4. Can I plot multiple graphs on the same figure in Matlab?

Yes, you can plot multiple graphs on the same figure in Matlab by using the hold function. This function allows you to plot multiple graphs on the same figure without overwriting the previous ones. Simply use the command hold on before plotting each graph, and use hold off when you are finished.

5. How do I create a bar graph in Matlab?

To create a bar graph in Matlab, you can use the bar function. This function takes in a set of x-coordinates and corresponding bar heights as inputs and plots them on a bar graph. For example, if you want to create a bar graph with bars at x=1, 2, and 3 with heights 4, 5, and 6, respectively, you can use the command bar([1,2,3],[4,5,6]).

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
928
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top