MATLAB: Plotting Multiple Functions on One Line

engineeringmechanical engineering

I need help with a homework assignment in terms of having all functions on one plot.
Below is the problem:
We want to understand the fine details of the relationships between the various properties of a material and its orientation. This is best done by developing your own code. Using MATLAB, recreate a figure similar to Figure 2.11 in Jones using the material properties listed below. They are representative of a boron/epoxy composite. It is ok to create a separate plot for Poisson's ratio. Please download and examine the attached MATLAB script (M) for expectations and hints on how to complete MATLAB assignments for this course.
  • E1 = 45.0 x 106 psi
  • E2 = 5.0 x 106 psi
  • G12 = 1.5 x 106 psi
  • v12 = 0.3
I have posted my code below. I was able to get Ex/E2 to successfully display, however when I try to add another function, Vxy, I cannot get it to display.
We are asked to replicate this plot:
So far I believe I know what functions I need use, I just need help with putting it on one plot. Also, it was suggested to use ratios? I.E. E1 could = 3? I am not sure what he meant about that part.
% The purpose of this code is to
% (1) We want to understand the fine details of the relationships between
%the various properties of a material and its orientation.
%This will be representative of a boron/epoxy composite
%just like the video, start by closing all existing windows and plots that
%are open and %clearing
%all variables
close all;
clear all;
%Define Material Properties if applicable
%boron-epoxy composite
E1 = 45.0*10^6;
E2 = 5.0*10^6;
G12 = 1.5*10^6;
v12 = .3;
%derived
v21 = v12*(E2/E1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Part 1 - Plot the ratios per figure 2.11 in Jones first part for Ex/E2
figure %create a new figure but hold it for the calculations to be made
hold on;
theta = linspace (0,90,18);
Ex = zeros(size(theta));
Vxy = zeros(size(theta));
for i = 1: length(theta)
theta(i)
[Ex(i)] = E_longitudinal (E1, E2, G12, v12, theta(i));
[Vxy(i)] = Vxy_longitudinal (E1, E2, G12, v12, theta(i));
end
plot(theta, Ex/E2, '-+r');%plot uses red squares
plot(theta, Vxy, '-+b');
xlabel ('\theta (degree)');
ylabel ('E_x/E_2', '|Vxy|');
legend ('E_x/E_2', 'Vxy');
yyaxis left;
pLeft = plot(theta, Ex/E2, 'bs', theta, Gxy/G12, 'ko', theta, -nxy, 'g+');
yyaxis right;
pRight = plot(theta, Vxy, 'rs');
xlabel('\theta (degree)');
yyaxis left;
ylabel('Ex/E_2, Gxy/G12, -\etaxy, x');
yyaxis right;
ylabel('\nuxy');
h = (pLeft; pRight);
legend(h, 'Ex/E2', 'Gxy/G12', '-\etaxy,x', '\nuxy');
hold off
%%%%%%%%%%%%%functions%%%%%%%%%%%%%%%%%%%%%%%
%Find longitudinal stiffness using eq 2.97
function [Ex] = E_longitudinal (E1, E2, G12, v12, theta)
%eq 2.97
E_Inverse = (1/E1)*(cosd(theta)^4) + (1/G12 - 2*v12/E1)*(sind(theta)^2)*(cosd(theta)^2) + (1/E2)*(sind(theta)^4);
Ex = 1/E_Inverse;
end
function [Vxy] = Vxy_longitudinal (E1, E2, G12, v12, theta)
Vxy = Ex*((V12/E1)*((sind(theta))^4+(cosd(theta))^4)-((1/E1)+(1/E2)-(1/G12))*(sind(theta))^2*(cosd(theta))^2);
end

Best Answer

% The purpose of this code is to
% (1) We want to understand the fine details of the relationships between
%the various properties of a material and its orientation.
%This will be representative of a boron/epoxy composite
%just like the video, start by closing all existing windows and plots that
%are open and %clearing
%all variables
close all;
clear all;
%Define Material Properties if applicable
%boron-epoxy composite
E1 = 45.0*10^6;
E2 = 5.0*10^6;
G12 = 1.5*10^6;
v12 = .3;
%derived
v21 = v12*(E2/E1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Part 1 - Plot the ratios per figure 2.11 in Jones first part for Ex/E2
figure %create a new figure but hold it for the calculations to be made
hold on;
theta = linspace (0,90,18);
Ex = zeros(size(theta));
Vxy = zeros(size(theta));
for i = 1: length(theta)
theta(i)
[Ex(i)] = E_longitudinal (E1, E2, G12, v12, theta(i));
[Vxy(i)] = Vxy_longitudinal (E1, E2, G12, v12, Ex(i), theta(i)); %FIXED



end
ans = 0
ans = 5.2941
ans = 10.5882
ans = 15.8824
ans = 21.1765
ans = 26.4706
ans = 31.7647
ans = 37.0588
ans = 42.3529
ans = 47.6471
ans = 52.9412
ans = 58.2353
ans = 63.5294
ans = 68.8235
ans = 74.1176
ans = 79.4118
ans = 84.7059
ans = 90
plot(theta, Ex/E2, '-+r');%plot uses red squares
plot(theta, Vxy, '-+b');
xlabel ('\theta (degree)');
ylabel ({'E_x/E_2', '|Vxy|'}); %FIXED
legend ('E_x/E_2', 'Vxy');
yyaxis left;
pLeft = plot(theta, Ex/E2, 'bs', theta, Gxy/G12, 'ko', theta, -nxy, 'g+');
Unrecognized function or variable 'Gxy'.
yyaxis right;
pRight = plot(theta, Vxy, 'rs');
xlabel('\theta (degree)');
yyaxis left;
ylabel('Ex/E_2, Gxy/G12, -\etaxy, x');
yyaxis right;
ylabel('\nuxy');
h = [pLeft; pRight]; %FIXED
legend(h, 'Ex/E2', 'Gxy/G12', '-\etaxy,x', '\nuxy');
hold off
%%%%%%%%%%%%%functions%%%%%%%%%%%%%%%%%%%%%%%
%Find longitudinal stiffness using eq 2.97
function [Ex] = E_longitudinal (E1, E2, G12, v12, theta)
%eq 2.97
E_Inverse = (1/E1)*(cosd(theta)^4) + (1/G12 - 2*v12/E1)*(sind(theta)^2)*(cosd(theta)^2) + (1/E2)*(sind(theta)^4);
Ex = 1/E_Inverse;
end
function [Vxy] = Vxy_longitudinal (E1, E2, G12, V12, Ex, theta) %FIXED
Vxy = Ex*((V12/E1)*((sind(theta))^4+(cosd(theta))^4)-((1/E1)+(1/E2)-(1/G12))*(sind(theta))^2*(cosd(theta))^2);
end
I cannot fix the Gxy problem as you have no code anywhere that defiens Gxy.