exponential decay function y = exp*(-Tau.time)

100 views (last 30 days)
Another exponential decay function I am having problem with: Need to write script to plot the following equation
y = exp ^ -(timeconstant*time)
prompt the user for beginning and ending values of time vector.
prompt the user for two values of timeconstant
Now, calculate two different y vectors
Here is what I did:
timeconst1 = input('Please enter the first value of time constant: ');
timeconst2 = input('please enter the second value of time constant: ');
initial = input('Please enter the beginning value of time: ');
final = input('Please enter the ending value of time: ');
vec = initial:final;
yinitial = exp(-timeconst1*vec)
plot(initial,yinitial,'r*')
hold on
yfinal = exp(-timeconst2*vec)
plot(final,yfinal,'c*')

Accepted Answer

Mischa Kim
Mischa Kim on 30 Jan 2015
Hi Nabin, to help with readability I have slightly re-formatted the code and re-named some variables:
tau1 = 1;
tau2 = 2;
ti = 1;
tf = 10;
t = linspace(ti,tf,20);
yinitial = exp(-tau1*t);
yfinal = exp(-tau2*t);
plot(t,yinitial,'r*')
hold on
plot(t,yfinal,'c*')
hold off

More Answers (1)

ZUBAIR WAR
ZUBAIR WAR on 13 Aug 2022
tau1 = 1;
tau2 = 2;
ti = 1;
tf = 10;
t = linspace(ti,tf,20);
yinitial = exp(-tau1*t);
yfinal = exp(-tau2*t);
plot(t,yinitial,'r*')
hold on
plot(t,yfinal,'c*')
hold off

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!