필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Sierra Bounds
Sierra Bounds 2019년 2월 26일
댓글: KSSV 2019년 2월 26일
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일
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일

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by