How to plot This graph in matlab?
조회 수: 1 (최근 30일)
이전 댓글 표시
x=[1.0:0.1:3.0];
%Composition
%Outlet Specification [PFAD(4)]
y=-2.03^9-3*x^2)+5.76^(-3x)+1;
z=-1.11^-2*x^2+6.49^-2*x+9.99;
plot(x,y,'-b',x,z,'-r')
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend('a) FFA','b)TAG');
댓글 수: 0
채택된 답변
DGM
2023년 2월 1일
편집: DGM
2023년 2월 1일
1.00E-2 is shorthand for scientific notation 1.00*10^-2.
% define x
x = 1.0:0.05:3.0;
% YData as row vectors in a matrix
y = zeros(3,numel(x)); % preallocate
y(1,:) = -2.03E-3*x.^2 + 5.76E-3*x + 1E2;
y(2,:) = -1.11E-2*x.^2 + 6.49E-2*x + 9.99E1;
y(3,:) = -2.73E-2*x.^3 + 1.05E-1*x.^2 - 1.42E-1*x + 1E2;
% plot all y vs x
hp = plot(x,y);
% set colors using short names or direct tuples
% set line and marker styles as needed
linecolors = {'k',[0.8 0.5 0],[0.8 0.8 0]};
for k = 1:3
hp(k).Color = linecolors{k};
hp(k).Marker = 'o';
hp(k).MarkerFaceColor = linecolors{k};
hp(k).MarkerSize = 3;
end
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend(hp,{'a) FFA','b) TAG','c) something'});
Why aren't the curves in the same location? The equations in the annotations contain constants which are rounded. It's also likely that the curves are measured data and the equations are a polynomial fit, so they might not actually be identical.
댓글 수: 4
DGM
2023년 2월 1일
편집: DGM
2023년 2월 1일
To try to better approximate what the graph shows while staying within the rounded constants given:
% define x
x = 1.0:0.05:3.0;
% YData as row vectors in a matrix
y = zeros(3,numel(x)); % preallocate
% using polyval() is the same as writing a polynomial with the specified coefficients
p1 = [-2.025E-3 5.755E-3 99.996];
p2 = [-1.115E-2 6.495E-2 99.883];
p3 = [-2.728E-2 1.051E-1 -1.423E-1 100.066];
y(1,:) = polyval(p1,x);
y(2,:) = polyval(p2,x);
y(3,:) = polyval(p3,x);
% plot all y vs x
hp = plot(x,y);
% set colors using short names or direct tuples
% set linestyles as needed
linecolors = {'k',[0.8 0.5 0],[0.8 0.8 0]};
for k = 1:3
hp(k).Color = linecolors{k};
hp(k).Marker = 'o';
hp(k).MarkerFaceColor = linecolors{k};
hp(k).MarkerSize = 3;
end
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend(hp,{'a) FFA','b) TAG','c) something'});
Otherwise, you'll have to find a better source of information than a picture.
DGM
2023년 2월 1일
... or if we assume the plotted data are measured values and not the polynomial fit, we could approximate the measured values instead of trying to refine the fit.
% define x
x = 1.0:0.05:3.0;
% YData as row vectors in a matrix
S = load('y.mat');
% plot all y vs x
hp = plot(x,S.y);
% set colors using short names or direct tuples
% set line and marker styles as needed
linecolors = {'k',[0.8 0.5 0],[0.8 0.8 0]};
for k = 1:3
hp(k).Color = linecolors{k};
hp(k).Marker = 'o';
hp(k).MarkerFaceColor = linecolors{k};
hp(k).MarkerSize = 3;
end
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend(hp,{'a) FFA','b) TAG','c) something'});
Note that this is a better approximation of what the image itself shows.
추가 답변 (1개)
KSSV
2023년 2월 1일
I have shown one plot for you reference. You may extend the same to others.
x=1.0:0.1:3.0;
y=-2.03*10^-3*x.^2+5.76*10^-3*x+1*10^2 ;
plot(x,y,'-b')
title('Distillate composition vs time');
xlabel('time');
ylabel('xd');
legend('a) FFA');
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!