Get left and right side argument trying to execute this code, any suggestions on how to fix it?

close all;
clear all;
% Material Properties of Boron/Epoxy composite
E1 = 30*10^6;
E2 = 3*10^6;
G12 = 1*10^6;
v12 = .3;
v21 = v12*(E2/E1);
% setting the zeros for the functions
figure
hold on;
theta = linspace(0,90,18);
Ex = zeros(size(theta));
Gxy = zeros(size(theta));
vxy = zeros(size(theta));
nxyx = zeros(size(theta));
% defining the functions
for i=1: length(theta)
theta(i)
[Ex(i)] = Ex_lon(E1,E2,G12,v12,theta(i));
[Gxy(i)] = Gxy_lon(E1,E2,G12,v12,theta(i));
[vxy(i)] = vxy_lon(Ex E1,E2,G12,v12,theta(i));
[nxyx(i)] = nxyx_lon(Ex E1,E2,G12,v12,theta(i));
end
% generating the plot
plot(theta,Ex/E2,'-+r',theta,Gxy/G12,'-*g',theta,vxy,'-^b',theta,nxyx,'-xk');
xlabel('\theta (degree)');
yyaxis left;
ylabel('E_x/E_2, Gxy/G12, -nxyx');
yyaxis right;
ylabel('vxy');
legend('E_x/E_2','Gxy/G12','vxy','-nxyx');
hold off
% the following are the functions that the previously defined functions are
% called to
function [Ex] = Ex_lon(E1,E2,G12,v12,theta)
E_inv = (1/E1)*(cosd(theta)^4) + (1/G12- 2*v12/E1)*(sind(theta)^2)*(cosd(theta)^2) + (1/E2)*(sind(theta)^4);
Ex = (1/E_inv);
end
function [Gxy] = Gxy_lon(E1,E2,G12,v12,theta)
Gxy_inv = 2*(2/E1 + 2/E2 + 4*v12/E1 - 1/G12)*(sind(theta)^2)*(cosd(theta)^2)+ 1/G12*((sind(theta)^4)+(cosd(theta)^4));
Gxy = 1/Gxy_inv;
end
function [vxy] = vxy_lon(Ex,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
function [nxyx] = nxyx_lon(Ex E1,E2,G12,v12,theta)
nxyx = Ex*((2/E1 + 2/E2 - 1/G12)*(sind(theta))*(cosd(theta)^3)-(2/E2 +2*v12/E1 - 1/G12)*(sind(theta)^3)*(cosd(theta)));
end

7 Comments

There is the issue as the all output arguments of different function are vectors, you are trying to save all those output arguments in array???
for i=1:length(theta)
Ex(i)=Ex_lon(E1,E2,G12,v12,theta(i));
Gxy(i)=Gxy_lon(E1,E2,G12,v12,theta(i));
vxy(i)=vxy_lon(Ex,E1,E2,G12,v12,theta(i));
nxyx(i)=nxyx_lon(Ex,E1,E2,G12,v12,theta(i));
end
Also note on "./" vector dot operation.
Yes, vxy_lon passes the vector Ex in and uses the entire vector. Perhaps it should only be passing Ex(i) in; likewise on the next line.
Yes these are macro mechanical equations for materials meant to be plotted together on one plot to compare the plots. With Ex removed from the vx and nxy,x functions, the program runs perfectly but the plots are obviously not correct for those two.
Got it gentlemen, thank you for the help. Definitely led me in the correct direction.

Sign in to comment.

Answers (0)

Tags

Asked:

on 9 Nov 2019

Commented:

on 9 Nov 2019

Community Treasure Hunt

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

Start Hunting!