How to implement a for loop for a equation and plot the values on a graph?

1 回表示 (過去 30 日間)
Prayash Thapa
Prayash Thapa 2020 年 11 月 4 日
回答済み: David Hill 2020 年 11 月 4 日
How can I correct the array values of 'fncT' when t becomes bigger than 19, the answers become incorrect for some reason. What is wrong with this and how can I solve this? I want a repeating set of answers up to 100 values. Also how can I possible put this in a for loop and plot the values on the graph?
This is the code:
A = 7;
P = 100;
M = 15;
t = 1:1:P
fncT = (A.^t) - floor(A.^t/M)*M; % Alternative to mod() function
plot(t,fncT)

採用された回答

David Hill
David Hill 2020 年 11 月 4 日
Need to use symbolics because 7^100 is too big.
A = sym(7);
P = 100;
M = 15;
t = 1:1:P
fncT = double((A.^t) - floor(A.^t/M)*M);
plot(t,fncT)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by