Plotting exponential curves with random numbers.
Mostrar comentarios más antiguos
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.
Respuestas (2)
Mischa Kim
el 10 de Feb. de 2014
Editada: Mischa Kim
el 10 de Feb. de 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.
1 comentario
Liam
el 10 de Feb. de 2014
Jos (10584)
el 10 de Feb. de 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
Categorías
Más información sobre Uniform Distribution (Continuous) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!