Need to calculate the power of battery

7 次查看(过去 30 天)
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.

回答(1 个)

Prudhvi Peddagoni
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 个评论
Ajit Bashyal
Ajit Bashyal 2021-3-18
Thank you for your informative response. This helps a lot to solve my problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by