What does the >> n = 1:100; >> x = ( (-1).^(n+1) ) ./ (2*n - 1); >> y = sum(x) >>plot(x(1,1:4)) mean?

1 回表示 (過去 30 日間)
NN
NN 2023 年 10 月 8 日
コメント済み: NN 2023 年 10 月 8 日
>> n = 1:100;
>> x = ( (-1).^(n+1) ) ./ (2*n - 1);
>> y = sum(x)
>>plot(x(1,1:4))
While executing this, what is the meaning and answer of plot line (Last command)?
  1 件のコメント
John D'Errico
John D'Errico 2023 年 10 月 8 日
編集済み: John D'Errico 2023 年 10 月 8 日
Why not try it?
Even better, why not take a basic MATLAB tutorial, and learn MATLAB? It will be time well spent. After all, is there a reason why we should be writing an entire tutorial in MATLAB for you here, when it already exists?
If not, then look at one line at a time. TRY IT! If you don't know what the first line does, then you definitely need to start reading the manual.

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

採用された回答

Image Analyst
Image Analyst 2023 年 10 月 8 日
x is a row vector so it doesn't need two indexes. y is assigned but not used. The plot() plots the first 4 values from the x array (row 1, columns 1-4):
n = 1:100;
x = ( (-1).^(n+1) ) ./ (2*n - 1)
x = 1×100
1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 0.0270 -0.0256 0.0244 -0.0233 0.0222 -0.0213 0.0204 -0.0196 0.0189 -0.0182 0.0175 -0.0169
y = sum(x)
y = 0.7829
plot(x(1, 1:4), 'b.-', 'LineWidth', 2, 'MarkerSize', 40)
grid on;
title('Plot of first 4 values of x in row 1')
ylabel('x');
xlabel('Index')
To learn other fundamental concepts, invest 2 hours of your time here:
  1 件のコメント
NN
NN 2023 年 10 月 8 日
thank you .I was confused with plot function

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by