Problem with getting a reasonable plot for mixed positive and negative data result
显示 更早的评论
Hi all
I am having a problem with plotting of my solution as the resulting plotting has no meaning at all along with error displayed saying negative data ignored.
The code I am working on is related to Poisson's ration of a conventional honeycomb which plotted correctly before with certain variables (strut thickness-changed-, strut height-fixed-). However, as I change the variables, the plotted figure has no meaning at all.I tried semilogy code but still not getting a full, related figure.
I have included the code I am working and hope I can get a solution to this problem. The resulted plot should has the same trend as the photo below.
Thanks ......
clear all; close all; clc;
v = 0.3;
k = 2.4+(1.5*v);
Em = 2400;
alpha = [0.5 1 2];
beta = 0.1;
theta = [-60:0.05:60];
for i = 1:length(alpha)
for j = 1:length(theta)
A(i,j) = (cosd(theta(j))).*(cosd(theta(j)));
B(i,j) = (alpha(i)+sind(theta(j))).*(sind(theta(j)));
C(i,j) = (1+((k-1).*(beta.^2)));
D(i,j) = (1+((beta.^2).*(k+((cotd(theta(j))).*(cotd(theta(j)))))));
V_xy(i,j) = (A(i,j).*C(i,j)')/(B(i,j).*D(i,j)');
end
end
plot(theta,V_xy)
-----------------------------------------------------------------------------------
回答(2 个)
You've got such a huge spike for alpha = 0.5 at around theta = -30 that your plot just looks like a line on the default [min max] scale. Simply change the scale and it looks reasonable:
plot(theta, V_xy);
ylim([-50, 50]);
legend(sprintfc('alpha = %g', alpha));
In my opinion, your overuse of unnecessary brackets makes the formulae much harder to read. In addition, the loops are not needed. This would achieve the same result:
v = 0.3;
k = 2.4+(1.5*v);
Em = 2400;
alpha = [0.5 1 2];
beta = 0.1;
theta = -60:0.05:60;
%transpose alpha to a column vector
alpha = alpha.';
A = cosd(theta) .^ 2;
B = (alpha + sind(theta)) .* sind(theta); %requires R2016b or later
C = 1 + (k-1) * beta^2;
D = 1 + beta^2 * (k + cotd(theta).^2);
V_xy = A*C ./ (B.*D); %requires R2016b or later
If on an earlier version that R2016b, replace the two marked lines by:
B = bsxfun(@plus, alpha, sind(theta)) .* sind(theta);
V_xy = bsxfun(@rdivide, A*C, bsxfun(@times, B, D));
2 个评论
Hi Guillaume
First of all , thanks for replying
secondly, I used loops as I was coding other analytical equations along in such a manner as to get the results properly. Also, I changed the ylim but still don't get the correct trend.
I attached the code script for the Major poisson's ratio in which alpha set to a fixed value and beta set to three different values and the resulted plot was correct and reasonable.
You may check it by running it first to have an idea about the trend and after that give it a try by setting beta=0.1 and alpha=[0.5 1 2].
Thanks..
% V_xy Non-Dimensionalized Major Poisson's Ratio for Conventional
% Honeycomb Celluler Structure
% Alpha is constant
clear all; close all; clc;
v = 0.3; % Zero-Poisson's Ratio Honeycomb
k = 2.4+(1.5*v);
Em = 2400; % Vergin Material Young's Modulus
alpha = 2; % Vertical Strut Height
beta = [0.05 0.1 0.2]; % Strut Thickness
theta = [-60:0.05:60]; % Inclined Strut Inclination
for i = 1:length(beta)
for j = 1:length(theta)
A(i,j) = (cosd(theta(j))).*(cosd(theta(j)));
B(i,j) = (alpha+sind(theta(j))).*(sind(theta(j)));
C(i,j) = (1+((k-1).*(beta(i).^2)));
D(i,j) = (1+((beta(i).^2).*(k+((cotd(theta(j))).*(cotd(theta(j)))))));
V_xy(i,j) = (A(i,j).*C(i,j)')/(B(i,j).*D(i,j)');
end
end
plot(theta,V_xy)
Guillaume
2017-3-16
I know nothing about what you're plotting, but if it's not giving you what you want it's because you've made a mistake with your formulae.
I'll note that even for the plots you says is ok (alpha = 2), you have a discontinuity at theta = 0. You'll see it if you zoom in on [0, 0]. That is because for theta = 0, cotd(0) is infinite, so D is infinite. On the other hand sind(0) is 0, so your V_xy for theta = 0 is
V_xy = something / (0 * Inf)
which is undefined. So all your curves have a discontinuity. In addition, for alpha = 0.5, there are some strong peaks as previously stated.
Again, no loop is needed for calculating V_xy for different alpha, beta, and theta:
v = 0.3; % Zero-Poisson's Ratio Honeycomb
k = 2.4+(1.5*v);
Em = 2400; % Vergin Material Young's Modulus
alpha = [[0.5, 1, 2]]; % Vertical Strut Height as row vector
beta = permute([0.05, 0.1, 0.2], [1 3 2]); % Strut Thickness as a vector in 3rd dimension
theta = (-60:0.05:60).'; % Inclined Strut Inclination as a column vector
A = cosd(theta) .^ 2;
B = (alpha + sind(theta)) .* sind(theta); %requires R2016b or later
C = 1 + (k-1) * beta.^2;
D = 1 + beta.^2 .* (k + cotd(theta).^2); %requires R2016b or later
V_xy = A.*C ./ (B.*D); %requires R2016b or later
rows of V_xy correspond to the different theta, columns to the different alpha, and pages to the different beta. To produce your original (alpha = 2, 3 betas):
figure;
plot(theta, squeeze(V_xy(:, alpha == 2, :)));
legend(sprintfc('beta = %g', beta));
But then zoom in on theta = 0
xlim([-2 2])
and see the discontinuity.
You can also plots all of the data at once, with e.g.:
figure;
hold on;
for alphaidx = 1:numel(alpha);
plot3(theta, repmat(alpha(alphaidx), size(theta)), squeeze(V_xy(:, alphaidx, :)));
end
view(3);
zlim([-20 20])
xlim([-60 60])
ylabel('alpha');
xlabel('theta');
grid on;
legend(compose('alpha = %g, beta = %g', repelem(alpha(:), numel(beta)), repmat(beta(:), numel(alpha), 1)));
类别
在 帮助中心 和 File Exchange 中查找有关 Pulsed Waveforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!