As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

ECE/CS majors... does this make sense to you?

coryjcoryj Registered User regular
edited August 2007 in Help / Advice Forum
Just want to make clear that I am not asking for someone to do this assignment for me, but I am at a loss for where to even start. I have emailed the TA and he has been less than helpful, and my friends in the class are more confused than I am. This is the project that was assigned for our final project in "Programming for Engineers." Essentially, its a high school level JAVA course (which I was breezing through), but then they dumped this assignment out of nowhere to, I suppose, emphasize the "for engineers" aspect of the course name. Ignore the dates on the paper, as they are not accurate.

I am assuming some kind of code needs to be written to automate the "solve 100 equations part", but even most of this terminology was not discussed in class at all. I am relieved I had a pretty good understanding of JAVA before this class, because the people who didn't are really struggling.

I can answer more questions if they arise, but I am really wondering at this point what I even am being asked to do here.

http://img514.imageshack.us/img514/2885/programmingprojectoa4.jpg

I know there are a lot of people here who are a lot more knowledgeable than I am, so maybe this will seem incredibly easy to you and I am just missing it.

Thanks.

coryj on

Posts

  • Options
    LewishamLewisham Registered User regular
    edited August 2007
    Well, it's not easy, but doable. Presuming you are right about having a Java program create and solve the equations, you're still stuck when it comes to the graph.

    Generating a graph is no easy thing; you'd need some libraries. It sounds like it would be easier to do in Excel.

    There isn't enough in that question sheet to give any real guidance to an impartial observer as to what has to be done. You'll need to ask your professor or TA and tell them it's pretty useless in the state it's been written.

    EDIT: So I think what it's asking you is to have 100 elements, and inside each element you can work out a value based on the value before and the value after. However, I don't know what h is, and I presume you're going to know what a Gaussian iteration is (I don't!). I expect you loop through all the elements with a Gaussian iteration and the values will all settle, as they all seem to depend on each other. Then generate a graph of the values.

    It's more of an engineering question than a CS one, it's a pretty simple CS problem, not a lot of code there. It's the graphing part that's difficult.

    Lewisham on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    Lewisham wrote: »
    Well, it's not easy, but doable. Presuming you are right about having a Java program create and solve the equations, you're still stuck when it comes to the graph.

    Generating a graph is no easy thing; you'd need some libraries. It sounds like it would be easier to do in Excel.

    There isn't enough in that question sheet to give any real guidance to an impartial observer as to what has to be done. You'll need to ask your professor or TA and tell them it's pretty useless in the state it's been written.

    As for the graph, I was planning to have the program just spit out the values and just put them into excel, as you said.

    As for no real guidance... thats how the whole course has been. When I got this in my email, I had to verify the sender was actually a professor of a course I am enrolled in.

    coryj on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    h is 1 centimeter

    I'm not sure but I think that the formula they gave you at the bottom is misleading

    I believe that = 1 should be = X where X is the node position ranging 1-100

    So your task is to solve for A where h = 1cm and X = 1-100

    Right? Someone tell me if I am crazy or not.

    Jasconius on
  • Options
    LewishamLewisham Registered User regular
    edited August 2007
    Jasconius wrote: »
    h is 1 centimeter

    D'oh.

    Yeah, X 1-100 sounds right. I should have really looked at the graph more...

    Lewisham on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    Jasconius wrote: »
    h is 1 centimeter

    I'm not sure but I think that the formula they gave you at the bottom is misleading

    I believe that = 1 should be = X where X is the node position ranging 1-100

    So your task is to solve for A where h = 1cm and X = 1-100

    Right? Someone tell me if I am crazy or not.

    I figured out the h thing pretty quickly (one of the only things that readily made sense)... I think you may be on to something with the X=1-100 thing... it makes a lot of sense. I will email and ask if that is the case. I am starting to see what needs to happen, but not enough yet to start on this ;-)


    Now to figure out how exactly to solve for "A"...

    EDIT: I think I am starting to get it.. thanks for the help you two, feel free to contribute further, I asked about the X=1-100 to clarify with the TA just to make sure.

    coryj on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    Hmmm... the TA told me the =1 remains the same for each node.

    coryj on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    In that case, I don't really see where the formula works.

    If X is irrelevant to the equation, then A shouldn't change because h is a constant....

    Unless X is related to whatever the hell Gaussian iterations are, but that should have been give to you with the assignment.

    Jasconius on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    There's 3 values of A, though A1, A2 and A0. It specifies in there which is which... though I do see what you're saying, won't they all be the same??? This class/project sucks. I am pretty sure they are supposed to be an exponential decay (when plotted 1-100)

    coryj on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    Right, if h is a constant, which it is, and the equation is balanced by = 1, then A can only be a single value.

    I think your TA is dumb.

    You can solve for A, but how the hell can you make a graph out of it, lol.

    Just draw 100 dots on the same point in the grid and hand it in. Because that's basically what your TA just told you.

    Jasconius on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    Jasconius wrote: »
    Right, if h is a constant, which it is, and the equation is balanced by = 1, then A can only be a single value.

    I think your TA is dumb.

    You can solve for A, but how the hell can you make a graph out of it, lol.

    Just draw 100 dots on the same point in the grid and hand it in. Because that's basically what your TA just told you.

    I'd love to "show him" but its 10% of the total grade regardless of how dumb he is :xD:

    coryj on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    Well, ask him what Gaussian iterations are... that may be the missing link...

    Jasconius on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    They sent out an email about Gaussians... I don't really know what it is. Heres the unformatted, very poorly commented code they sent, if you don't want to try to make sense of it, I won't hold it against you at all
    import java.util.*;
    
    public class Cholesky {
       
    public static void main(String[] args)
    {
        int i, j, k, n; 
        double Sum;
        n = 3;
        double [][] A = new double [3] [3];
        A[0][0] = 4; A[0][1] = 2; A[0][2] = -2;
        A[1][0] = 2; A[1][1] = 5; A[1][2] = -1;
      A[2][0] = -2; A[2][1] = -1; A[2][2] = 10;
        double [] B = new double [3];
      B[0] = 6; B[1] = 11; B[2] = 6;
        double [] X = new double [3];
      double [] Z = new double [3];
     X[0] = 0.0; X[1] = 0.0; X[2] = 0.0;
      A[0][0] = Math.sqrt(A[0][0]);
      //A[i,j] to be computed from row 2 i.e., i = 1
      for (i=1; i<=n-1; i++)
      {
       //doing j=0
       A[i][0] = A[i][0]/A[0][0];
       if (i>=2)
       {
         for (j=1; j<=i-1; j++)
         {
          Sum = A[i][j];
          for (k=0; k<=j-1; k++)
          {
           Sum = Sum - A[i][k]*A[j][k];
          } 
           A[i][j] = Sum/A[j][j];
       }
        Sum = A[i][i];
       for (k=0; k<=i-1; k++)
        Sum = Sum - A[i][k]*A[i][k];
       A[i][i] = Math.sqrt(Sum);
        }
        else
         A[1][1] = Math.sqrt(A[1][1] - A[1][0]*A[1][0]);
     }
      System.out.println("A Row 0 = "     +A[0][0]);
      System.out.println("A Row 1 = "     +A[1][0] +"   " + A[1][1]);
      System.out.println("A Row 2 = "     +A[2][0] +"   " + A[2][1] +"   " +A[2][2]);
     Z[0] = B[0]/A[0][0];
     //Begin forward elimination
     for (i=1; i<=n-1; i++)
     {
      Sum = B[i];
      for (j=0;j<=i-1;j++)
       Sum = Sum - A[i][j]*Z[j];
      Z[i] = Sum/A[i][i];
     }
     //Begin back-substitution
     X[n-1]=Z[n-1]/A[n-1][n-1];
     for (i = n-2; i>=0;i--)
     {
      Sum = Z[i];
      for (j = i+1; j<=n-1; j++)
       Sum = Sum-A[j][i]*X[j];
      X[i] = Sum/A[i][i];  
     }
     for (i = 0; i<=n-1; i++)
      System.out.print("X[" +i +"] = " +X[i] +"   ");
     System.out.println();
     
     //The same problem is aolved now by Gaussian Iterations
     //A needs to be reset since we over-wrote L on A
     A[0][0] = 4; A[0][1] = 2; A[0][2] = -2;
        A[1][0] = 2; A[1][1] = 5; A[1][2] = -1;
      A[2][0] = -2; A[2][1] = -1; A[2][2] = 10;
      //Begin initialization -- guess values.
     for (i=0; i<=n-1; i++)
      X[i] = B[i]/A[i][i];
     int iter;
     double errorX, maxX, errorXi, Xi, old, alpha;
     alpha = 1.4;//acceleration factor
     iter = 0;
     do
     {
      iter = iter+1;
      errorX = 0.0; //max absolute value of change in x value
      maxX=0.0; // max absolute value of x
      for (i=0; i<=n-1; i++)
      {
       old = X[i];//Old value is stored to determine errorX and acceleration
       Sum = - A[i][i]*X[i]; //diagonal term is subtracted and added to avoid asking if i!=j
       for (j=0;j<=n-1;j++)
        Sum = Sum + A[i][j]*X[j];
       X[i] = (B[i]-Sum)/A[i][i];
       X[i] = old + alpha*(X[i]-old);
       errorXi=Math.abs(X[i]-old);//Accelerating
       Xi=Math.abs(X[i]);
       //Updating errorX and maxX
       if (Xi>maxX)
        maxX=Xi;
       if (errorXi>errorX)
        errorX = errorXi;
      }
       System.out.println ("iter = " +iter +"  errorX = " +errorX +" maxX = " +maxX);
     }
     while (errorX/maxX>0.000001 && iter<1000);
     for (i = 0; i<=n-1; i++)
      System.out.print("X[" +i +"] = " +X[i] +"   ");
      System.out.println();
    
    }
    }
    

    coryj on
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited August 2007
    Damn. They must have done that in notepad...

    Do you have Visual Studio? Just plop it in there if see if the code even runs. Based on that formatting alone, I doubt it is without errors.

    Whatever it outputs might give you some clues.

    I would for you but it is both late, and my computer is doing a lot of work atm.

    Jasconius on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    Yeah, they have not set a very good example all term (my handed in assignments have more comments than their example progs)... I have JCreator which I will throw it in later.... I am planning to dedicate most of tomorrow to this, which is probably wise since its due Thursday! (I'm just thankful its curved and I dominated most of the other assignments).

    coryj on
  • Options
    ScooterScooter Registered User regular
    edited August 2007
    Well, going to the formula for Node 1 (A0), we know A1 to the left is 0, and h = 1 cm, so it becomes A0 = (A2-1cm^2)/2. And you could make a hundred equations with subbing each into the next and get something huge, but at the end I don't see how you'd solve it, knowing just one A value to start with. if dA/dx = 0 is supposed to be true across the entire line, then A is always 0.

    ...I've really got no idea what the code is trying to do or how it relates to the problem. :\

    Scooter on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    I took the dA/dx = 0 to be only true at node 100, but I don't see a way to not get the same value across the entire thing for A's...

    coryj on
  • Options
    LewishamLewisham Registered User regular
    edited August 2007
    Jasconius wrote: »
    Damn. They must have done that in notepad...

    Do you have Visual Studio? Just plop it in there if see if the code even runs. Based on that formatting alone, I doubt it is without errors.

    Whatever it outputs might give you some clues.

    I would for you but it is both late, and my computer is doing a lot of work atm.

    Well I would hope that coryj has just pasted it in wrongly, loads of the loops and if statements don't have opening {. Unless the coder knows something I don't about Java programming.

    Lewisham on
  • Options
    Vrtra TheoryVrtra Theory Registered User regular
    edited August 2007
    As has already been pointed out, the equation provided can't be solved by normal means, since the value of every node depends on neighbors on either side. To clarify that, the equation should have been worded like this:
    When a node i has node i-1 immediately to the left, and node i+1 immediately to the right, with equal spacing h, [...]:

    (Ai-1 + Ai+1 - 2Ai) / h^2 = 1

    Based on the class name, I dug up a wiki article on Cholesky decomposition. I'm not familiar with that name, but I'm familiar with the idea, as it is similar to how a neural network works.

    Basically, you create a matrix, and start out by filling it with reasonable guesses. Then, iteratively update every element of the matrix by averaging it with what its "correct" value should be based on its neighbors and your target equation. Over enough iterations, every element in the matrix will converge on the correct number. (In this case, it looks like you would wait until the sum of the corrections each iteration went below a certain threshold.) You then have a list of 100 Ai values that you can graph and table.

    An example might like something like this:

    1. Fill hundred-item vector X[1,100] with values.
    2. For each item i=2 through 99 in X:
    2a. Solve for Ai using equation.
    2b. Store the difference between Ai and Xi (also known as the error).
    2c. Update X by averaging it with Ai.
    3. Repeat step 2 until the sum of all the stored differences (errors) is less than a given threshold.

    You can see this skeleton very plainly (including the error threshold checking) in the code given. I'm not sure exactly how the Cholesky algorithm does its thing, but I'm sure that this is the basic idea.

    Vrtra Theory on
    Are you a Software Engineer living in Seattle? HBO is hiring, message me.
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    Lewisham wrote: »
    Well I would hope that coryj has just pasted it in wrongly, loads of the loops and if statements don't have opening {. Unless the coder knows something I don't about Java programming.

    Actually, I pasted it directly from an email sent by the professor, that is how it looked when he sent it (ie, severe lack of indenting).
    EDIT: Also, the for loops don't need {} if you exclude them, though, only the first line following will be counted as part of the for statement (you probably knew this, but that could be what you were referring to)


    Vrtra Thoery, thanks very much... you gave a lot of info to go off of, and you seem to be entirely correct.

    coryj on
  • Options
    etdragonetdragon Registered User regular
    edited August 2007
    I think I agree with Vrtra Theory's logic on this one but I'm not 100% sure.

    Also, slightly off topic but coryj, being that you are in Philly what school do you go to?

    etdragon on
    sig.jpg
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    etdragon wrote: »
    I think I agree with Vrtra Theory's logic on this one but I'm not 100% sure.

    Also, slightly off topic but coryj, being that you are in Philly what school do you go to?

    The only school that would be wrapping up classes in the last week of August... Drexel

    coryj on
  • Options
    etdragonetdragon Registered User regular
    edited August 2007
    coryj wrote: »
    etdragon wrote: »
    I think I agree with Vrtra Theory's logic on this one but I'm not 100% sure.

    Also, slightly off topic but coryj, being that you are in Philly what school do you go to?

    The only school that would be wrapping up classes in the last week of August... Drexel
    That's what I figured based on the fact that you were still in class. I went to Drexel as an undergrad and now I'm here for grad school in ECE.

    Who is teaching this programming class (because it sounds kind of retarded)?

    etdragon on
    sig.jpg
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    etdragon wrote: »
    coryj wrote: »
    etdragon wrote: »
    I think I agree with Vrtra Theory's logic on this one but I'm not 100% sure.

    Also, slightly off topic but coryj, being that you are in Philly what school do you go to?

    The only school that would be wrapping up classes in the last week of August... Drexel
    That's what I figured based on the fact that you were still in class. I went to Drexel as an undergrad and now I'm here for grad school in ECE.

    Who is teaching this programming class (because it sounds kind of retarded)?

    S. Ratnajeevan Hoole... I don't know much about the guy, but they don't really seem to be going about the course properly at all (the first day of class he said "we don't teach syntax in this course, its best learned through doing" and then the TA wouldn't help these guys who never even saw JAVA before, telling them they 'obviously didnt read the book"). I mean, I took AP Comp Sci in high school and this class covers the same stuff (a little less, even), but I have found it pretty challenging just because the labs assigned are confusing as hell.

    coryj on
  • Options
    etdragonetdragon Registered User regular
    edited August 2007
    coryj wrote: »
    etdragon wrote: »
    coryj wrote: »
    etdragon wrote: »
    I think I agree with Vrtra Theory's logic on this one but I'm not 100% sure.

    Also, slightly off topic but coryj, being that you are in Philly what school do you go to?

    The only school that would be wrapping up classes in the last week of August... Drexel
    That's what I figured based on the fact that you were still in class. I went to Drexel as an undergrad and now I'm here for grad school in ECE.

    Who is teaching this programming class (because it sounds kind of retarded)?

    S. Ratnajeevan Hoole... I don't know much about the guy, but they don't really seem to be going about the course properly at all (the first day of class he said "we don't teach syntax in this course, its best learned through doing" and then the TA wouldn't help these guys who never even saw JAVA before, telling them they 'obviously didnt read the book"). I mean, I took AP Comp Sci in high school and this class covers the same stuff (a little less, even), but I have found it pretty challenging just because the labs assigned are confusing as hell.
    Yeah I know Hoole. He started last year as a visiting professor. I had him for a single term for one of the graduate level systems classes and I never want to take a class with him again. He just seems so unorganized and never knows the subject material particularly well.

    After thinking about this problem though I really do think Vrtra Theory's steps will give you a feasible solution. I'm not a programmer by nature but the logic behind his steps makes sense mathematically. I would say you should check in with the TA before you spend time writing the code but it sounds kind of like the TA is useless for this course.

    etdragon on
    sig.jpg
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    etdragon wrote: »
    After thinking about this problem though I really do think Vrtra Theory's steps will give you a feasible solution. I'm not a programmer by nature but the logic behind his steps makes sense mathematically. I would say you should check in with the TA before you spend time writing the code but it sounds kind of like the TA is useless for this course.

    Yes, I am pretty sure that's what needs to happen... they have been REALLY generous with partial credit so far this term (at least for me since I was doing things like using recursion in week 1...), so I think I am just going to put something together without consulting the TA (he isn't very helpful). Hoole decided this would be a fun week to be gone the whole time for a trip of some kind... I emailed him 2 days ago with no reply, so I don't think he will be around to help either.

    Thanks for all the help, guys!

    coryj on
  • Options
    coryjcoryj Registered User regular
    edited August 2007
    OK, I actually found the code provided very helpful after my eyes were opened.

    I took the given code and edited it and formatted it properly and added comments to make it more sensible. Now, the two immediate things I need to do are populate the arrays A[] [] and B[]

    I am not 100% sure I understand why A is a 2d array, but that is how it was before.

    Does anyone know any logical ways to populate these?
    //import for math utils
    import java.util.*;
    
    public class Gaussian {
       
    	public static void main(String[] args)
    	{
        	int i, j, n, iter=0; 
        	double Sum, errorX, maxX, errorXi, Xi, old, alpha;
        	n = 100; //100 terms
        	
        	double [][] A = new double [100] [100];
        	//*****NEED TO INITIALIZE
        	
        	double [] B = new double [100];
      		//*****NEED TO INITIALIZE
        
        	double [] X = new double [100];
       		//populate x array, its all 0.0
       		for(int popx=0; popx < 100; popx++)
       			X[popx] = 0.0;
      		
      		//Begin initialization -- guess values.
     		for (i=0; i<=n-1; i++)
      			X[i] = B[i]/A[i][i];
     		
     		alpha = 1.4;//acceleration factor
     		
     		do
     		{
      			iter = iter+1;
      			errorX = 0.0; //max absolute value of change in x value
      			maxX=0.0; // max absolute value of x
      			
      			for (i=0; i<=n-1; i++)
      			{
       				old = X[i];//Old value is stored to determine errorX and acceleration
       				Sum = - A[i][i]*X[i]; //diagonal term is subtracted and added to avoid asking if i!=j
       				
       				for (j=0;j<=n-1;j++)
        				Sum = Sum + A[i][j]*X[j];
       
       				X[i] = (B[i]-Sum)/A[i][i];
       				X[i] = old + alpha*(X[i]-old);
       				errorXi=Math.abs(X[i]-old);//Accelerating
       				Xi=Math.abs(X[i]);
       				
       				//Updating errorX and maxX
       				if (Xi>maxX)
        				maxX=Xi;
       				if (errorXi>errorX)
        				errorX = errorXi;
      			}
       			System.out.println ("iter = " +iter +"  errorX = " +errorX +" maxX = " +maxX);
     		}while (errorX/maxX>0.000001 && iter<1000);
     
     		for (i = 0; i<=n-1; i++)
      			System.out.print("X[" +i +"] = " +X[i] +"   ");
      		System.out.println();
    
    	}
    }
    

    coryj on
  • Options
    ScooterScooter Registered User regular
    edited August 2007
    Might as well just do a loop and set them to i. Or make them all 50. It probably doesn't matter what they start as.

    Scooter on
  • Options
    LewishamLewisham Registered User regular
    edited August 2007
    Scooter wrote: »
    Might as well just do a loop and set them to i. Or make them all 50. It probably doesn't matter what they start as.

    That was my thought as well. The iteration should make them settle.

    Lewisham on
Sign In or Register to comment.