How Do You Plot Complex Equations in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter tomg10000
  • Start date Start date
  • Tags Tags
    Matlab Plotting
Click For Summary
SUMMARY

This discussion focuses on plotting complex equations in MATLAB, specifically the oxygen sag curve equation for two different sources in a river. The equation provided 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)]. A user successfully resolved their issue by defining the variable x using the MATLAB function linspace to create 100 points between 0 and 1 and correcting the bracketing in their equation. The final plotting command used was plot(x,C).

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of exponential functions and their syntax in MATLAB
  • Knowledge of the oxygen sag curve and its components
  • Ability to define and manipulate arrays in MATLAB
NEXT STEPS
  • Learn how to use MATLAB's linspace function for generating vectors
  • Explore MATLAB's plotting functions for visualizing complex equations
  • Study the mathematical principles behind the oxygen sag curve
  • Investigate debugging techniques in MATLAB for resolving syntax errors
USEFUL FOR

This discussion is beneficial for environmental engineers, MATLAB programmers, and researchers involved in water quality modeling and analysis, particularly those working with complex mathematical equations.

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 7 ·
Replies
7
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K