I am unable run this code , can i know where is wrong

1 view (last 30 days)
function [theta_p, epsilon_max, epsilon_min, Y_max_in] = P_7_C6(-260,-60,480,0.334)
%
% Define average normal strain
epsilon_avg = ((epsilon_x + epsilon_y)/2);
%
% Calculate, Radius of the Mohr circle
R = sqrt(((((epsilon_x) - (epsilon_y))/2)^2) + ((Y_xy/2)^2) );
%
% Calculate maximum principal strain
epsilon_max = epsilon_avg + R;
%
% Calculate minimum principal strain
epsilon_min = epsilon_avg - R;
%
% Locate the position of the principal plane
theta_p = (atand((Y_xy)/ ((epsilon_x) - (epsilon_y) ) ) )/2;
%
% Calculate maximum in-plane shear strain
Y_max_in = 2*R;
%
% Define third principal strain along an axis perpendicular
% to the plane of stress.
epsilon_c = -(nu/ (1-nu) )* ((epsilon_max) + (epsilon_min));
%
% Calculate maximum shear strain
if (epsilon_max >= epsilon_min && epsilon_min >= epsilon_c)
Y_max_out = (epsilon_max) - (epsilon_c);
elseif (epsilon_max >= epsilon_c && epsilon_c >= epsilon_min)
Y_max_out = (epsilon_max) - (epsilon_min);
elseif (epsilon_c >= epsilon_max && epsilon_max >= epsilon_min)
Y_max_out = (epsilon_c) - (epsilon_min);
end
%
%Print the output values
fprintf([ '\nAngle between xy axes and principal axes ',...
'(+ Counter-clockwise) :' ])
fprintf([ * \n-------------------------------------------',...
'-------------------------\n' ])
fprintf( 'Principal plane is at %f Degrees \n' , theta_p)
fprintf (['epsilon_a = %d micro meter\nepsilon_b = %d micro ',...
'meter\n' ], epsilon_max, epsilon_min)
fprintf( 'epsilon_c = %5.2f micro meter \n', epsilon_c)
fprintf([ '\n--------------------------------------------- ,...
'---------------------\n' ])
fprintf(['Y_max(in-plane) = %5.2f micro radians',...
'\nY_max(out-of-plane) = %5.2f micro radians \n' ], Y_max_in, Y_max_out)
end

Answers (1)

Bhanu Prakash
Bhanu Prakash on 11 Jul 2024
Hi Saravana,
The provided code has the following errors:
  • The arguments [epsilon_x, epsilon_y, Y_xy, nu] that you are using in the function 'P_7_C6' must be passed as input arguments to the function. Assuming that the values of [epsilon_x, epsilon_y, Y_xy, nu] are [-260, -60, 480, 0.334] respectively, the funciton signature can be modified as:
function [theta_p, epsilon_max, epsilon_min, Y_max_in] = P_7_C6(epsilon_x, epsilon_y, Y_xy, nu)
  • The character vectors in the 'fprintf' statements are not properly terminated.
Here is the modified code after resolving the errors:
function [theta_p, epsilon_max, epsilon_min, Y_max_in] = P_7_C6(epsilon_x, epsilon_y, Y_xy, nu)
%
% Define average normal strain
epsilon_avg = ((epsilon_x + epsilon_y)/2);
%
% Calculate, Radius of the Mohr circle
R = sqrt(((((epsilon_x) - (epsilon_y))/2)^2) + ((Y_xy/2)^2) );
%
% Calculate maximum principal strain
epsilon_max = epsilon_avg + R;
%
% Calculate minimum principal strain
epsilon_min = epsilon_avg - R;
%
% Locate the position of the principal plane
theta_p = (atand((Y_xy)/ ((epsilon_x) - (epsilon_y) ) ) )/2;
%
% Calculate maximum in-plane shear strain
Y_max_in = 2*R;
%
% Define third principal strain along an axis perpendicular
% to the plane of stress.
epsilon_c = -(nu/ (1-nu) )* ((epsilon_max) + (epsilon_min));
%
% Calculate maximum shear strain
if (epsilon_max >= epsilon_min && epsilon_min >= epsilon_c)
Y_max_out = (epsilon_max) - (epsilon_c);
elseif (epsilon_max >= epsilon_c && epsilon_c >= epsilon_min)
Y_max_out = (epsilon_max) - (epsilon_min);
elseif (epsilon_c >= epsilon_max && epsilon_max >= epsilon_min)
Y_max_out = (epsilon_c) - (epsilon_min);
end
%
%Print the output values
fprintf([ '\nAngle between xy axes and principal axes ',...
'(+ Counter-clockwise) :' ])
fprintf([ '\n-------------------------------------------',...
'-------------------------\n' ])
fprintf( 'Principal plane is at %f Degrees \n' , theta_p)
fprintf (['epsilon_a = %d micro meter\nepsilon_b = %d micro ',...
'meter\n' ], epsilon_max, epsilon_min)
fprintf( 'epsilon_c = %5.2f micro meter \n', epsilon_c)
fprintf([ '\n---------------------------------------------' ,...
'---------------------\n' ])
fprintf(['Y_max(in-plane) = %5.2f micro radians',...
'\nY_max(out-of-plane) = %5.2f micro radians \n' ], Y_max_in, Y_max_out)
end
You can now call the function with the required values like this:
[theta_p, epsilon_max, epsilon_min, Y_max_in] = P_7_C6(-260, -60, 480, 0.334);

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!