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');

采纳的回答

DGM
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'});
If you want to add equations to the plot, you can use annotation()
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
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
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
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 CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by