Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matrix dimension mismatch

Subject: matrix dimension mismatch

From: Md. Mushfiqur

Date: 5 May, 2013 15:40:09

Message: 1 of 4

I am trying to calculate the equations of Tsr, Cp, Pf, Pair, Prot, Ke, E, I, Pe, Pgen, Pnet imposing conditions of the range "-0.05<Pnet && Pnet<0.05". In every iteration the compiler will work with the individual value of the matrix N(j,k). Thus working the first iteration, matlab will increase the value of j(row) until it goes to the 5th row, then it will increase the k(column), until it reaches the last value (row=5, column=3). Can you see what is the error in the codes

V=3.0;
j=1;
k=1;
N=[150 151.2 154.2; 156.9 161.4 167.3; 176.7 182 187.5; 193.5 200 206.6; 213.5 224.6 230;];
for i=0:1:300
V=V+0.01;
Tsr=(N(j,k)*3.14*0.34)/(V*60);
Cp=(((-1)*0.4416*Tsr*Tsr)+(0.4342*Tsr));
Pf=(N(j,k)*0.03*0.1046);
Pair=(1.212*V*V*V*0.153)/2;
Prot=N(j,k)*0.03*0.1046;
Ke=0.0955;
E=Ke*N(j,k);
I=(E-13-1.4)/15;
Pe=E*I*1.04;
Pgen=Pe+Pf;
Pnet=Prot-Pgen;
if((-0.05<Pnet) && (Pnet<0.05))
display(V)
display(N)
display(Tsr)
display(Cp)
display(Pf)
display(Pair)
display(Prot)
display(Ke)
display(E)
display(I)
display(Pe)
display(Pgen)
display(Pnet)
j=j+1;
end
if (j==5)
    k=k+1;
end
while (j>5 && k>3)
    break
end
N(j,k)
end

Subject: matrix dimension mismatch

From: pietro

Date: 6 May, 2013 07:01:09

Message: 2 of 4

"Md. Mushfiqur" wrote in message <km5ugp$m5m$1@newscl01ah.mathworks.com>...
> I am trying to calculate the equations of Tsr, Cp, Pf, Pair, Prot, Ke, E, I, Pe, Pgen, Pnet imposing conditions of the range "-0.05<Pnet && Pnet<0.05". In every iteration the compiler will work with the individual value of the matrix N(j,k). Thus working the first iteration, matlab will increase the value of j(row) until it goes to the 5th row, then it will increase the k(column), until it reaches the last value (row=5, column=3). Can you see what is the error in the codes
>
> V=3.0;
> j=1;
> k=1;
> N=[150 151.2 154.2; 156.9 161.4 167.3; 176.7 182 187.5; 193.5 200 206.6; 213.5 224.6 230;];
> for i=0:1:300
> V=V+0.01;
> Tsr=(N(j,k)*3.14*0.34)/(V*60);
> Cp=(((-1)*0.4416*Tsr*Tsr)+(0.4342*Tsr));
> Pf=(N(j,k)*0.03*0.1046);
> Pair=(1.212*V*V*V*0.153)/2;
> Prot=N(j,k)*0.03*0.1046;
> Ke=0.0955;
> E=Ke*N(j,k);
> I=(E-13-1.4)/15;
> Pe=E*I*1.04;
> Pgen=Pe+Pf;
> Pnet=Prot-Pgen;
> if((-0.05<Pnet) && (Pnet<0.05))
> display(V)
> display(N)
> display(Tsr)
> display(Cp)
> display(Pf)
> display(Pair)
> display(Prot)
> display(Ke)
> display(E)
> display(I)
> display(Pe)
> display(Pgen)
> display(Pnet)
> j=j+1;
> end
> if (j==5)
> k=k+1;
> end
> while (j>5 && k>3)
> break
> end
> N(j,k)
> end

in my computer it works but all elements of N are 150

Subject: matrix dimension mismatch

From: Md. Mushfiqur

Date: 6 May, 2013 11:39:09

Message: 3 of 4

"pietro " <bracardi82@email.it> wrote in message <km7kfl$8q7$1@newscl01ah.mathworks.com>...
> "Md. Mushfiqur" wrote in message <km5ugp$m5m$1@newscl01ah.mathworks.com>...
> > I am trying to calculate the equations of Tsr, Cp, Pf, Pair, Prot, Ke, E, I, Pe, Pgen, Pnet imposing conditions of the range "-0.05<Pnet && Pnet<0.05". In every iteration the compiler will work with the individual value of the matrix N(j,k). Thus working the first iteration, matlab will increase the value of j(row) until it goes to the 5th row, then it will increase the k(column), until it reaches the last value (row=5, column=3). Can you see what is the error in the codes
> >
> > V=3.0;
> > j=1;
> > k=1;
> > N=[150 151.2 154.2; 156.9 161.4 167.3; 176.7 182 187.5; 193.5 200 206.6; 213.5 224.6 230;];
> > for i=0:1:300
> > V=V+0.01;
> > Tsr=(N(j,k)*3.14*0.34)/(V*60);
> > Cp=(((-1)*0.4416*Tsr*Tsr)+(0.4342*Tsr));
> > Pf=(N(j,k)*0.03*0.1046);
> > Pair=(1.212*V*V*V*0.153)/2;
> > Prot=N(j,k)*0.03*0.1046;
> > Ke=0.0955;
> > E=Ke*N(j,k);
> > I=(E-13-1.4)/15;
> > Pe=E*I*1.04;
> > Pgen=Pe+Pf;
> > Pnet=Prot-Pgen;
> > if((-0.05<Pnet) && (Pnet<0.05))
> > display(V)
> > display(N)
> > display(Tsr)
> > display(Cp)
> > display(Pf)
> > display(Pair)
> > display(Prot)
> > display(Ke)
> > display(E)
> > display(I)
> > display(Pe)
> > display(Pgen)
> > display(Pnet)
> > j=j+1;
> > end
> > if (j==5)
> > k=k+1;
> > end
> > while (j>5 && k>3)
> > break
> > end
> > N(j,k)
> > end
>
> in my computer it works but all elements of N are 150

££££ Yes Sir, it shows only 150 the first element of the matrix. I was trying to use variable in the N(j,k), so that matlab takes the value from the matrix one by one until the last matrix of the matrix. Thus I feel there is a mistake in the code.

Subject: matrix dimension mismatch

From: pietro

Date: 6 May, 2013 21:00:09

Message: 4 of 4

"Md. Mushfiqur" wrote in message <km84ot$jhn$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message <km7kfl$8q7$1@newscl01ah.mathworks.com>...
> > "Md. Mushfiqur" wrote in message <km5ugp$m5m$1@newscl01ah.mathworks.com>...
> > > I am trying to calculate the equations of Tsr, Cp, Pf, Pair, Prot, Ke, E, I, Pe, Pgen, Pnet imposing conditions of the range "-0.05<Pnet && Pnet<0.05". In every iteration the compiler will work with the individual value of the matrix N(j,k). Thus working the first iteration, matlab will increase the value of j(row) until it goes to the 5th row, then it will increase the k(column), until it reaches the last value (row=5, column=3). Can you see what is the error in the codes
> > >
> > > V=3.0;
> > > j=1;
> > > k=1;
> > > N=[150 151.2 154.2; 156.9 161.4 167.3; 176.7 182 187.5; 193.5 200 206.6; 213.5 224.6 230;];
> > > for i=0:1:300
> > > V=V+0.01;
> > > Tsr=(N(j,k)*3.14*0.34)/(V*60);
> > > Cp=(((-1)*0.4416*Tsr*Tsr)+(0.4342*Tsr));
> > > Pf=(N(j,k)*0.03*0.1046);
> > > Pair=(1.212*V*V*V*0.153)/2;
> > > Prot=N(j,k)*0.03*0.1046;
> > > Ke=0.0955;
> > > E=Ke*N(j,k);
> > > I=(E-13-1.4)/15;
> > > Pe=E*I*1.04;
> > > Pgen=Pe+Pf;
> > > Pnet=Prot-Pgen;
> > > if((-0.05<Pnet) && (Pnet<0.05))
> > > display(V)
> > > display(N)
> > > display(Tsr)
> > > display(Cp)
> > > display(Pf)
> > > display(Pair)
> > > display(Prot)
> > > display(Ke)
> > > display(E)
> > > display(I)
> > > display(Pe)
> > > display(Pgen)
> > > display(Pnet)
> > > j=j+1;
> > > end
> > > if (j==5)
> > > k=k+1;
> > > end
> > > while (j>5 && k>3)
> > > break
> > > end
> > > N(j,k)
> > > end
> >
> > in my computer it works but all elements of N are 150
>
> ££££ Yes Sir, it shows only 150 the first element of the matrix. I was trying to use variable in the N(j,k), so that matlab takes the value from the matrix one by one until the last matrix of the matrix. Thus I feel there is a mistake in the code.

In your code i is used only in the for statement but not inside the loop

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us