Attempted to access x(-36); index must be a positive integer or logical.?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2014-10-18
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.
回答(1 个)
David Young
2014-10-18
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(...).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!