Solving equation using for loop

2 ビュー (過去 30 日間)
Mangesh KAle
Mangesh KAle 2019 年 11 月 6 日
コメント済み: Star Strider 2019 年 11 月 6 日
Iteratively compute Vm. Starting with 0 , use a for-loop
to iterate through all time steps.
I am getting error in solving this. Am I solving this correctly?
clear all;
clc;
rm=0.9;
V(0)=0;
cm=12;
Tm=10.8;
t=0:0.05:250;
ie=25;
for i=1:length(t)-1
dV(i)=(1/Tm)*(rm*ie -V(i-1))*dt;
V(i+1) = V(i)+dV(i);
end

回答 (1 件)

Star Strider
Star Strider 2019 年 11 月 6 日
Your code throws (as expected from reading it):
Array indices must be positive integers or logical values.
V(0)=0;
MATLAB subscript indexing uses only integers greater than zero. You need to revise your code so that none of the subscripts are negative or zero.
  2 件のコメント
Mangesh KAle
Mangesh KAle 2019 年 11 月 6 日
getting this error
Array indices must be positive integers or logical values.
Error in TNS1_s2 (line 4)
V(0)=1;
Star Strider
Star Strider 2019 年 11 月 6 日
Please see my Answer!
I already explained the reason your code is throwing that error, and what you need to do to correct your code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by