How Do You Plot Complex Equations in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter tomg10000
  • Start date Start date
  • Tags Tags
    Matlab Plotting
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
tomg10000
Messages
3
Reaction score
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
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.
 
thanks, i got it working, just needed to correct some bracketing.