MATLAB Drawing P(L) Equation in MATLAB: A Noob's Guide

  • Thread starter Thread starter dervast
  • Start date Start date
  • Tags Tags
    Matlab Noob
AI Thread Summary
To plot the equation P(L) = Po * e^(-aL) in MATLAB, start by defining the parameters: Po = 1 watt and a = 0.2 db/km. Create a vector for L that ranges from 0 to 10 km, using a fine increment for accuracy, such as 100 evenly spaced points. Two methods are suggested for calculating P(L): the first involves a loop to compute P1 element by element, while the second method computes all values at once, resulting in P2. Finally, use the plot function to visualize P against L. This approach effectively demonstrates how to graph exponential decay in MATLAB.
dervast
Messages
132
Reaction score
1
Hi there.. I am really noob to MATLAB i want to draw the following equation
P(L)=Po*e^(-aL)
How can i draw this function?
Can u help me?
L takes values from 0 to 10km
a=0.2db/km
and Po=1watt
 
Physics news on Phys.org
Well, start with the basics... do you know how to enter your data for L into Matlab? How about P(L)?
 
Code:
Po = 1; % define Po
a = 0.2; % define a
L = 0:10/100:10 % make a vector L with 100 elements evenly spaced from 0 to 10

%option 1, compute P(L) one element at a time
for i = 1:length(L) %loop through all values of L
    P1(i) = Po*exp(-a*L(i));
end

%option 2, compute all the values at once
P2 = Po*exp(-a*L);

figure;plot(L,P1) % Plot P vs L
 

Similar threads

Replies
8
Views
3K
Replies
12
Views
2K
Replies
1
Views
2K
Replies
4
Views
3K
Replies
4
Views
1K
Back
Top