# Homework Help: Matlab help

1. Mar 1, 2013

### whynot314

I have everything correct, that is when I put in a value for n=10 I get the right results however I want to enter in more than one number at a time to give me three different results like a vector like [ 10 20 30] but I am just clueless as to how to go about this. the dots are there because i thought if i did that it might treat it the input as vector but i guess not I am stuck.I've tried using array addressing such as n(1,:) took me forever to get this far i just cant get past this bump. please help.

n=input('Enter the number of terms as a vector:');
l=0;
s=pi;
for k=0:1:n
l=l+sqrt(12)*(((-3).^(-k))./(2*k+1));
a=l;
j=abs(s-a);

end
fprintf('\n the diffrence between the series and pi is:%i\n\n',j)
fprintf('\n the diffrence: %g\n\n',j)
Report Post Edit/Delete Message

2. Mar 1, 2013

### whynot314

that last fprintf line i have deleted do not pay it any attention.

3. Mar 4, 2013

### peterpiper

Isn't a nested loop necessary here? Your outer loop would iterate over your input vector while the inner loop gives you your operation results for each entry in n. Just save your results to a multidimensional array and it should all work, right?

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted