Attempted to access x(-36); index must be a positive integer or logical.?

2 vues (au cours des 30 derniers jours)
Jared
Jared le 18 Oct 2014
Commenté : Jared le 19 Oct 2014
Hello, I am pretty new to MatLab. I am trying to write a code to calculate the 3 Principal Stresses of a Material. I'm not sure if I am using the function correctly or not, or if I am just making a small error in entering the formula. I keep getting the error above.
My code i have currently is:
1 - S = [x y z a b c];
2 - I(1) = x+y+z;
3 - I(2) = (x*y)+(y*z)+(x*z)-(a^2)-(b^2)-(c^2);
4 - I(3) = (x((y*z)-(b^2))-(a((a*z)-(b*c)))+(c((a*b)-(y*c))));
5 - t = ((1/3)/(cos(((2*I(1)^3)-(9*I(1)*I(2))+(27*I(3)))/(2*((I(1)^2)-(3*I(2))^(3/2))))));
6 - sigma(a) = (I(1)/3)+((2/3)*(((I(2)^2)-(3*I(2)))^(1/2))*(cos(t)));
7 - sigma(b) = ((I(1)/3)+((2/3)*(((I(1)^2)-(3*I(2)))^(1/2))*(cos((t)+((2*3.14)/3)))));
8 - sigma(c) = ((I(1)/3)+((2/3)*(((I(1)^2)-(3*I(2)))^(1/2))*(cos((t)+((4*3.14)/3)))));
x y z = to the stresses experienced by the corresponding planes
a b c = Shear stresses of the xy, yz, xz plane
x y z a b c are all the givens in the problem
Any help at all would be greatly appreciated to get this running. I don't know if i am even close with what i have, as i am really new to MatLab.
Thanks!
  1 commentaire
Image Analyst
Image Analyst le 18 Oct 2014
Attach your code. We can't run what you have posted above. MATLAB code does not start with numbers, plus we don't know what values x,y,x,a,b, and c take on. Make it easy for us to help you. Give us something that runs. But basically indexes start at 1 and are integers, like 1,2,3,4,5,etc. There is no -36th element of an array.

Connectez-vous pour commenter.

Réponses (1)

David Young
David Young le 18 Oct 2014
Image Analyst's comment is correct - working code and the values for the variables should be given. Nevertheless, I can make a guess that the expression
x((y*z)-(b^2))
which is part of the computation of I(3), is not what you mean. This expression computes the ((y*z)-(b^2))'th element of the array x. I suspect x is actually a scalar, and maybe you mean
x*((y*z)-(b^2))
or something of the sort. Likewise for the expressions a(...) and c(...).
  2 commentaires
John D'Errico
John D'Errico le 19 Oct 2014
I'd bet this is correct.
Jared
Jared le 19 Oct 2014
Thank You i was able to figure everything out now!
I really appreciate the help

Connectez-vous pour commenter.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by