MATLAB: How to make a line discontinue when it intersects with another line and display the intersection points

intersection points

I am trying to construct a Goodman diagram to study fatigue and am having a couple problems formatting the graph:
1. How can I discontinue the load line when it intersects with the Goodman line? I currently have the load line set to certain x values, which isn't correct, but I don't know what to change.
2. How can I determine the intersection point of the Goodman line vs load line and display it on the graph?
3. How can I plot points along the load line and label them?
I've attached the code I've written to display the graph. Please let me know if there is anything I need to clarify. Thank you!
%coordinates for the goodman line
x1 = [Sut 0];
y1 = [0 Se];
%coordinates for the yield line
x2 = [Sy 0];
y2 = [0 Sy];
%coordinates for the load line
x3 = 0:1:200;
y3 = x3;
figure
plot(x1, y1, x2, y2, x3, y3, '--');
legend("Goodman line", "yield line", "load line");
xlabel("Mean Stress, \sigma_m");
ylabel("Alternating Stress, \sigma_a");
ylim([0 150]);
yticks([0:30:150]);
grid on;

Best Answer

Using the mrdivide,/ (link) function and some elementary algebra will produce the ‘x’ or ‘Mean Stress’ intersections:
Sut = 750; % Provide Correct Value


Se = 140; % Provide Correct Value
Sy = 450; % Provide Correct Value
%coordinates for the goodman line
x1 = [Sut 0];
y1 = [0 Se];
%coordinates for the yield line
x2 = [Sy 0];
y2 = [0 Sy];
%coordinates for the load line
x3 = 0:1:200;
y3 = x3;
Gb = y1/[x1; 1 1]; % Goodman Line Parameters
Yb = y2/[x2; 1 1]; % Yield Line Parameters
Lb = y3/[x3; ones(size(x3))]; % Load Line Parameters
GYisX = (Gb(2)-Yb(2))/(Yb(1)-Gb(1)); % Goodman - Yield ‘x’ Intersection
GLisX = (Gb(2)-Lb(2))/(Lb(1)-Gb(1)); % Goodman - Load ‘x’ Intersection
GYisY = Gb * [GYisX; 1]; % Goodman - Yield ‘y’ Intersection
GLisY = Gb * [GLisX; 1]; % Goodman - Load ‘y’ Intersection
Use those values to define the end of the line you want to plot.