Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Curious
Posts:
2,354
Registered:
12/6/04


Re: Need help with replacing the letter i with 1, 2, 3, 4
Posted:
Mar 9, 2014 12:34 AM


"John Dao" <SlimJ_87D@hotmail.com> wrote in message <lfgsqi$t4d$1@newscl01ah.mathworks.com>... > I'm a matlab noobie. I was wondering if I could get some help with my code. I am trying to replace i with 1, 2, 3, 4 > > t=[.5773,.5773,.5773,.5773] > s=[.5773, .5773, .5773, .5773] > for i = 1:4 > z(i) = [0, 1t(i),t(i)s(i),s(i)1; t(i)1, 0, s(i)+1, s(i)t(i); s(i)t(i), s(i)1, 0, t(i)+1;1s(i), s(i)+t(i), t(i)1,0]; > detJ(i) = (1/8) * (x * z * y), > a(i) = (1/4) * ((y1*(s(i)1))+(y2*(1s(i)))+(y3*(1+s(i)))+(y4*(1s(i)))); > b(i) = (1/4) * ((y1*(t(i)1))+(y2*(1t(i)))+(y3*(1+t(i)))+(y4*(1t(i)))); > c(i) = (1/4) * ((x1*(t(i)1))+(x2*(1t(i)))+(x3*(1+t(i)))+(x4*(1t(i)))); > d(i) = (1/4) * ((x1*(s(i)1))+(x2*(1s(i)))+(x3*(1+s(i)))+(x4*(1s(i)))); > B1(i)=.25*[(a1*(1+t(i)))(b1*(1+s(i))),0;0,(c1*(1+s(i)))(d1*(1+t(i))); (c1*(1+s(i)))(d1*(1+t(i))),(a1*(1+t(i)))(b1*(1+s(i)))] > B2(i)=.25*[(a1*(1t(i)))(b1*(1s(i))),0;0,(c1*(1s(i)))(d1*(1t(i))); (c1*(1s(i)))(d1*(1t(i))),(a1*(1t(i)))(b1*(1s(i)))] > B3(i)=.25*[(a1*(1+t(i)))(b1*(1+s(i))),0;0,(c1*(1+s(i)))(d1*(1+t(i))); (c1*(1+s(i)))(d1*(1+t(i))),(a1*(1+t(i)))(b1*(1+s(i)))] > B4(i)=.25*[(a1*(1t(i)))(b1*(1s(i))),0;0,(c1*(1s(i)))(d1*(1t(i))); (c1*(1s(i)))(d1*(1t(i))),(a1*(1t(i)))(b1*(1s(i)))] > B{i} = (1/detJ(i))*[B1(i),B2(i),B3(i),B4(i)] > end > > What I'm trying to do is find matrix B1, B2, B3, B4. > > Is there any easy way for me to do this? I know my code is very wrong at this point. I just want it to run the thing with all the i as 1, then as 2, then as 3, then as 4. > > Thanks in advance.
Well, the general answer to your question is that the for loop in the above code should do exactly what you want. But, as you said, the rest of the code is very wrong.
First. you cant place a vector into a single element of z. Change
z(i) = [0, 1t(i),t(i)s(i),s(i)1; t(i)1, 0, s(i)+1, s(i)t(i); s(i)t(i), s(i)1, 0, t(i)+1;1s(i), s(i)+t(i), t(i)1,0];
to
z = [0, 1t(i),t(i)s(i),s(i)1; t(i)1, 0, s(i)+1, s(i)t(i); s(i)t(i), s(i)1, 0, t(i)+1;1s(i), s(i)+t(i), t(i)1,0];
or make it a cell array (using curly brackets) as
z{I} = [0, 1t(i),t(i)s(i),s(i)1; t(i)1, 0, s(i)+1, s(i)t(i); s(i)t(i), s(i)1, 0, t(i)+1;1s(i), s(i)+t(i), t(i)1,0];
Then you will probably find the same problems with the next statement
detJ(i) = (1/8) * (x * z * y),
Without knowing what x & y are, its hard to say how to fix it.
Post whatever error messages you get and perhaps we can help you more.



