How to plot This graph in matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
DGM
am 1 Feb. 2023
Bearbeitet: DGM
am 1 Feb. 2023
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 Kommentare
DGM
am 1 Feb. 2023
Bearbeitet: DGM
am 1 Feb. 2023
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
am 1 Feb. 2023
... 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.
Weitere Antworten (1)
KSSV
am 1 Feb. 2023
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');
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!