Jovo854
Jovo854

Reputation: 33

How to plot stress distribution diagram?

I'm trying to plot a diagram showing a distribution of stress over a section of a beam in matlab or some other program. This is the given function:

  s(y): (q/(h^3*l))*(l^3*2*y+(l/5)*(3*h^2*y-20*y^3))

where s represents the stess, y the height. y goes from -h/2 to h/2. h,q and l are given as known values without specific numbers.

Can someone please explain how to do this in some program or even manually?

Upvotes: 2

Views: 640

Answers (2)

Tarik
Tarik

Reputation: 11209

What you want to do is to plot a 3D surface. The following documentation explains how to generate a meshgrid which covers a regularly spaced x and y values within a selected range. The z value is then calculated for each then ployed.

See https://matplotlib.org/3.1.0/gallery/mplot3d/surface3d.html

Upvotes: 1

CitizenInsane
CitizenInsane

Reputation: 4855

Here below is some matlab code to plot stress distribution for a given set of (h,q,l) values. You specified for what should be the range of y (i.e [-h/2, h/2]), but you did not specified how many samples ... Change the count value for more or less samples.

function [] = ShowStress(h, q, l, count)
%[
    % Default arguments
    if (nargin < 4), count = 1001; end
    if (nargin < 3), l = 0.1; end
    if (nargin < 2), q = 10; end
    if (nargin < 1), h = 10; end

    % Create range of values for y
    y = linspace(-h/2, h/2, count);

    % Compute stress distribution
    s = (q/(h^3*l))*(l^3*2*y+(l/5)*(3*h^2*y-20*y.^3));

    % Plot things
    plot(y, s);
    xlabel('y'); ylabel('stress');
    title(sprintf('Stress distribution (h = %G, q = %G, l = %G)', h, q, l));  
%]
end

enter image description here

Upvotes: 2

Related Questions