Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Basic matlab help with plotting

  1. Aug 4, 2011 #1

    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 im 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 im 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.
  2. jcsd
  3. Aug 4, 2011 #2


    User Avatar
    Homework Helper

    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)]


    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.
  4. Aug 5, 2011 #3
    thanks, i got it working, just needed to correct some bracketing.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook