Unexpected MATLAB expression.

조회 수: 3 (최근 30일)
lgdupont
lgdupont 2019년 2월 10일
댓글: lgdupont 2019년 2월 10일
Everything works until the while loop. The Sbar matrix is where I have issues. The first line works. On the second line at the first 'S12' I get an error "Invalid syntax at 'S12'. Possibly, a ), }, or ] is missing." The fifth line has an error on the first 'S11' saying "Parse error at S11: usage might be invalid MATLAB syntax." On the eighth line on the first '(' I get the error "Parse error at '(': usage might be invalid MATLAB syntax."
If anyone can help me as to why I'm getting these errors, it would be much appreciated! I tried not splitting the lines and I still get the same errors.
My code:
E11 = 100E9;
E22 = 18E9;
nu12 = 0.33;
G12 = 10E9;
S = [1/E11 -nu12/E11 0; -nu12/E11 1/E22 0; 0 0 1/G12];
Q = [E11^2/(E11-nu12^2*E22) nu12*E11*E22/(E11-nu12^2*E22) 0; nu12*E11*E22/(E11-nu12^2*E22) ...
E11*E22/(E11-nu12^2*E22) 0; 0 0 G12];
S11 = S(1,1);
S12 = S(1,2);
S22 = S(2,2);
S33 = S(3,3);
theta = 0;
while theta <= pi/2
Sbar = [S11*cos(theta)^4+(2*S12+S33*cos(theta)^2*sin(theta)^2+S22*sin(theta)^4 ...
S12*(cos(theta)^4+sin(theta)^4)+(S11+S22-S33)*cos(theta)^2*sin(theta)^2 ...
(2*S11-2*S12-S33)*cos(theta)^3*sin(theta)-(2*S22-2*S12-S33)*cos(theta)*sin(theta)^3; ...
S12*(cos(theta)^4+sin(theta)^4)+(S11+S22-S33)*cos(theta)^2*sin(theta)^2 ...
S11*sin(theta)^4+(2*S12+S33)*cos(theta)^2*sin(theta)^2+S22*cos(theta)^4 ...
(2*S11-2*S12-S33)*cos(theta)*sin(theta)^3-(2*S22-2*S12-S33)*cos(theta)^3*sin(theta); ...
(2*S11-2*S12-S33)*cos(theta)^3*sin(theta)-(2*S22-2*S12-S33)*cos(theta)*sin(theta)^3 ...
(2*S11-2*S12-S33)*cos(theta)*sin(theta)^3-(2*S22-2*S12-S33)*cos(theta)^3*sin(theta) ...
2*(2*S11+2*S22-4*S12-S33)*cos(theta)^2*sin(theta)^2+S33*cos(theta)^4*sin(theta)^4];
Exx_eff = 1/Sbar(1,1);
Eyy_eff = 1/Sbar(2,2);
nu12_eff = -Sbar(1,2)/Sbar(1,1);
nu21_eff = -Sbar(1,2)/Sbar(2,2);
Gxy_eff = 1/Sbar(3,3);
etaxx,xy_eff = Sbar(1,3)/Sbar(1,1);
etayy,xy_eff = Sbar(2,3)/Sbar(2,2);
etaxy,xx_eff = Sbar(1,3)/Sbar(3,3);
etaxy,yy_eff = Sbar(2,3)/Sbar(3,3);
plot(theta,Exx_eff,Eyy_eff)
end

채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 10일
Count your brackets on the first line of that definition. You are missing a ) on that first line.
Start your count at 0; increase every time you encounter a ( or [ or { and decrease every time you encounter a } or ] or ) . You will find that at the end of the line the count is 1, indicating 1 too many open brackets compared to close brackets.
  댓글 수: 2
lgdupont
lgdupont 2019년 2월 10일
Ah yes, I see that now! I was looking for missing brackets on the second line. Thanks!
lgdupont
lgdupont 2019년 2월 10일
That fixed everything actually! Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by