Subscript dimension mismatch problem

I keep getting the error: Subscripted assignment dimension mismatch. Can some help me on how to fix this please
Error in untitled4 (line 39)
u(:,it+1:4)=((c*p(:,ip+1))+(d*p(:,ip))+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))/((a*MM)+(b*KM));
%Time
ti=0;
dt=0.02;
tf=5.98;
t=ti:dt:tf
nt=length(t)
%force
pi=0;
dp=2649.64;
pf=792242.36;
p=pi:dp:pf
np=length(p)
%Constants
alpha=0;
beta=0;
a1=alpha+(1/(0.5*dt));
b=beta+(0.5*dt);
c=0.5*dt;
d=(1-0.5)*dt;
e=1/0.5;
f=beta-((1-0.5)*dt);
g=1/(0.5*dt);
h=(1-0.5)/0.5;
%Initial conditions
u(:,1)=zeros;
v(:,1)=zeros;
a(:,1)=zeros;
p(:,1)=zeros;
MM=[1044,0,0,0;0,733.46,0,0;0,0,457.8,0;0,0,0,44.67];
KM=[9900000000,-9893000000,0,0;0,10000000000,-439000000,0;0,0,1370000000,-932200000;0,0,-932200000,932200000];
%time step
for it=1:nt-1;
for ip=1:np-1;
u(:,it+1)=((c*p(:,ip+1))+(d*p(:,ip))+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))/((a*MM)+(b*KM));
v(:,it+1)=g*(u(:,it+1)-u(:,it))-(h*v(:,it));
a(:,it+1)=g*(v(:,it+1)-v(:,it))-(h*a(:,it));
end
end

댓글 수: 2

Adam
Adam 2015년 3월 6일
Your code does not contain the line specified in the error message. Where does the it+1:4 part come from?
Vivek Bhadouria
Vivek Bhadouria 2015년 3월 6일
Can you share the snnipet of the equation which you are trying to implement on Line#39?

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

답변 (1개)

Star Strider
Star Strider 2015년 3월 6일

1 개 추천

The right-hand-side of ‘u’ is a (4x4) matrix of identical rows. What do you want to do in that assignment?
Put this statement just before the ‘u(:,it+1)’ assignment to see the result of that calculation:
qu =((c*p(:,ip+1))+(d*p(:,ip))+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))/((a*MM)+(b*KM));

댓글 수: 4

Vivek Bhadouria
Vivek Bhadouria 2015년 3월 6일
Yeah, RHS is a 4X4 matrix but it's really unclear what kind of assignment in LHS is supposed to make!
laura  dolan
laura dolan 2015년 3월 7일
편집: Star Strider 2015년 3월 7일
i have updated the code to get:
MM=[1044,0,0,0;0,733.46,0,0;0,0,457.8,0;0,0,0,44.67];
KM=[9900000000,-9893000000,0,0;0,10000000000,-439000000,0;0,0,1370000000,-932200000;0,0,-932200000,932200000];
%Time
ti=0;
dt=0.02;
tf=5.96;
t=ti:dt:tf;
n=length(MM);
nt=fix((tf-ti)/dt);
%Constants
alpha=0;
beta=0;
a1=alpha+(1/(0.5*dt));
b=beta+(0.5*dt);
c=0.5*dt;
d=(1-0.5)*dt;
e=1/0.5;
f=beta-((1-0.5)*dt);
g=1/(0.5*dt);
h=(1-0.5)/0.5;
%Initial conditions
u=zeros(n,nt);
v=zeros(n,nt);
a=zeros(n,nt);
u(:,1) = zeros ;
v(:,1) = zeros ;
a(:,1) = zeros ;
%time step
for it=1:nt;
for t=ti:dt:tf;
P=2649.64*[0;0;0;1]*t;
P1=(2649.64*[0;0;0;1]*t)+(2649.624*[0;0;0;1]);
u(:,it+1)=((c*P1)+(d*P)+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))/((a*MM)+(b*KM));
v(:,it+1)=g*(u(:,it+1)-u(:,it))-(h*v(:,it));
a(:,it+1)=g*(v(:,it+1)-v(:,it))-(h*a(:,it));
end
end
but its still not working.
Essentially i am trying to solve the equations
ui+1=(c*P1)+(d*P)+(a1*MM*ui)+(e*MM*vi)+(f*KM*ui))/((a*MM)+(b*KM))
vi+1=g*(ui+1-ui)-(h*vi)
ai+1=g*(vi+1-vi)-(h*ai)
Any help is greatly appreciated
laura  dolan
laura dolan 2015년 3월 7일
sorry i don't know why it formatted like that but the equations i am trying to solve shouldn't have showed up on the one line, so I'm trying to solve:
ui+1=(c*P1)+(d*P)+(a1*MM*ui)+(e*MM*vi)+(f*KM*ui))/((a*MM)+(b*KM)); vi+1=g*(ui+1-ui)-(h*vi); ai+1=g*(vi+1-vi)-(h*ai)
You have to format your code yourself so it shows up the way you want. Highlight the code in your posts, and then use the [{}Code] button at the top of the Comment window to format code.
You need to look closely at the calculations you’re doing. In the ‘u’ assignment, for instance, break the line down into its component calcualtions to see where the problems are:
%time step
for it=1:nt;
for t=ti:dt:tf;
P=2649.64*[0;0;0;1]*t;
P1=(2649.64*[0;0;0;1]*t)+(2649.624*[0;0;0;1]);
uq1 = (c*P1)+(d*P);
uq2 = (a1*MM*u(:,it));
uq3 = (e*MM*v(:,it));
uq4 = (f*KM*u(:,it));
uq5 = ((MM*a(:,it)));
uq6 = (b*KM);
u(:,it+1)=((c*P1)+(d*P)+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))/((a*MM)+(b*KM));
v(:,it+1)=g*(u(:,it+1)-u(:,it))-(h*v(:,it));
a(:,it+1)=g*(v(:,it+1)-v(:,it))-(h*a(:,it));
end
end
Note that I changed the reference in ‘uq5’ to ‘a(:,it)’ to make it a (4x1) vector. (I believe that is what you wanted.) The ‘uq6’ term remains a (4x4) matrix, and that is causing problems in your code. I will leave it to you to sort that.
I have outlined some debugging strategies that you can expand upon to figure out the reason your code is not working, then correct your code to get it to work. Since I don’t understand what you’re doing, that’s the most I can do.

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

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

질문:

2015년 3월 6일

댓글:

2015년 3월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by