Please help

This is a discussion on Please help within the C++ Programming forums, part of the General Programming Boards category; Hi, this is more of a math/linear algebra question. In the pdf you need to find v in order to ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    8

    Question Please help

    Hi, this is more of a math/linear algebra question. In the pdf you need to find v in order to make everything work... where the heck is v coming from? I see the equations and all, but what does it all mean, and how would you write that in c++?

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <sys/syslimits.h>
    #include <std.lib>
    
    double determinant(double M);
    double main(void)
    {
    	char filename[PATH_MAX+1];
    	printf("enter input file name =>");			/* prompt user for file name */
    	scanf("%s", filename);						/* store in filename[] buffer */
    
    	#define MAXPOINTS 100
    	int i, N;
    	double t[MAXPOINTS];
    	double y[MAXPOINTS];
    
    	FILE *f;									/* pointer to FILE (used for file I/O) */
    	f = fopen(filename, "r");					/* open input file for reading */
    
    	if (f == NULL)								/* fopen unsuccessful */
    	{
    		perror(filename);						/* print system error message */
    		exit(-1);								/* die */
    	}
    
    	for (i = 0; i < MAXPOINTS; i++)
    	if (fscanf(f, "%lf %lf", &t[i], &y[i]) != 2)
    	break;
    
    	fclose(f);
    	N = i;
    
    	double sumt, sumtt, sumttt, sumtttt;		/* sums for t, t^2, t^3, t^4 */
    	double sumy, sumty, sumtty;					/* sums for y, t*y, t^2*y */
    	double M[3][3], v[3];						/* system we are solving: Mx = v */
    	double x[3];								/* solution: x = [a b c] */
    
    
    }
    
    double determinant(double M[3][3]){
    
    	return ((-1)*M[2][0]*M[1][1]*M[0][2]+(-1)*M[2][1]*M[1][2]*M[0][0]+
                    (-1)*M[2][2]*M[1][0]*M[0][1]+M[0][0]*M[1][1]*M[2][2]+M[0][1]*M[1][2]*M[2][0]+
                    M[0][2]*M[1][0]*M[2][1]);
    
    }
    
    void solve(double M[3][3], double v[3], double x[3])
    {
    	double det = determinant(M);
    	double A[3][3];
    
    	A[0][0]=v[0][0];
    	A[1][0]=v[1][0];
    	A[2][0]=v[2][0];
    
    	X[0]= determinant(A)/det;
    
    	X[1]= determinant(A)/det;
    
    	X[2]= determinant(A)/det;
    
    }
    this is all that I have so far, and I know that I'm not done yet. Thanks for the help!
    -Jonbuckets

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    8

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    What pdf?

    EDIT: Ah ok.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    33,292
    > double determinant(double M);
    This needs to match the definition of the function later on.

    > double main(void)
    Nope, main returns an int, not a double.
    It makes a change from the usual "void main" crowd though

    > and how would you write that in c++?
    Apart from the mixing of declarations and statements, all of this could just as easily be C code.
    Which language are you supposed to be using?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    The code is stuff that I've written already. I'm writting the code in a c++ compiler, but we are only supposed to use the C laguage. The big part I'm confused with is how to find v, or what v even is, I just don't understand the math behind it. From there I can get everything else to work.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    33,292
    From reading the PDF, I would think v means velocity
    For which there is an equation if you know the initial velocity and a number of acceleration/time measurements.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21