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 CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by