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

1 件のコメント

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 9 月 30 日
It is a homework assignment. Please show your attempts what you have done so far.

サインインしてコメントする。

 採用された回答

DGM
DGM 2021 年 9 月 30 日
編集済み: DGM 2021 年 9 月 30 日

0 投票

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by