- Upvotes Received
- 1
- Posts with Upvotes
- 1
- Upvoting Members
- 1
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
24 Posted Topics
I've followed an example from a website on how to use diff time, however its telling me that it took 0 seconds which obviously isn't right...can anyone please explain what I'm doing wrong? Thanks in advance! [code=php]int main() { time_t t1, t2; double dif; Matrix A(2); Matrix B(2); A.SetElement(1,1,1); A.SetElement(1,2,2); … | |
I'm using [code=php] for (int i = 0; i<mdim_; i++) { for (int j = 0; j<ndim_; j++) { data_[j * ndim_ + i]; } } [/code] to change the matrix 1 3 2 4 stored in data, into row order. If I print data_[j * ndim_ + i]; to … | |
I have a 2x2 matrix A stored in data_ 1 3 2 4 (column major order) and a 2x2 matrix B stored in b.data_ 5 7 6 8 and I'm using the function below to append (stick underneath) B to A. so my result should be 1 3 5 7 … | |
I'm trying to find a formula for copy[3] = b.data[0] copy[4] = b.data[1] copy[5] = b.data[2] copy[9] = b.data[3] copy[10] = b.data[4] copy[11] = b.data[5] letting the right hand side be b.data[i], I can see this is like copy[3] = b.data[0] multiply by 2, add 3 copy[4] = b.data[1] multiply … | |
I'm trying to use matrix multiplication to multiply b onto a. Using the method I've written below, changes the values of matrix A which I've then realised messes up later calculations. Would the best way to get around this be to make two copies of the matrices A and B … | |
I have a matrix A stored in column major order as 1 3 2 4 and I'm using this function to output it in row major order, i.e. 1 2 3 4 which is does correctly. However I'm confused about how it does this, as I thought the loops would … | |
My program keeps crashing and I can't see why, if I remove the line [code=php] myfile << data_[i+ndim_*j] << " "; [/code] then it runs OK...but can't see anything wrong with this line? [code=php] void Matrix::WriteToFile(std::string fname) const { ofstream myfile; myfile.open ( (fname+".txt").c_str() ); for (int i = 0; … | |
My function is: [code=php] void Matrix::WriteToFile(std::string fname) const { ofstream myfile; myfile.open ("std::string fname.txt"); for (int i = 0; i<data_.size(); i++) myfile << data_[i] << " "; myfile.close(); } [/code] and then in the main I have A.WriteToFile("hello"), but it's saving it as fname still? Can anyone please tell me … | |
I've been struggling over this for hours, and just can't seem to figure out a formula for it. I'm trying to append below, (attach underneath) one matrix to the other. So for example, for Matrix A: 1 2 3 4 5 6 and Matrix B: 7 8 9 A.Append(B) becomes: … | |
My program keeps crashing and I can't see why...pretty sure its something to do with creating matrix B since when I remove the commands to create matrix B it runs ok. Can anyone see what is wrong? Thanks in advance! I have the header file: [code=php] // matrixlib.h - A … | |
I need this for matrix multiplication, I'm putting any 2 dimensional matrix into 1 dimension by column major order, i.e. the matrix 1 2 3 4 is stored as [1 3 2 4]. To try and figure it out I've worked out the pattern for 2x2 matrices: [code=php] data_[1] = … | |
I'm using the header file below. I'm a little confused about how to store any matrices I create... If I do: [code=php] int main() { Matrix A(2, 3); Matrix B(3); return 0; } Matrix::Matrix(int mdim_, int ndim_) { data_.resize (mdim_*ndim_); for (int i = 0; i < mdim_*ndim_; i++) { … | |
Could someone please have a look at my code and tell me anything that can be improved? Anything at all - layout, using headers etc? Thanks in advance! [code=php] #include<iostream> #include<vector> #include<cmath> #include<iomanip> using namespace std; typedef double(*fun)(double); //Declare functions double gauss(fun f, double &a, double &b, int &n, double … | |
I've just read up about pointers, so wanted to see if I can try and use them in my program. I have the function "equation", which at present is t^2. I also have the function "gauss", in which I am going to use the equation t^2, (code for this is … | |
I was just hoping to get some advice before I start writing my program, I need to put two columns of data into some sort of data structure, and each number has about 25 decimal places. Can anyone recommend the best one? Would storing them as a vector work? Thanks … | |
My code compiles and is working correctly, but I was just wondering if anyone could check over it and suggest any improvements or correct things I've done that are bad in the c++ world...anything at all? Thanks in advance! [code=php] #include<iostream> #include<vector> #include<cmath> #include<iomanip> using namespace std; //Declare functions void … | |
I'm testing this program for: x^2 + 0.17714x -2.5147583 with k = 1.4997 I've been looking at this for hours and have worked through it on paper, but can't figure out why line 59 is calculating C[1] as 0.17714. C[1] should be 1.6768. Can anyone please help me figure this … | |
I have 2 main if statements inside this for loop (lines 7 and 56). I'm trying to get so that if after all the iterations are complete, i.e. j = 51 the first and second if statements are not satisfied, then it will print out an error message. I have … | |
Hi all, For have implemented a program that performs the bisection method, currently with the user entering the initial interval to find one root. However I was wondering if I could get the program to find the intervals automatically without the users input. The only way I can think to … | |
I'm trying to implement the algorithm described here under 'definition', [url]http://en.wikipedia.org/wiki/Laguerre%27s_method[/url] To summarise it takes an initial guess 0, and then iterates to find the root. In lines 68 to 71 I was hoping this would exit the function, i.e. when the root is found...but it's still carrying on. Can … | |
I've put so much effort into making this program and it keeps crashing! I previously had the two functions in separate files which were working fine, but I combined them into 2 - the poly function is still working fine, but the bisection function crashes at the line: "Enter the … | |
This program was working fine yesterday, and then all of a sudden today it isn't working and I haven't changed anything?! It complies OK, but for for easy functions that I enter and know the roots of, it says there is no root. Can anyone please explain what is going … | |
Hi, My program takes any polynomial and calculates the first and second derivatives and evaluates them at a given x. The coefficients of the polynomial are stored in a vector A. I now want to do something else to this polynomial, however my calculations for the derivatives mean that the … | |
Hi, I've tried to make a program that inputs two 3D vectors and then calculates various norms of the first vector, and the dot product and addition of both vectors. My code is working fine when everything is put into the main, however I wanted to create some functions to … |
The End.