1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab help

  1. Mar 1, 2013 #1
    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. jcsd
  3. Mar 1, 2013 #2
    that last fprintf line i have deleted do not pay it any attention.
     
  4. Mar 4, 2013 #3
    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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Matlab help
  1. Help in Matlab (Replies: 1)

  2. Matlab HELP ! (Replies: 4)

  3. Matlab help (Replies: 2)

  4. Help with matlab (Replies: 7)

  5. MATLAB help (Replies: 2)

Loading...