I am trying to store data for a variable in a for loop and then plot it against something else. I am guessing that the variable is getting overwritten, but can not seem to work a way to do this out. Here is the code:
clcclear allx=(-4:.1:4)y=5*exp(x)N=input('What value for n?')b=0*yfor n=1:N b(n) = b + 5*(x.^n)/factorial(n)ende=abs(100*(y-b)/y)figure(2)plot (x,e)figure(3)plot (x,y, 'r-o')hold onplot (x,b)
I added the subscript to the variable b as a way to store it, but I get errors about matrix sizes not matching. Is someone able to point out what is wrong or another solution to the problem?
Best Answer