Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Need help with replacing the letter i with 1, 2, 3, 4
Replies: 3   Last Post: Mar 9, 2014 1:19 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 1,986
Registered: 12/6/04
Re: Need help with replacing the letter i with 1, 2, 3, 4
Posted: Mar 9, 2014 12:34 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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, 1-t(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;1-s(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*(-1-s(i)))+(y3*(1+s(i)))+(y4*(1-s(i))));
> b(i) = (1/4) * ((y1*(t(i)-1))+(y2*(1-t(i)))+(y3*(1+t(i)))+(y4*(-1-t(i))));
> c(i) = (1/4) * ((x1*(t(i)-1))+(x2*(1-t(i)))+(x3*(1+t(i)))+(x4*(-1-t(i))));
> d(i) = (1/4) * ((x1*(s(i)-1))+(x2*(-1-s(i)))+(x3*(1+s(i)))+(x4*(1-s(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*(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)))]
> 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*(-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)))]
> 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, 1-t(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;1-s(i), s(i)+t(i), -t(i)-1,0];

to

z = [0, 1-t(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;1-s(i), s(i)+t(i), -t(i)-1,0];

or make it a cell array (using curly brackets) as

z{I} = [0, 1-t(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;1-s(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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.