A. We continue our exploration of MATLAB\'s plotting facilities by considering p
ID: 3703457 • Letter: A
Question
A. We continue our exploration of MATLAB's plotting facilities by considering plots with left and right y axes. Such plots are particularly appropriate when we want two plot curves with different scales. We are given three functions to be plotted: fit) sin(rt) g(t)= 20Vt . f2(t) = cos(2nt) . e-t Submit a MATLAB script that produces the plot of Figure The key command whose documentation you want to read is yyaxis. This is a relatively new com mand. In the past this type of plots was obtained with the now-obsolescent plotyyExplanation / Answer
% create vecto for time
t = [ 0 : 0.01 : 10 ];
% vector to store f1(t)
f1 = [ 1 : length(t) ];
% vector to store f2(t)
f2 = [ 1 : length(t) ];
% vector to store g(t)
g = [ 1 : length(t) ];
for i = 1 : length(t)
f1(i) = sin( pi * t(i) );
f2(i) = cos( 2 * pi * t(i) ) * exp( -t(i) );
g(i) = 20 * sqrt( t(i) );
end
yyaxis left
% set title
title('Dual-axis plot');
ylabel('f1(t).f2(t)');
xlabel('t');
hold
% plot the graph
plot( t , f1 , 'b' , t , f2 , '--');
% for right y axis
yyaxis right
% set y label
ylabel('g(t)');
hold
% plot the graph
plot( t , g , 'r');
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.