Thread: Noob Question....Any help appreciated

  1. #16
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    The solution you're likely to do is probably going to work regardless of what function you're given, and if it isn't, changing it to do that is a one liner. So what I don't understand is why not go straight to that.

    In fact, learning to do it for any function would teach you a lesson about abstraction, a very important concept in computer science.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  2. #17
    Registered User RandomX's Avatar
    Join Date
    Nov 2006
    Posts
    19
    Quote Originally Posted by Happy_Reaper
    The solution you're likely to do is probably going to work regardless of what function you're given, and if it isn't, changing it to do that is a one liner. So what I don't understand is why not go straight to that.

    In fact, learning to do it for any function would teach you a lesson about abstraction, a very important concept in computer science.

    I am just curious what the coding would look like for a derivative. I think Im just gonna do it using the max/min formula.

  3. #18
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    What I was talking about didn't use the derivative whatsoever.

    However, it you actually wanted to use the derivatives for this problem, there are 2 ways I know of doing this.

    1) Calculating it by coding up symbology and chain rules and polys etc (this can be quite a hassle...)

    2) Approximate it using the midpoint approximation (which is the most accurate.) :
    f'(x) = (f(x - h) + f(x + h))/(2h) where h is small.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  4. #19
    Registered User RandomX's Avatar
    Join Date
    Nov 2006
    Posts
    19
    ok... well what conclusion can we come to about which will be the easiest...

    using the min/max formula?

    or

    doing the sequence structure like we originally mentioned.

  5. #20
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Ideally, execute the pseudo-code posted by manutd.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #21
    Registered User RandomX's Avatar
    Join Date
    Nov 2006
    Posts
    19
    well im gonna get started on this in the morning.... ill ask u guys more if i come across any more issues, which i might when i get to the little man source to binary conversion.

    again, im a programming beginner... so take it easy on me.
    Last edited by RandomX; 11-20-2006 at 11:15 PM.

  7. #22
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    It looks like you have a very intelligent community here.
    kurr...zu-wakaiinoo, grunt?


    The solution you're likely to do is probably going to work regardless of what function you're given,
    Wrong. the function has to be continuous.

    If you want to impress your lecturer (NB: this is not always the best thing to do with some lecturers, even if you're capable of it), try the Newton-Raphson iteration. I'm no calculus major, but you can use N-R to find maximums and minimums of a relatively smooth function by solving its derivative. Of course your function must be smooth enough so you can differentiate its derivative.

    If you're lazy, you can just make the computer do it for you through brute force: check every interval [n, n+0.1] and find the lowest interval, then search [n, n+0.01] in that interval, and so on, until you reach, sa, 9 digits or so. It's less reliable, may fail to find solutions for pathological functions and can get stuck in local minima, but it's a pretty good way of going about things.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  8. #23
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Quote Originally Posted by jafet
    Wrong. the function has to be continuous.
    Actually, I was referring to the solution suggested by manutd. But to jafet's credit, that solutiong only works if the function is defined at the points at which you evaluate it. This does not necessarily imply continuity, but it is definitely worth noting.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  9. #24
    Registered User RandomX's Avatar
    Join Date
    Nov 2006
    Posts
    19
    Quote Originally Posted by jafet
    If you want to impress your lecturer try the Newton-Raphson iteration. I'm no calculus major, but you can use N-R to find maximums and minimums of a relatively smooth function by solving its derivative. Of course your function must be smooth enough so you can differentiate its derivative.
    If I did Newtons method, I would first have to find X0. But in Newtons method, you find X0 but making an "initial guess". There cant possibly be a way to have the program make the initial guess, could there? I suppose the initial guess is just a linear approximation (tangent line), so if i could find the tangent line of a function, then i would be able to do Newtons method......I think.

  10. #25
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Again, I think you're making this loads more complicated then it needs to be. But if you're really looking to go ahead and write a PHD thesis for this one problem, here's a link that will give you pretty much all you need to know about Newton-Raphson.

    Further, your problem implies finding the 0 of your derivative. So you'd have to calculate the derivative (or a functional approximation) of your function. Then your initial guess can be anything you really want (save some specific values), preferably near the 0 that you're calculating, though.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  11. #26
    Registered User RandomX's Avatar
    Join Date
    Nov 2006
    Posts
    19
    Well Ive been posting this stuff on two different forums talking about the derivative stuff.... both places have told me to not make it so complicated, and I dont know why I was so persistent on it.

    My apologies to everyone if I came off rude or anything. I appreciate your help with all of this.

    Im just gonna do it the easy way, like we originally talked about.

  12. #27
    Registered User
    Join Date
    Nov 2006
    Posts
    19

    keep in mind the underlying mathematics

    I guess your program will be largely affected by how advanced the mathematics that you use are. Using derivatives you can find out wether a function's value is increasing or decreasing (any continuos differentiable polinomial is easy to differentiate) on a certain range. Otherwise you can use algebra and stick to discrete values (what if the minimum or maximum for another function is at x = 3.2). Mathematics are often ignored by us, programming students, but they just keep coming back to bite us. The method you use will be extremely simple if you stick to one equation and to whole-number values, and rather difficult (and interesting) if you consider variable ranges, continuos values and equations of varying degree. To work with polynomials you can always start working with classes in C++ or or Java to represent a term like

    2 * x ^ 3

    as one single object. I hope your programming goes well, good luck! By the way, if you think processing the data is hard, just wait until you try to design a nice, user-friendly interface , have fun!

  13. #28
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    To be honest, you didn't come off as rude. You just seemed bent on making things complicated.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  14. #29
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Yeah, which is not bad as a learning exercise, but
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  15. #30
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    If you don't want to use N-R, you could try the second method I pointed out. It's far less complicated and can usually produce similar results with most "normal" functions. The hard part comes in selecting the initial interval. I'm guesstimating a reliable initial interval for polynomials to be (degree of polynomial * leading coefficient)^-1.

    Damn, I feel pretty bad for participating in this discussion, I think I'm seriously pulling you off track But it's good intellectual stimulation, and I think I've learnt a thing or two here.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 01:28 PM
  2. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM
  3. Noob question (redeclaring a array)
    By Demon.killer in forum C Programming
    Replies: 8
    Last Post: 10-21-2006, 12:06 PM
  4. Noob question - Implementing INI Parsing class
    By Highland Laddie in forum C++ Programming
    Replies: 2
    Last Post: 07-04-2005, 05:47 PM
  5. Replies: 5
    Last Post: 11-01-2002, 06:09 PM