Not working, mohr circle

조회 수: 3 (최근 30일)
Maria Chu
Maria Chu 2015년 6월 20일
답변: Geoff Hayes 2015년 6월 22일
I try to execute the program, but its not working. I need to plot a circle (Mohr Circle) and display some results.
Sigmax=-60; %Normal Stress X Axis
Sigmay=90; %Normal Stress Y Axis
Tauxy=30; %Shear Stress
theta=-25; %Rotation of element
%Stresses in terms of the rotated coordinate
Sigmaxp=0.5*(Sigmax+Sigmay)+0.5*(Sigmax-Sigmay)*cos(2*theta)+Tauxy*sin(2*theta);
%Normal Stress X2 Axis
Sigmayp=0.5*(Sigmax+Sigmay)-0.5*(Sigmax-Sigmay)*cos(2*theta)-Tauxy*sin(2*theta);
%Normal Stress Y2 Axis
Tauxpyp=-0.5*(Sigmax+Sigmay)-0.5*(Sigmax-Sigmay)*cos(2*theta)-Tauxy*sin(2*theta); %Shear Stress
SigmaAve=0.5*(Sigmax+Sigmay); %Average Stress
r=(((0.5*(Sigmax-Sigmay))^2)+Tauxy^2);
MaximumStress=SigmaAve+r; %Maximum Principal Stress
MinimumStress=SigmaAve-r; %Minimum Principal Stress
MaximumTau=((0.5*(Sigmax-Sigmay))^2+Tauxy^2)^0.5;
Principaltheta1=0.5*arctan((2*Tauxy)/(Sigmax-Sigmay));
Principaltheta2=90+Principaltheta1;
Secondarytheta1=0.5*arctan((Sigmax-Sigmay)/(2*Tauxy));
Secondarytheta2=90+Secondarytheta1;
Display Sigmaxp;
Display Sigmayp;
Display Tauxpyp;
Display MaximumStress;
Display MinimumStress;
Display MaximumTau
Display Principaltheta1;
Display Principaltheta2;
Display Secondatytheta1;
Display Secondarytheta2;
function circle(SigmaAve,0,r);
%SigmaAve and 0 are the coordinates of the circle
%r is the radius of the circle
%0.01 is the angle step
ang=0:0.01:2*pi;
xp=R*cos(ang);
yp=R*sin(ang);
plot(x+xp,y+yp);
end
>> P8
Error: File: P8.m Line: 27 Column: 1
Function definitions are not permitted in this context.
  댓글 수: 1
Image Analyst
Image Analyst 2015년 6월 21일
Also, FUNCTION and END must be lower case, and you need to have Display defined somewhere.
I have no idea what went wrong, because you didn't say, but we will after you read that first link I gave you and you fix your post. Just to be clear POST ALL THE RED ERROR TEXT!

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

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 6월 22일
Maria - the error message is telling you that have incorrectly setup your MATLAB file, P.m. You cannot include a function within a script (like you have done) but should either create a new file (for this function) or embed rework your script into a function (which will allow multiple functions to be defined in the same file).
It isn't clear to me why the first 26 lines precede the function definition as they don't provide any data to or even call the circle function.
Note also how your function has been defined
function circle(SigmaAve,0,r);
%SigmaAve and 0 are the coordinates of the circle
%r is the radius of the circle
%0.01 is the angle step
ang=0:0.01:2*pi;
xp=R*cos(ang);
yp=R*sin(ang);
plot(x+xp,y+yp);
end
You pass in SigmaAve as a variable but do not use it anywhere in the functionb body. The second input is a number (zero) when you should be using a variable to represent this number. Finally, the third input parameter is r but you are referencing it as R in the function body. (This mismatch will cause an error to be thrown.)

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by