Can someone help me display the area bounded by the curve and the linear line. Pls see attached photo.
4 views (last 30 days)
Show older comments
2 Comments
John D'Errico
on 10 Mar 2024
I already showed you how to solve that problem in your last question. Thre is no need to keep on asking it over and over again.
Accepted Answer
Star Strider
on 10 Mar 2024
Edited: Star Strider
on 10 Mar 2024
One approach —
clear all;
close all
format shortG
filename = 'GT+10-ubc-X-Axis - Static.csv';
T1 = readtable(filename, 'VariableNamingRule','preserve')
% T1 = readtable('GT+10-ubc-X-Axis - Static.csv', 'VariableNamingRule','preserve')
% clear all
% filename = 'GT+10-ubc-X-Axis - Static.csv';
data1 = readmatrix(filename);
x=data1(:,1);
y=data1(:,2);
% start point
xs=0;
ys=0;
% end point
maxy=max(y)
ip= find(y ==maxy);
%ip= find(x =maxy=displacement);
dist=1
figure(4)
plot(x(1:ip+dist),y(1:ip+dist),'LineWidth',2, 'DisplayName','Non-Elastic Response')
xe=x(ip);
ye=y(ip);
yin = @(t) interp1(x(1:ip), y(1:ip), t);
ynn=yin
% Generate t values for plotting
t_values = linspace(x(1), x(ip), 200);
% Evaluate yin for each t value
y_values = yin(t_values);
% Plot the graph
%plot(t_values, y_values);
x=t_values
y=y_values
d=length(x)
ym=0
i=1
while ym<y(end)-400
%intersectingpoint
xi=x(i);
yi=y(i);
%midpoint
xm=xi/(0.6);
ym=yi/(0.6);
% Calculate slope
% Define the equation of the line
syms xx % Define x as a symbolic variable
m1 = (ym - yi) / (xm - xi);
m2=(ye-ym)/(xe-xm);
eqn2 = ym + m2*(xx - xm);
dxx=0.01;
eqn = yi + m1*(xx - xi);
domx=linspace(xi,xm,100);%
dxx=domx(2)-domx(1);
domx2=xm:dxx:xe-0.1;
curvev = yin(domx);
linev = subs(eqn,xx,domx);
dx1=domx(2)-domx(1);
curvev2 = yin(domx2);
linev2 = subs(eqn,xx,domx2);
%cld=min(abs(curvev2-linev2));
%intpo= find(abs(curvev2-linev2) ==cld);
%x3=domx2(intpo);
%y3=curvev2(intpo);
domx3=linspace(xm,xe,100);%xm:dxx:x3
curvev2 = yin(domx3);
linev2 = subs(eqn2,xx,domx3);
dx2=domx3(2)-domx3(1);
area1(i)=sum(abs(curvev-linev))*dx1;
area2(i)=sum(curvev2-linev2)*dx2;
tot_diff(i)=abs((area1(i)-area2(i)));
i=i+1;
end
cld=min(tot_diff);
minindex= find( tot_diff==cld);
figure(4)
xi=x(minindex);
yi=y(minindex);
xm=xi/(0.6);
ym=yi/(0.6);
yn = ynn(xm);
yn2=(yn/xm)*xe;
%hold on
%plot([xm,xe],[ym,yn2],'red','DisplayName','Linear Elastic Response')
xy = [x; y]; % Non-Linear Elastic Response Curve
% [b1, b2] = bounds(xy,2)
% s = [xs ys]
% m = [xm ym]
% e = [xe ye]
B_s_m = [xs 1; xm 1] \ [ys;ym] % Linear Regression
s_m_x = x(x >= xs & x <= xm);
s_m_y = [s_m_x(:) ones(size(s_m_x(:)))] * B_s_m;
B_m_e = [xm 1; xe 1] \ [ym;ye] % Linear Regression
m_e_x = x(x >= xm & x <= xe);
m_e_y = [m_e_x(:) ones(size(m_e_x(:)))] * B_m_e;
xint = x;
yc = [s_m_y; m_e_y];
dy = yc - y(:);
Lv1 = x >= xm;
y2 = y(Lv1);
Lv1 = y2(:) >= m_e_y; % Region Of 'A_2'
A_2 = trapz(x(Lv1), dy(Lv1)) % 'A_2'
cumulative_area = cumtrapz(xint, abs(dy));
Area = cumulative_area(end);
A_1 = Area - A_2
hold on
plot([xs,xm,xe],[ys,ym,ye],'red','DisplayName','Billinear Curve Fit')
hold on
plot(xs, ys, '.', 'DisplayName','ys')%, 'Marker','p', 'MarkerSize',20)
plot(xm, ym, '.', 'DisplayName','ym')%, 'Marker','p', 'MarkerSize',20)
plot(xe, ye, '.', 'DisplayName','ye')%, 'Marker','p', 'MarkerSize',20)
% hold off
%Plotting
title('Billinear Curve Fitting of Pushover Curve')
xlabel('Displacement (m)')
ylabel('Baseshear Force (kN)')
ax=gca;
ax.YAxis.Exponent = 0;
hold on
plot([0,xm],[ym,ym],'--','HandleVisibility','off')
plot([xm,xm],[0,ym],'--','HandleVisibility','off')
%plot([xe,xe],[0,yn2],'--','HandleVisibility','off')
%plot([0,xe],[yn2,yn2],'--','HandleVisibility','off')
%plot([0,xe],[ye,ye],'--','HandleVisibility','off')
text(xm+0.01, ym-200, sprintf('\\leftarrow A_1 = %.3f', A_1))
text(0.3, 6900, sprintf('\\leftarrow A_2 = %.3f', A_2), 'Rotation',-10)
% hold on
legend('Location','best')
% lgd = legend;
% lgd.NumColumns = 1;
% Display the results
disp('Values:');
disp(['y coordinate of yield point umax = ', num2str(xe)]);
disp(['x cordinate of yield point uy = ', num2str(xm)]);
disp(['y coordinate of yield point Vy = ', num2str(ym)]);
disp(['y coordinate of yield point Ve = ', num2str(yn2)]);
disp(['y coordinate of yield point Vmax = ', num2str(ye)]);
figure
yyaxis left
plot(x, y, 'DisplayName','Non-Elastic Response')
hold on
plot(s_m_x, s_m_y,'DisplayName','s - m')
plot(m_e_x, m_e_y,'DisplayName','m - e')
plot(x, dy, 'DisplayName','Curve Difference')
plot(x, abs(dy), '.', 'DisplayName','Curve Difference - Absolute Value')
xline(xm, '--k', 'xm', 'DisplayName','xm')
hold off
yyaxis right
plot(x, cumulative_area, 'DisplayName','Cumulative Area')
hold off
grid
legend('Location','southoutside', 'NumColumns',2)
title('Plots Demonstraating ''Cumulative Area'' Calculation')
To use trapz or cumtrapz you need to interpolate the lines defined by the three points and then subtract them from the curve. The linear regressions do that here. Since I am not certain how you want to calculate the ares, I provided both the difference and the absolute value of the difference between the olines and the curve, and did the integration on the absolute value. Change that if necessary.
It took a bit of time to figure out how your code works. My apologies for the delay.
EDIT — (10 Mar 2024 at 04:28)
Added specific and calculations.
EDIT — (10 Mar 2024 at 04:45)
Added text objects for and .
.
2 Comments
Star Strider
on 10 Mar 2024
That looks like different data.
A couple text calls are all that would be necessary for that. I will add them to my original code. Check it in about five minutes.
More Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!