フィルターのクリア

How can I put the value of z in a matrix and later call it as z(1,i) and z(2,i) in the while loop?

1 回表示 (過去 30 日間)
close all;
dt = 0.1;%time step
u1=1;
u2=1;
c = u2-u1;
u = sign(u2-u1);
z = u*c;
k=0.12;
m=2.21;%initial parameters
v=1;
a=1.4;
tend=1000;
t=0;
i=1
while t < tend-2*dt
vh=v(i)-dt*k*z(i)/ (2*m);
z(i+1) = z(i)+ dt*vh;
%a(i+1)= -k*z(i)/2;
v(i+1)= vh-dt*k*z(i+1)/ (2*m);% + dt*a(i+1)/2;
i = i+1;
t = t + dt
end
plot(z);
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 26 日
What should be in z(1,i) and what should be in z(2,i)?
Advait Sinha
Advait Sinha 2019 年 6 月 26 日
Z(2,i)= z(1,i)+dt*vh
Basically z(1,i) and z(2,i) would give the position of the first two coordinates of the linear system represented by the code. Z can be any matrix such that z(:,1) = [0;1]

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

回答 (2 件)

sourav  malla
sourav malla 2019 年 6 月 26 日
If you want a matrix of 2 column with changing row values then you can do like this:-
while i<t
Z(2,i)= z(1,i)+dt*vh;
i=i+1
end

Advait Sinha
Advait Sinha 2019 年 6 月 26 日
But then what would happen to the other equations that also make use of z. Also would I need to implement z as a matrix before the while loop too

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by