MATLAB How Do You Plot Complex Equations in MATLAB?

  • Thread starter Thread starter tomg10000
  • Start date Start date
  • Tags Tags
    Matlab Plotting
AI Thread Summary
The discussion revolves around creating a MATLAB program to plot an oxygen sag curve based on a specific equation. The user initially struggles with formatting the equation correctly in MATLAB. A helpful response suggests defining the variable 'x' using the linspace function to create 100 points between 0 and 1. The user is then guided to input the equation directly into MATLAB and plot the results using the plot function. Ultimately, the user resolves the issue by correcting some bracketing in the equation, leading to a successful plot.
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.
 

Similar threads

Replies
10
Views
3K
Replies
4
Views
3K
Replies
9
Views
5K
Replies
4
Views
2K
Replies
5
Views
2K
Replies
2
Views
2K
Back
Top