Hey all,
I'm trying to write a general form to compute the partial sum of e^x. So far I've gotten a function that spits out the value of the nth term, but not the sum of that term and all the terms before it. (Ex, if M is 2, the computer gives me 0.5 as the output, but it should be 1+1+0.5 = 2.5 for terms n=0, n=1, and n=2.).
The problem definitely has to do with the summation line– how do I fix that? Thanks!
function y = Pset0_P5_fxn(x,M)
x = 1; M = 2;
for n = 0:M a = ((x.^n)./(factorial(n))) y = sum(a) endend end
EDIT: The function seems to work fine, but won't plot– for all x values, the y value is the same (whatever the output is on the last iteration). How can I store the output at each iteration in a vector?
Best Answer