How do I store data to plot it from a summation?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205894/image.png)
2 Commenti
madhan ravi
il 26 Feb 2019
Modificato: madhan ravi
il 26 Feb 2019
people can’t run images upload your code
Risposte (1)
KSSV
il 26 Feb 2019
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 Commenti
Vedere anche
Categorie
Scopri di più su Scatter Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!