Matlab help a noob

  • Thread starter dervast
  • Start date
133
0
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
 

hypnagogue

Staff Emeritus
Science Advisor
Gold Member
2,185
2
Well, start with the basics... do you know how to enter your data for L into Matlab? How about P(L)?
 
212
0
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
 

Want to reply to this thread?

"Matlab help a noob" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving

Latest threads

Top