## Decrement of the value of varivel with Matlab Function

on 17 May 2018
Latest activity Edited by Ademir Silva

on 19 May 2018
Hi, I am new user of MATLAB. I need to create a decrement function. Example:
EcAcum = Ec- (Ec- (EcAcum-Input);
At where,
EcAcum: Available kinetic energy;
Ec: Total kinetic energy;
Input: Field instantaneous energy;
My goal is to start the decrease from the EC value and decrease to zero.
I tried using Matlab Function but it did not work.

on 18 May 2018
Independent of the mathematical problem. how can I work around this problem without having to set EcAcum before? Even though I use the expression you have done,
deltaEc = Ec- (EcAcum-Input); EcAcum = Ec-deltaEc;
the error is the same. The algorithm requires that the variable be defined first. However, if I set it will not work.
Greg

### Greg (view profile)

on 18 May 2018
I don't understand the question. How can you possibly subtract a value from a variable that doesn't exist? You can't have a delta without an initial condition.
I think you want a loop, not a function. Re-reading that you're dealing with energy, I am guessing you are starting with some energy, and using it in bursts until you run out.
EcAcum = Ec; % The energy available in the system at the beginning
while EcAcum > 0
% Probably some code here to calculate "Input"
% which is assumedly the energy used by some action
EcAcum = EcAcum - Input; % The remaining available energy in the system?
end

on 18 May 2018
"I do not understand the question. How can you possibly subtract a value from a variable that does not exist? You can not have a delta without an initial condition." That is exactly my difficulty. Different conditions:
1. Without the loop I need to set the variable to an initial condition. In this way the decrement calculation will not work. Why the defined variable restarts with the initial value during runtime;
2. With the loop I need to set the variable to an initial condition. In this way the decrement calculation works, but the output variable is updated only when it exits the loop. I need the updated value at runtime.
The ultimate goal of all this.
With a kinetic energy (EcAcum) available (flywheel for example) I will define in pu the mechanical power input of a synchronous machine to feed a load (kW). With the reduction of EcAcum the power of the synchronous machine will also decrease until it is exhausted.
Regards