Computer Science Questoins

Discussion in 'Programming/Html' started by Ieldra, Feb 27, 2010.

  1. Ieldra

    Ieldra Banned

    Messages:
    3,490
    Likes Received:
    0
    GPU:
    GTX 980Ti G1 1500/8000
    Hey guys, whats up?
    I'm ieldra's friend and I need help with the following question (I'm in first year of college btw.):

    FLOWCHARTS

    Given the equation: z = 3x2 – 2xy + y3, with the following constraints:
    -3 <= x <= 5 and -2 <= y <=4.
    Print the largest value of z and the corresponding values of x and y, taking into consideration that Δx = 0.1 and Δy = 0.2. (Draw a flowchart for this)
     
    Last edited: Feb 27, 2010
  2. PuddingWagon

    PuddingWagon Maha Guru

    Messages:
    1,087
    Likes Received:
    0
    GPU:
    Gigabyte GTX 670
    You have to check each value of z for the values of x and y within the given domain, using the Δx and Δy given.

    i.e.
    (get a value of x, then use all the values of y)
    z when x = -3, y = -2
    z when x = -3, y = -1.98
    ...
    (get the next value of x, then use all the values of y again)
    z when x = -2.99, y = -2
    z when x = -2.99, y = -1.98
    ...
    z when x = 5, y = -2
    z when x = 5, y = -1.98
    ....
    z when x = 5, y = 3.98
    z when x = 5, y = 4
    (until you finish x and y)
    You need to compare the newly calculated value of z to the previous maximum value of z and update if required.

    In pseudo code, some parts deliberately vague.
    Code:
    //initial conditions, we need an initial 'lowest' value of z to compare to
    //I've chosen when x = -3 and y = -2
    zMax = (z when x = -3, y = -2)
    xValAtZMax = -3
    yValAtZMax = -2
    
    for (xLoop = -3 to 5 (inclusive), incrementing by 0.1)
    {
      for (yLoop = -2 to 4 (inclusive), incrementing by 0.2)
      {
         //calculate the 'current' value of z (using 'xLoop' and 'yLoop')
    
         //compare the 'current z' to 'zMax'
             //If larger than, then we have a new zMax, xValAtZMax and yValAtZMax
             //otherwise move on
      }
    }
    
    [I]output [/I]zMax, xValAtZMax, yValAtZMax //end
    Ideally you would have a few more constants in there (xMin, xMax, xInc, yMin... etc) so there aren't any magic numbers, even in the flowchart. You could also skip when x = -3 and y = -2 since you already have that z value.


    I'm probably cheating a bit by going to code then converting to a flowchart, but I think better like this.
     
    Last edited: Feb 27, 2010
  3. Anubis

    Anubis Ancient Guru

    Messages:
    2,788
    Likes Received:
    0
    GPU:
    Gigabyte GTX 760 4GB
    Jesus Christ!!

    I've only understood this so far:

    Good luck on solving this m8 :p
     
  4. BBN

    BBN Master Guru

    Messages:
    603
    Likes Received:
    0
    GPU:
    Vapor-X 7950 3 Way Xfire
    brain f#$k
     

  5. Tat3

    Tat3 Ancient Guru

    Messages:
    11,842
    Likes Received:
    225
    GPU:
    GB GTX 1660 Ti OC
    Making code works with small programs, but you need some basic idea how to do that before start typing... Perhaps if you do simple functions and just name those and tell what those are supposed to do (include zero code), then it's easier to start making flowchart from it.

    Anyways, I dont know what kind of flowcharts you are supposed to make, can those include any code or just the basic idea how those are supposed to work ? Are you going to use that flowchart to convert it to code using some code generator (Insoft Prosa for exmaple) or just leave it to flowchart level. Are you supposed to include variables there or not ?

    What program are you going to use ? Microsoft Office Viso 2007 or just pencil and paper ?
     
  6. lmimmfn

    lmimmfn Ancient Guru

    Messages:
    10,474
    Likes Received:
    165
    GPU:
    AorusXtreme 1080Ti
    result is Max value for z=43.0, x=4.9 , y=-2.0

    haha( i couldnt resist running it )
     
  7. TroM

    TroM Ancient Guru

    Messages:
    1,921
    Likes Received:
    0
    GPU:
    Gigabyte HD6850 OC
    I was bored so I wrote a Java program that solves that equation for any value of x and y. Also tells you if x and y are within the constraints. :p

    I'm not leet enough to do the max value thing though, if anyone want to mess with the code below please do so cause I'm curious.

    You can crash it easily, just try to enter any character A-Z lol.
     
    Last edited: Feb 28, 2010
  8. lmimmfn

    lmimmfn Ancient Guru

    Messages:
    10,474
    Likes Received:
    165
    GPU:
    AorusXtreme 1080Ti
    er thats not whats needed it should calculate it itself

    This is whats needed :p, i got bored too and as i was editing a work junit test i just added another( note tabs dont show )

     
  9. Cybermancer

    Cybermancer Don Quixote

    Messages:
    13,795
    Likes Received:
    0
    GPU:
    BFG GTX260OC (192 SP)
  10. F1refly

    F1refly Ancient Guru

    Messages:
    9,042
    Likes Received:
    0
    GPU:
    970GTX-oc edition

Share This Page