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:
Summation over for loop-Subscripted assignment dimension mismatch.

Subject: Summation over for loop-Subscripted assignment dimension mismatch.

From: Vsh

Date: 9 Dec, 2012 01:40:08

Message: 1 of 2

Hi guys, I'm trying to get the summation over for loop statement for A(i,j). First, I'm not sure if i'm doing the whole summation right, secondly, I get a subscripted assignment dimension mismatch error, but I quiet don't understand why. Thanks for the help.

clear all
close all

%Crack length
b=10;
% # of elements on the line
N=10;
% Poisson's ratio
v=0.1;
%Pressure
PR=1;
%Shear modulus
G=1000;
%BE Length
a=b/N;

x=linspace(0,b,2*N+1);
y=x;

for i=1:N
    X(i)=x(2*i-1)+a/2;
end

xp=X';

XX=zeros(N,N);

for i=1:N
    for j=1:N
        XX(i,j)=xp(i)-xp(j);
    end
    XX(i,i)=a/N^2;
end

B=(-G/pi/(1-v))*ones(N,N);
a1=a*ones(N,N);

K=1;
A=ones(N,N);
for i=1:N
    for j=1:N
        A(i,j)=B*(XX(i,j).^2-(a1).^2)
    end
    K=K+1;
end

Subject: Summation over for loop-Subscripted assignment dimension mismatch.

From: Roger Stafford

Date: 9 Dec, 2012 23:23:13

Message: 2 of 2

"Vsh" wrote in message <ka0q5o$hvc$1@newscl01ah.mathworks.com>...
> Hi guys, I'm trying to get the summation over for loop statement for A(i,j). First, I'm not sure if i'm doing the whole summation right, secondly, I get a subscripted assignment dimension mismatch error, but I quiet don't understand why. .....
> .........
> B=(-G/pi/(1-v))*ones(N,N);
> a1=a*ones(N,N);
>
> K=1;
> A=ones(N,N);
> for i=1:N
> for j=1:N
> A(i,j)=B*(XX(i,j).^2-(a1).^2)
> end
> K=K+1;
> end
- - - - - - - - - - - -
  In the line

 A(i,j)=B*(XX(i,j).^2-(a1).^2) ,

on the right side you have an entire 10 by 10 matrix product and you are trying to squeeze it into the scalar, A(i,j). It just won't fit! What is it you expect to happen here?

  In any case, the expression B*(XX(i,j).^2-(a1).^2) would be an awfully hard way to calculate that result there, which tells me that you meant something altogether different for the right side, presumably something that is also a scalar. Also there is a K counter here which you have made no use of at all. Only you can determine what is "right". However I would hazard the guess that you meant this:

 A(i,j) = (-G/pi/(1-v))*(XX(i,j)^2-a^2);

Roger Stafford

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