Creating a Decay line graph that repeats with last answer

2 visualizaciones (últimos 30 días)
Elizabeth
Elizabeth el 12 de Dic. de 2022
Respondida: Bora Eryilmaz el 12 de Dic. de 2022
Hello, I am new to Matlab and am trying to figure out how I can create a decay graph using the last input from the previous answer and print it on a line graph. The code provided below does the first point on the graph correct but the following points are wrong due to the fact that it takes the orignal power each time. I want it to take the result of the first answer and run the same decay through it again to gain a new answer and print on the graph. The original powers are user inputs as well. Any help would be appriciated this is the code I have so far.
axes(handles.axes4);
x = 0:1:25;
o_power = total1;
o_power2 = total2;
o_power3 = total3;
o_power4 = total4;
decay = 0.16;
y = o_power + (-x * o_power * decay);
plot(x,y)
hold on
y2 = o_power2 + (-x * o_power2 * decay);
plot(x,y2)
y3 = o_power3 + (-x * o_power3 * decay);
plot(x,y3)
y4 = o_power4 + (-x * o_power4 * decay);
plot(x,y4)
hold off

Respuestas (1)

Bora Eryilmaz
Bora Eryilmaz el 12 de Dic. de 2022
Perhaps something like this, where the current value of "y" is dependent on its previous value:
power = 2.0;
decay = 0.16;
N = 25; % Number of points to generate.
y = zeros(1,N); % Initialize vector of results.
y(1) = 0; % Initialize the starting point.
for i = 2:N
y(i) = power + (-y(i-1) * power * decay); % Update equation.
end
plot(y)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by