Help with knowing what kind of vector im using

1 回表示 (過去 30 日間)
Lavorizia Vaughn
Lavorizia Vaughn 2021 年 11 月 13 日
コメント済み: Lavorizia Vaughn 2021 年 11 月 13 日
could someone tell me what th2s=[th2s,y(2)] means?
th1=1;
th2=1;
w1=0;
w2=0;
hs(1)=[0.05];
hs(2)=[0.05/2];
hs(3)=[0.05/4];
hs(4)=[0.05/8];
hs(5)=[1/1000];
th2s=[];
for h=hs %for all the stepsizes
y=[th1,th2,w1,w2]; we have this vetir which has the values
N=100/h;
for i=1:N
k1= h*fpend(y);
k2=h*fpend(y + k1/2);
k3=h*fpend(y + k2/2);
k4= h*fpend(y + k3);
y = y + (k1 + 2*k2 + 2*k3 + k4) / 6;
end
th2s=[th2s,y(2)]
end

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 11 月 13 日
It is appending y(2) to the end of the vector th2s at the end of each h loop.
th2s=[];
for a=1:3
a
th2s = [th2s,a]
end
a = 1
th2s = 1
a = 2
th2s = 1×2
1 2
a = 3
th2s = 1×3
1 2 3
  3 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 11 月 13 日
It looks like you are doing a 4th order runge-kutta. There are a lot of questions about implementing that on Answers. Take a look at some of them for ideas. Your code looks pretty clean. Just be sure to place a % before any comments.
Lavorizia Vaughn
Lavorizia Vaughn 2021 年 11 月 13 日
i am doing a rk4. and i wish to find a better way. this way seems a bit hard.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by