Plotting exponential curves with random numbers.

6 views (last 30 days)
Liam
Liam on 10 Feb 2014
Commented: Liam on 10 Feb 2014
Ok I wonder if anyone can help me. Forgive me, but I am a complete novice with MATLAB and only ever had to complete worked examples in my class but now I have had this seemingly huge task put in my hands.
So I have some data that I have been able to plot as a scatter and (as I couldn't figure out how) through excel, have got the equation of the line which roughly resembles an exponential curve (as per the conditions of the question) as y= b*e^(c*x) ==> y=0.0274*exp(0.0332*x).
I now need to generate 100 further exponential lines to be displayed on the same graph using a random number function where b and c are changing.
I'm really not sure how to get this started.
b needs to exist between 0.15 and 0.424 c needs to exist between 0.252 and 0.372
I'm not sure how to get the random number thing working or how I can plot 100 lines on one graph.
Any help anyone could give would be greatly appreciated.

Answers (2)

Mischa Kim
Mischa Kim on 10 Feb 2014
Edited: Mischa Kim on 10 Feb 2014
This will do:
N = 100;
b = 0.150 + (0.424-0.150)*rand(N,1);
c = 0.252 + (0.372-0.252)*rand(N,1);
x = 0:0.1:10;
figure
box; grid;
hold all
for ii = 1:N
y = b(ii)*exp(c(ii)*x);
plot(x,y)
end
rand(N,1) generates a 100-by-1 vector of uniformly distributed pseudorandom numbers. The loop will take care of displaying all 100 curves, which you can plot all in one figure by using the hold all command.

Jos (10584)
Jos (10584) on 10 Feb 2014
Here is something to get you started
x = linspace(-10,10,100) ;
hold on % help!
for k = 1:5,
B = 0.15 + (0.424-0.15) * rand(1,1) ;
C = % do it yourself, given the equation for B
y = B * exp(C * x) ;
plot(x,y,'-') % plot a line
end
hold off

Categories

Find more on 2-D and 3-D Plots 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!