How do I store data to plot it from a summation?

I want to be able to store the data for each new term that is generated and plot it. with k/b to be the x axis and term results on the y axis. I am not sure how to do this.

2 件のコメント

madhan ravi
madhan ravi 2019 年 2 月 26 日
編集済み: madhan ravi 2019 年 2 月 26 日
people can’t run images upload your code
Sierra Bounds
Sierra Bounds 2019 年 2 月 26 日
function cosx = mycos(a,b)
k = 0;
term = 0;
%term = zeros(1,121);
while k < b %IDK about infinity...
k2 = 2*k;
top = (((-1)^k) * (a^k2));
bot = factorial(k2);
term = term + (top / bot);
k = k + 1;
end
cosx = term;
end

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

回答 (1 件)

KSSV
KSSV 2019 年 2 月 26 日

0 投票

function cosx = mycos(a,b)
k = 0;
term = 0;
%term = zeros(1,121);
x = zeros([],1) ;
y = zeros([],1) ;
while k < b %IDK about infinity...
k2 = 2*k;
top = (((-1)^k) * (a^k2));
bot = factorial(k2);
term = term + (top / bot);
k = k + 1;
x(k) = k/b ;
y(k) =term ;
end
cosx = term;
plot(x,y,'.r')
end

2 件のコメント

Sierra Bounds
Sierra Bounds 2019 年 2 月 26 日
Is there a way to do it with lines, instead of dots?
KSSV
KSSV 2019 年 2 月 26 日
plot(x,y,'r')

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

カテゴリ

ヘルプ センター および File ExchangeView and Analyze Simulation Results についてさらに検索

質問済み:

2019 年 2 月 26 日

コメント済み:

2019 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by