Matlab Help - Taylor Series
I am studying and I cannot figure out how to do this practice problem... Can ANYONE help me please! Thanks!
The function 1/(1-x) can be approximated using a specific type of Taylor Series as follows:
1/(1-x)≈Σ(where n=0, and k=∞)=x^0+x^1+x^2+x^3....
Write a program to calculate the series approximation using a "for" loop running from 1 to k. Also, calculate the correct value. Test the code for k=5 & K=10 with x=0.5.
Thanks a lot, I've been working on this for a while, and don't usually get stuck with programming, I just haven't learned the "for" loop too well yet.
The function 1/(1-x) can be approximated using a specific type of Taylor Series as follows:
1/(1-x)≈Σ(where n=0, and k=∞)=x^0+x^1+x^2+x^3....
Write a program to calculate the series approximation using a "for" loop running from 1 to k. Also, calculate the correct value. Test the code for k=5 & K=10 with x=0.5.
Thanks a lot, I've been working on this for a while, and don't usually get stuck with programming, I just haven't learned the "for" loop too well yet.
0
Comments
k=5
x=0.5
k=10
x=0.5
for n = 0:k
x(n) = x(n-1) + x^n
end
matlab uses 1-based indexing, so the first element of the array is x(1).
i'd do something like this:
THANKS!! I think I got it!
My friend and I have one more we can't figure out, if you are willing to help. I'll give you the problem, original code template, and what I have so far.
What I have thus far: Let me know if you can help. Thanks a million!!
% for_sines.m
% yourname and lab section
fprintf('\n Gretchen Paden, Th 3:00-5:00 \n');
% initialize t and sine to zeros
t=zeros(1,251);
sine=zeros(3,length(t));
% sin_t(1,:) = sin(2*pi*f(1).*t)
% t = 0:.01:2.5
% f = 6:2:10
% initialize f to its proper values using a "for" loop
for i = 6:2:10
f = i
end
% initialize t to its proper values using a "for" loop
for ii = 0:.01:2.5
t = ii
end
% calculate the sine and plot using a "for" loop
%you should do this in 2 steps. first calculate the sin values, and then plot.
%you'll need to loop over f and t.
figure;
for ii
y(ii,:)=sin(2*pi*f(ii).*t);
subplot(3,1,ii)
plot(x,y(1,:),'k');
ylabel('y');
xlabel('x');
title('Frequency');
grid on
end
2) if you post your code inside [php] [/php] it'll look nicer
Error: ??? Index exceeds matrix dimensions.
And the plot is blank
your loops aren't doing what you think they're doing. you might want to try stepping through them (mentally, on paper, or using matlab debug if you know how) and see if they're actually working...