フィルターのクリア

how to plot the equation

1 回表示 (過去 30 日間)
shiv gaur
shiv gaur 2022 年 2 月 21 日
コメント済み: Image Analyst 2022 年 2 月 21 日
x(0)=1;
y(0)=0
t=1:15;
for n=1:15
x(n+1)=(x(n-1)-y(n))/n+1;
y(n+1)=(x(n)+y(n)-t)/n+1
plot(t,x)
end
  2 件のコメント
shiv gaur
shiv gaur 2022 年 2 月 21 日
x(0) is the initial value you take as x0
Image Analyst
Image Analyst 2022 年 2 月 21 日
Yeah, I figured that, but what I meant by my answer below is you're supposed to do
x(1) = 1;
y(1) = 0;

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

採用された回答

Image Analyst
Image Analyst 2022 年 2 月 21 日
編集済み: Image Analyst 2022 年 2 月 21 日
Indexing starts at 1, not 0. Also, check your formulas - they look weird.
For example in
y(n+1)=(x(n)+y(n)-t)/n+1
you need t(n), not just t which is the entire array.
y(n+1)=(x(n)+y(n)-t(n))/n+1
  4 件のコメント
shiv gaur
shiv gaur 2022 年 2 月 21 日
it is
Image Analyst
Image Analyst 2022 年 2 月 21 日
OK, so it's all working now that you're starting your vectors at index 1 instead of 0, and changed t to t(n)? If so, can you accept this answer because I pointed out the problems? If not, post your current code so we can continue to work on it. This is what I got. Let me know if it's the same as what you have.
x = zeros(1, 16);
y = zeros(1, 16);
x(1)=1;
% y(1)=0
t=1:15;
for n = 2: length(x) - 1
fprintf('n = %d.\n', n);
x(n+1) = (x(n-1)-y(n)) / n + 1; % Note only n is in the denominator, not (n+1)
y(n+1) = (x(n)+y(n)-t(n)) / n + 1;
end
n = 2. n = 3. n = 4. n = 5. n = 6. n = 7. n = 8. n = 9. n = 10. n = 11. n = 12. n = 13. n = 14. n = 15.
plot(t, x(1:end-1), 'b.-', 'LineWidth', 2, 'MarkerSize', 30);
hold on;
plot(t, y(1:end-1), 'r.-', 'LineWidth', 2, 'MarkerSize', 30);
grid on;
xlabel('t', 'FontSize', 20);
ylabel('x or y', 'FontSize', 20);
title('x or y VS. t', 'FontSize', 20);
legend('x', 'y')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by