For only one fucking exercise, I'm supposed to use a code and a software I never used before... And I can't get it to work. There's a QT project, and I'm supposed to code a few functions in C++, about the Lagrange interpolation. So here's the QT project:
And here's the code I did for one of the functions (which doesn't work because for the life of me I couldn't get variables from a scope to another in fucking C++):
std::vector<float> LagrangePolynomial::computeLagrangeBasisDenominators() { float xi, xj; std::vector<float> d = std::vector<float>(); // Array containing all the denominators to return for (int i=0; i<3; i++) { float di = 1; // Denominator number i xi = p[i][0]; // Find a way to bring fucking p in here for (int j = 0; j < 3; j++) { if(j != i) { xj = p[j][0]; di *= (xi - xj); } } d.push_back(di); } return d; }
The code itself should be easy, the algorithmic is basic. But I just can't seem to use this software and I have no idea about C++. I don't even understand how to call a function, which I need to do if I want to test my code.
So plz halp anyone, wud be veri much appreciated :'(
LoOk_tOm wrote:I have something in particular against Kaisar (GERMANY NOOB mercenary LAMME FOREVER) And the other people (noobs) like suck kaiser ... just this ..
I can't take a serious look at this right now, because I'm in the middle of an emergency, but from what I remember, you can define a variable in a class with public access and then use that scope to call it in another class.
I think you want to pass p in as a parameter to the function computeLagrangeBasisDenominators. So, the function definition would look like, computeLagrangeBasisDenominators (float[3][3] p) {...}. Then in your main when you want to call the function you would say, Vector<float> ans = computeLagrangeBasisDenominators(p); Assuming you have some 3x3 float array called p.
@Dolan the problem is that I need to keep the projects the teachers gave me, and just code 3 functions. Everything else should be left untouched, I think. So I can't change the way they declared their variables.
@Dankl I thought about that, it makes most sense imo. However, in the C++ header file (which I guess kind of declares the functions and global variables used in the C++ source file..?), I have:
Which means that the computeLagrangeBasisDenominators function doesn't take any parameter, right? And since I'm not supposed to touch the framework I was given, but only the bodies of 3 functions, I'm afraid I can't do that :S
But thanks a lot guys for helping anyway, it's much appreciated
LoOk_tOm wrote:I have something in particular against Kaisar (GERMANY NOOB mercenary LAMME FOREVER) And the other people (noobs) like suck kaiser ... just this ..
(which doesn't work because for the life of me I couldn't get variables from a scope to another in fucking C++)
Clarify? Are you unable to call the function or unable to access variables that you need inside the function? I'm guessing the latter because in your code it says "find a way to get fucking p in here". Is p a field in the same class your function is in? Then you can use it by saying this->p
(which doesn't work because for the life of me I couldn't get variables from a scope to another in fucking C++)
Clarify? Are you unable to call the function or unable to access variables that you need inside the function? I'm guessing the latter because in your code it says "find a way to get fucking p in here". Is p a field in the same class your function is in? Then you can use it by saying this->p
I am unable to access variables from inside the function. Plus, I am also unable to call my function to test it, because I can't get to run my code in QT and get output in a console.
p is a variable that was declared in, I think, another function of the same class:
According to what the exercise says, p is indeed the variable I need to use. But it wasn't declared in the header file (which is where some global variables were declared I think), instead it was declared in this weird function. And I need to use it in another function of the same class.
LoOk_tOm wrote:I have something in particular against Kaisar (GERMANY NOOB mercenary LAMME FOREVER) And the other people (noobs) like suck kaiser ... just this ..
That weird function is the constructor (because it has the same name as the class). It creates a temporary variable p and stores it in the curve supportPoints. To access it you need the line,
std::vector<Vector> p = supportPoints.getPositions();
Dankl wrote:That weird function is the constructor (because it has the same name as the class). It creates a temporary variable p and stores it in the curve supportPoints. To access it you need the line,
std::vector<Vector> p = supportPoints.getPositions();
inside your function.
Wow, I don't get any error anymore when I declare p the way you said. Sounds good, thanks a lot! Do you know how I can test it now, though? When I run the project, it just launches an empty command prompt, in which I can't type anything, and nothing happens. I guess I need to call my function somehow?
Ashvin wrote:Passing p as an argument it is kinda hard to see how that would work, are you sure you are not allowed to do that?
I'm pretty sure I'm not, though I could ask. But with Dankl's solution, I guess I don't need to.
LoOk_tOm wrote:I have something in particular against Kaisar (GERMANY NOOB mercenary LAMME FOREVER) And the other people (noobs) like suck kaiser ... just this ..
LoOk_tOm wrote:I have something in particular against Kaisar (GERMANY NOOB mercenary LAMME FOREVER) And the other people (noobs) like suck kaiser ... just this ..