Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1. Error in linear2d (line 7) z(:,1)=[0;1];
1 回表示 (過去 30 日間)
古いコメントを表示
close all;
dt = 0.1;%time step
u1=1;
u2=1;
c = u2-u1;
u = sign(u2-u1);
z(:,1)=[0,1];
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(1,i)/ (2*m);
z(2,i) = z(1,i)+ dt*vh;
%a(i+1)= -k*z(i)/2;
v(i+1)= vh-dt*k*z(2,i)/ (2*m);% + dt*a(i+1)/2;
i = i+1;
t = t + dt
end
plot(z);
0 件のコメント
回答 (2 件)
KALYAN ACHARJYA
2019 年 6 月 25 日
編集済み: KALYAN ACHARJYA
2019 年 6 月 25 日
You defined v=1, as scalar, but you called the function as vector v(i)
vh=v(i)-dt*k*z(1,i)/ (2*m);
%....^.........
When i=1, then v(1)=??
When i=2, then v(2)=?? in iterations.
Also the while loops runs multiple times
As t < tend-2*dt, where t=0 and tend=1000, dt=0.1, On such case the size of z also not sufficient
vh=v(i)-dt*k*z(1,i)/ (2*m);
%...............^.........
Because z(:,1)=[0,1] allows only two iterations.
2 件のコメント
KALYAN ACHARJYA
2019 年 6 月 25 日
Yes, I have hinted where the error is, I have no idea what you doing inside the code. You have to properly define the v and z or you have to change the code. Please try to undestand why you getting the error? Probably you may solve it afterwards.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!