I need help on how to make the code for this problem...

 Accepted Answer

If you ask me, this is just another poorly worded assignment. If x is a 100 element linear ramp from 0 to 10, then how is it implied that the plot starts on x = 0.01? We know the properties of logarithms, but nothing in the problem statement specifies that x starts at 0.01. The first two elements of x are 0 and ~0.101. So which is it? Should the x vector start at 0.01, or should it be defined as stated?
... or is x supposed to be a linear ramp from 0 to 1 instead?
I'm bothered enough that I'm going to throw down some guesswork. You'll have to decide what's intended and edit accordingly.
% the problem statement is contradictory
% so instead do a 100-point linear ramp from 0.01 to 10
npoints = 100;
x = linspace(1/npoints,10,npoints);
y1 = exp(-0.25*x).*sin(3*x);
h1 = semilogx(x,y1,'b','linewidth',2); hold on
y2 = exp(-0.25*x).*cos(3*x);
h2 = semilogx(x,y2,'r--','linewidth',3);
grid on;
legend([h1 h2],{'the first thing','some other thing'},'location','northeast')
title('Super Important Data')
xlabel('stuff')
ylabel('things')
clf
% the problem statement is contradictory
% so instead do a 100-point linear ramp from 0 to 1
% and then discard the first point
x = linspace(0,1,100);
x = x(2:end); % this isn't really necessary, but okay
y1 = exp(-0.25*x).*sin(3*x);
h1 = semilogx(x,y1,'b','linewidth',2); hold on
y2 = exp(-0.25*x).*cos(3*x);
h2 = semilogx(x,y2,'r--','linewidth',3);
grid on;
legend([h1 h2],{'the first thing','some other thing'},'location','southwest')
title('Super Important Data')
xlabel('stuff')
ylabel('things')

More Answers (0)

Categories

Find more on Mathematics 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!