Creating a Decay line graph that repeats with last answer

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Bora Eryilmaz
Bora Eryilmaz il 12 Dic 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)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by