Tangent line on a curve. From a peak down the "unload curve" (in each case the bottom curve)

1 Ansicht (letzte 30 Tage)
Hi guys :)
I'm pretty confused how i can plot tanget lines onto my 3 curves.
my current plot looks like this:
Now i want to insert 3 tangent lines each starting at the 3 peaks and going down the bottom curves. Should look like this (cause i need the values "h_c"):
THANKS a lot for your help!!!
Current Code:
A_04 = readmatrix("AlCrMoN_04.xlsx"); % Excelfile consist of 2 columns with 41 rows
ersteSpalte04 = [A_04(:,1)];
zweiteSpalte04 = [A_04(:,2)];
A_13 = readmatrix("AlCrMoN_13.xlsx"); % Excelfile consist of 2 columns with 41 rows
ersteSpalte13 = [A_13(:,1)];
zweiteSpalte13 = [A_13(:,2)];
A_29 = readmatrix("AlCrMoN_29.xlsx"); % Excelfile consist of 2 columns with 41 rows
ersteSpalte29 = [A_29(:,1)];
zweiteSpalte29 = [A_29(:,2)];
%% Plots
figure("Name","load displacement");
hold on
grid on
plot(ersteSpalte04,zweiteSpalte04,"LineWidth",1.5,"DisplayName","AlCrMoN 04");
plot(ersteSpalte13,zweiteSpalte13,"LineWidth",1.5,"DisplayName","AlCrMoN 13");
plot(ersteSpalte29,zweiteSpalte29,"LineWidth",1.5,"DisplayName","AlCrMoN 29");
xlim([0 0.23])
xlabel("Eindringtiefe (ht) in µm"); ylabel("Kraft (P) in mN");
legend("show", "Location", "northwest");
hold off

Akzeptierte Antwort

chicken vector
chicken vector am 16 Jan. 2024
Bearbeitet: chicken vector am 16 Jan. 2024
The approach is to find the index of the maximum point in the curve:
[~,idx] = max(yData{j});
Then we can compute the derivative from that point until the end of the data, such that we perform the evluation on a continous curve:
dydt = gradient(yData{j}(idx:end))./gradient(xData{j}(idx:end));
Or:
dydt = diff(yData{j}(idx:end))./diff(xData{j}(idx:end));
% In general I suggest you to use "gradient", but for the derivative
% on the first point using "diff" makes no difference.
Finally we can find the intersection with the X axis as follows:
hC(j) = -yData{j}(idx)/dydt(1) + xData{j}(idx);
If you like to keep graphics code seprated from computational code:
material = "AlCrMoN";
IDs = {"04","13","29"};
N = length(IDs);
xData = cell(N,1);
yData = cell(N,1);
hC = zeros(N,1);
for j = 1 : N
data = readmatrix(material + "_" + IDs{j} + ".xlsx");
xData{j} = data(:,1);
yData{j} = data(:,2);
[~,idx] = max(yData{j});
dydt = gradient(yData{j}(idx:end))./gradient(xData{j}(idx:end));
hC(j) = -yData{j}(idx)/dydt(1) + xData{j}(idx);
end
figure("Name","load displacement");
hold on;
for j = 1 : N
plot(xData{j}, yData{j}, "LineWidth",1.5, "DisplayName", material + " " + IDs{j});
plot([hC(j) xData{j}(idx)],[0 yData{j}(idx)],'k', "HandleVisibility", "Off");
end
hold off;
grid on;
xlim([0 0.23])
xlabel("Eindringtiefe (ht) in µm");
ylabel("Kraft (P) in mN");
legend("Show", "Location", "NorthWest");
  2 Kommentare
chicken vector
chicken vector am 16 Jan. 2024
Bearbeitet: chicken vector am 16 Jan. 2024
Shorter version:
material = "AlCrMoN";
IDs = {"04","13","29"};
N = length(IDs);
figure("Name","load displacement");
hold on;
for j = 1 : N
data = readmatrix(material + "_" + IDs{j} + ".xlsx");
xData = data(:,1);
yData = data(:,2);
[~,idx] = max(yData);
dydt = gradient(yData(idx:end))./gradient(xData(idx:end));
hC = -yData(idx)/dydt(1) + xData(idx);
plot(xData, yData, "LineWidth",1.5, "DisplayName", material + " " + IDs{j});
plot([hC xData(idx)],[0 yData(idx)],'k', "HandleVisibility", "Off");
end
hold off;
grid on;
xlim([0 0.23])
xlabel("Eindringtiefe (ht) in µm");
ylabel("Kraft (P) in mN");
legend("Show", "Location", "NorthWest");

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by