How to plot x(n) for many values of n?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SAS
el 6 de Jun. de 2020
Comentada: SAS
el 7 de Jun. de 2020
How to plot 𝑥(𝑛) = 𝛼𝑛 𝑥(0) for n=1-30 and x(0)=100?? I have tried this code, but it is repeating it's value again and again... What I am missing?
alpha = 2
x0 = 100; % Initial conditions
for n = 1:30
x(n) = (alpha^n)*(x0)
end
disp(x(n))
0 comentarios
Respuesta aceptada
madhan ravi
el 6 de Jun. de 2020
Editada: madhan ravi
el 6 de Jun. de 2020
Shorter code eliminating loop:
Alpha = 2
x0 = 100; % Initial conditions
n = 1:30;
x = Alpha.^n*x0;
plot(n,x)
Note: You were doing it correctly all you had to use was disp(x)
9 comentarios
madhan ravi
el 6 de Jun. de 2020
Editada: madhan ravi
el 6 de Jun. de 2020
Man... what do you want to do? Did you read https://www.mathworks.com/matlabcentral/answers/543416-how-to-plot-x-n-for-many-values-of-n#comment_886145 ?
Más respuestas (1)
David Hill
el 6 de Jun. de 2020
alpha = 2
x0 = 100; % Initial conditions
for n = 1:30
x(n) = (alpha^n)*(x0)
end
disp(x);
plot(1:30,x);
3 comentarios
David Hill
el 6 de Jun. de 2020
x has only 30 values...use ; to suppress
alpha = 2;
x0 = 100; % Initial conditions
for n = 1:30
x(n) = (alpha^n)*(x0);
end
disp(x);
plot(1:30,x);
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!