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

  • Context: MATLAB 
  • Thread starter Thread starter dervast
  • Start date Start date
  • Tags Tags
    Matlab Noob
Click For Summary
SUMMARY

This discussion provides a step-by-step guide for plotting the equation P(L) = Po * e^(-aL) in MATLAB. The parameters specified are Po = 1 watt and a = 0.2 dB/km, with L ranging from 0 to 10 km. Two methods for computing P(L) are presented: a loop-based approach and a vectorized approach for efficiency. The final output is a plot of P versus L using the MATLAB plotting function.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with exponential functions and their applications
  • Knowledge of vector operations in MATLAB
  • Experience with MATLAB plotting functions
NEXT STEPS
  • Learn about MATLAB vectorization techniques for improved performance
  • Explore MATLAB's plotting options to enhance visual representation
  • Study the impact of varying parameters a and Po on the function P(L)
  • Investigate MATLAB's built-in functions for mathematical modeling
USEFUL FOR

Beginner MATLAB users, students in engineering or physics, and anyone interested in mathematical modeling and data visualization 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 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K