Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: White needs help

  1. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: DJMrWhite
    #1

    White needs help

    So, I'm supposed to be writing a piece of MATLAB code to approximate cos to 8 sig figs. Seems easy right? It seems easy to me, but for some reason, I can't figure out why my while loop won't stop after 8 sig figs are reached. Any help/hints would be appreciated. Keep in mind that this is the first coding I've done in about 2 years.
    Code:
    clear
    
    x=.3*pi;
    
    n=2; %number of sig figs
    es=0.5*10^(2-n); %target error
    
    et=1; %actual error
    trueVal=cos(x);
    
    term(1)=1;
    counter=2;
    while (abs(et)>=es)
        counter1=(counter-1)*2;
        term(counter)=((-1)^(counter-1))*(x^counter1)/factorial(counter1);
        total=sum(term);
        et=((trueVal-total)/trueVal)*100;
        counter=counter+1;
    end
    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

  2. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: DJMrWhite
    #2

    Re: White needs help

    I also have tried to meet with the professor, but he's in a meeting right now and only meets with students by appointment. The project is due on Monday so I've got some time.
    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

  3. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: DJMrWhite
    #3

    Re: White needs help

    I also set the number of sig figs low in the above to see if it was just a long run time, but from removing the semi-colon on the counter var above, I've seen that the code is running into very high iterations.
    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

  4. Registered TeamPlayer dex71's Avatar
    Join Date
    12-28-07
    Location
    Gopher/Viking Country
    Posts
    17,455
    Post Thanks / Like
    Stat Links

    White needs help White needs help White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: dex71
    #4

    Re: White needs help

    Quote Originally Posted by DJ Mr. White View Post
    I also set the number of sig figs low in the above to see if it was just a long run time, but from removing the semi-colon on the counter var above, I've seen that the code is running into very high iterations.
    Lol....I came in, hoping I could help. I had to read that sentence twice......but I knew it was WAY over my head about half way through, the first time.

    Good luck.

  5. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: DJMrWhite
    #5

    Re: White needs help

    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

  6. Registered TeamPlayer deputyfestus's Avatar
    Join Date
    05-28-07
    Location
    East Texas
    Posts
    7,960
    Post Thanks / Like
    Blog Entries
    9
    Stat Links

    White needs help White needs help White needs help
    #6
    Last edited by deputyfestus; 12-03-10 at 04:11 PM.

  7. Registered TeamPlayer
    Join Date
    01-25-09
    Posts
    253
    Post Thanks / Like
    #7

    Re: White needs help

    I'm not entirely sure what problem your having... I ran your code with n=8 and got the following results.

    trueVal =

    0.587785252292473

    >> total

    total =

    0.587785251272005

    >> counter

    counter =

    7

    Which is accurate to 8 sig figs and only took 7-2=5 iterations. How many iterations are you getting?

  8. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: DJMrWhite
    #8

    Re: White needs help

    I have to shut down MatLab using Process Explorer to get it to stop running. I've seen it running as high as 180k iterations. I can't figure out what's up.
    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

  9. Registered TeamPlayer
    Join Date
    01-25-09
    Posts
    253
    Post Thanks / Like
    #9

    Re: White needs help

    Damn man... I'm not sure what that could be. Like I said, I ran it and it worked just fine.

    One troubleshooting technique you could try is to insert a break point at the beginning of your while loop. Then just run your script one step at a time and make sure your getting the values you expect for term/total/et during the first couple of iterations.

  10. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    White needs help White needs help White needs help White needs help
    Gamer IDs

    Steam ID: DJMrWhite
    #10

    Re: White needs help

    I'll try and try that.
    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Title