Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Summation over for loop-Subscripted assignment dimension mismatch.
Replies: 2   Last Post: Dec 9, 2012 6:23 PM

 Messages: [ Previous | Next ]
 Roger Stafford Posts: 5,929 Registered: 12/7/04
Re: Summation over for loop-Subscripted assignment dimension mismatch.
Posted: Dec 9, 2012 6:23 PM

"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

Date Subject Author
12/8/12 Vsh
12/8/12 neuronet
12/9/12 Roger Stafford