Need to calculate the power of battery

7 visualizaciones (últimos 30 días)
Ajit Bashyal
Ajit Bashyal el 4 de Mzo. de 2021
Comentada: Ajit Bashyal el 18 de Mzo. de 2021
Hello there,
Please kindly help me to write the matlab function code to calculate the power of the battery. Actually, the problem is that I have the I have a cost function whose output is battery power and there are several inputs. But the equation to calculate the input variables also depend on the output of previous time which is currently unknown. I can give you some example here:
function [X(t)]=batterypower(a(t)+b(t)+c(t)+d(t))
a(t)=b(t-1)+c(t-1)/X(t-1);
b(t)=a(t-1)/d(t-1);
c(t)=X(t-1)-d(t-1)/a(t-1);
d(t)=c(t-1)*b(t-1)/a(t-1)
where t=0:100 %time
I used for loop but still cannot get the result.
This is just the example but my problem is also similar. As we can see the input variable also depend on past output variable which is not yet calculated. How can write this in matlab function code. If anybody can help me, please I would be very thankful to him/her.
If you require my equation and given data, I would share that too. Please help me.

Respuestas (1)

Prudhvi Peddagoni
Prudhvi Peddagoni el 8 de Mzo. de 2021
Hi,
You can create arrays beforehand and try to fill it from t = 1 to 100.
a = zeros(1,100);
b = zeros(1,100);
c = zeros(1,100);
d = zeros(1,100);
X = zeros(1,100);
%Initialise
a(1) = 1;
b(1) = 1;
c(1) = 1;
d(1) = 1;
X(1) = 1;
for i = 1:100
[a,b,c,d,X] = batterypower(a,b,c,d,X,i);
end
function [a,b,c,d,X] = batterypower(a,b,c,d,X,t)
a(t)=b(t-1)+c(t-1)/X(t-1);
b(t)=a(t-1)/d(t-1);
c(t)=X(t-1)-d(t-1)/a(t-1);
d(t)=c(t-1)*b(t-1)/a(t-1)
Hope this helps.
  1 comentario
Ajit Bashyal
Ajit Bashyal el 18 de Mzo. de 2021
Thank you for your informative response. This helps a lot to solve my problem.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB 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!

Translated by