Fitting a line of best fit on a plot only between a restricted domain.

2 ビュー (過去 30 日間)
Bodhi Ruffels
Bodhi Ruffels 2022 年 8 月 10 日
編集済み: Matt J 2022 年 8 月 10 日
I have gathered data from a experiment and wish to put a line of best fit on a plot that is similar to that of an logarithmic curve. My code plots a stress strain curve shown below, and I need the gradient of the linear potion of the line which is equal to Young Modulus. Instead of just guessing the gradient I wanted to try put a line of best fit (with its equation) considering only the data between x values from [-2,0]. Can this be done? My code is as follows:
%% Insert and plot data
clc
clear
clearvars
Steel1020 = readmatrix('Excelsteeldata.txt');
Time = Steel1020(:,1); %Selects column 1 of file: in Seconds
Force = Steel1020(:,2).*1000; %Selects column 2 of files converts kN=N
Elongation = Steel1020(:,3); %Selects column 3 of files in mm
%% FIGURES
figure(1)
plot(Elongation, Force)
title("Load-Extension Curve for 1020 Carbon Steel")
xlabel("Force(N)")
ylabel("Elongation (mm)")
Stress = Force / (pi.*((0.5.*10.023)^2)); %since stress = force/crosss sectional area
Strain = Elongation / 50; % since strain = elongation / inital length
figure(2)
plot(Strain, Stress)
title("Stress-Strain Curve for 1020 Carbon Steel")
xlabel("Strain (%)")
ylabel("Stress (MPa)")

回答 (1 件)

Matt J
Matt J 2022 年 8 月 10 日
編集済み: Matt J 2022 年 8 月 10 日
You can do it interactively with the brush tool and basic fitting menu options on the figure toolbar.
Or, programmatically, you could use polyfit()
region=-2<=Strain & Strain<=2;
p=polyfit(Strain(region), Stress(region),1);
fun=@(x) polyval(p,x);
hold on;
plot(Strain,Stress,Strain,fun(Strain));

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by