필터 지우기
필터 지우기

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];

조회 수: 2 (최근 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);

답변 (2개)

KALYAN ACHARJYA
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.
Requested to read about array indexing.
  댓글 수: 2
KALYAN ACHARJYA
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.

댓글을 달려면 로그인하십시오.


Advait Sinha
Advait Sinha 2019년 6월 25일
I am new to matlab so I’m finding it confusing and hard

태그

Community Treasure Hunt

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

Start Hunting!

Translated by