C++ :: How To Create A Large Matrix To Be Solved Using Numerical Methods

Jun 24, 2013

I am having a problem on how will I create a large matrix to be solved using numerical methods. Say I have a 500 x 500 matrix and want to find these 500 equations. How will I do it? To be exact, here is a sample problem

| -2 1 . . . . . . . || x1 | |h^2|
| 1 -2 1 . . . . . . || x2 | |h^2|
| 0 1 -2 1 . . . . . || . | | . |
| 0 0 1 -2 1 . . . . || . | = | . |
| . . . . . . . . . 1 || . | | . |
| . . . . . . . . 1 -2||x500| |h^2|

Where h = 1/(n + 1)

Solutions on finding would be gauss elimination, Successive overrelaxation, Jacobi Iteration, biconjugate gradient method and Thomas algorithm. I want to compare the accuracy, with tolerance of 10^-6

View 2 Replies


ADVERTISEMENT

C++ :: Create A Map Based Hash Table For A Sparse Matrix?

Jul 24, 2014

I have this assignment where I have to create a map based hash table for a sparse matrix. The professor has provided some code and I'm supposed to fill in parts of it to make it work.

He has given us a class sparseMatrix which we need to provide a hash function for. This hash function is to be defined in a Class TupleHash which is inside sparseMatrix. I think I got that part down. What is really confusing me is what he has done with some typedefs.

For one of them I had to declare an unorderd_map that maps a struct Tuple on to the class template argument Object. I did that like so:

typedef unordered_map<Object,Tuple,TupleHash> HashTable;

The next typedef was given to me like so:

typedef typename HashTable::value_type valueType;

This is giving me a world of unintelligible error messages. This is how it starts.

In instantiation of 'struct std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash>':|
recursively required from 'struct std::__and_<std::is_default_constructible<sparseMatrix<int>::TupleHash>, std::is_copy_assignable<sparseMatrix<int>::TupleHash>, std::__detail::__is_noexcept_hash<int, sparseMatrix<int>::TupleHash> >'|

View 1 Replies View Related

C++ :: Create Random Matrix And Print It Out In Text File

Feb 11, 2014

I am trying to create a random 3x3 matrix and print it out in a text file using basic functions. My code below will not compile.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//nxn Matrix = 3x3
const int ROWS = 3;
const int COLS = 3;

[Code] .....

View 2 Replies View Related

C++ :: Create Matrix Of Data That Add Values Based On Reading Get From DVM

Apr 22, 2012

Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.

The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.

What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?

Here is what I got

Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3

[Code]....

View 7 Replies View Related

C :: Routines Library For Numerical Tasks

Jan 13, 2014

I am looking for C-libraries that would do numerical tasks with special emphasis on numerical differentiation of arbitrary order, numerical integration (Monte Carlo etc.) and interpolation. I would be grateful if you can provide me with some resources. By the way I already have Numerical Recipes but would like to have another resource at hand.

View 11 Replies View Related

C++ :: How To Put Values Of Array In Numerical Order

May 20, 2014

im trying to make a statistics program and i have an array holding all the users numbers. The array has 10 elements and i was wondering how i could put these elements in order from smallest to largest.

View 18 Replies View Related

C++ :: Sorting Numerical Array Error

Nov 25, 2013

Why this wont run? I'm getting the cant convert int* to const char error but i do not know why?

I'm trying to create a program that creates an array of 100 ints between 0 and 250 and then sorts them using a separate function, I've gotten this far

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <cstring>

using namespace std;
void quicksort (int *items, int len);

[Code] ....

View 3 Replies View Related

C++ ::  Sorting Array To Numerical Order?

Nov 25, 2014

I need to find the Mean, median, mode, and make a histogram of a 99 value array. How ever my sorting function is not sorting the array at all how can I fix this.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <cctype>

[Code].....

View 8 Replies View Related

C++ :: Using OOP To Implement Matrix Class That Provide Basic Matrix Operations

Mar 27, 2013

i want to know how i can solve this question? do i need to create a class or write the program codes.

View 12 Replies View Related

C :: How To Make Function Which Gives Back Two Numerical Values

Nov 3, 2014

How make function which gives back two numerical values. I think needs using structure. now i try found my c book.

View 3 Replies View Related

C++ :: Floating Point Numbers / Numerical Analysis

Oct 30, 2013

I have the problem of trying to find the smallest natural number that makes two consecutive terms in single precision floating point notation in the riemann zeta function equal. So basically the riemann function of 2 is given by:

sum of 1/(k^2) from k=1 until infinity, so : 1/(1^2) + 1/(2^2) + 1/(3^2) + ...... until infinity.

Now the question asks to stop at the smallest natural number n, at which the sum 1/1^2 + 1/2^2 + ......+ 1/(n^2) is equal to the sum 1/1^2 + 1/2^2 + ..... + 1/((n+1)^2) in single precision floating point notation.

Now well the obvious way to look for n would be on this way:

float i = 1.0;
float n = 1/(i);
float n1 = 1/(i+1.0);
while ( n != n1){
i += 1.0;
n = 1/i;
n1 = 1/(i+1.0);}

But first of all this is obviously completely inefficient and I dont think it will yield a valid answer for any float variable, i.e. I dont think the sum until 1/n^2 and 1/(n+1)^2 will ever differ. I tried it out with the largest possible value of a variable of type float and the values were still seen as unequal in C++. How to do this? Will C++ find a value for n for which the condition holds? Is the compiler or my hardware important for this, i.e. would I get different results on a different pc?

View 2 Replies View Related

C/C++ :: Infinite Loop If Non-numerical Character Entered

Jul 28, 2014

it will produce the answer above..when user enter a nonnumerical character it will force the user to reenter again

do {
cout<<"Min of the secret number : ";
cin>>min;
}while(cin>>min);
cout<<"Max of the secret number : ";
cin>>max;

this is my coding but it will auto jump out when i enter non-numeric character

View 7 Replies View Related

C++ :: Implementing Template Operator - Numerical Array

Jun 19, 2012

I what to implement to my Template operator * . There is <Template> Array which purpose is container like vector for classes. There is class Point, each object of contain two coordinate x and y.

So,
1. I wanna fill Array with objects from Point class
2. Multiply each objects from this vector to a factor
3. And print all this bunch of objects ()...

Compile error :
1>------ Build started: Project: HP_4.2b_Ex2, Configuration: Release Win32 ------
1> main.cpp
1>main.cpp(21): error C2440: 'initializing' : cannot convert from 'Point' to 'Array<Type>'

[Code] ....

And pop -up helper tell that : Error: no suitable user defined conversion from "Point " to Array<Point> exist

Code:
//array.h
#ifndef Array_H
#define Array_H
template <class Type> //Remove the "=double" default parameter.
class Array {
protected:
int m_size;
Type* m_data; //m_data should be a pointer, since you want to allocate data to it

[Code] ....

View 6 Replies View Related

C++ :: Accept Matrix As Argument And Display Its Multiplication Matrix

Jun 1, 2014

I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.

View 1 Replies View Related

C++ :: Number Of Characters / Operators / Uppercase Letters And Numerical Digits

May 5, 2014

I have to code a simple program who determining the number of Characters (A character could be any alphabets, digits, punctuation marks, or special , Operators ( Operators are those symbols that are used in mathematica expression, such as,'+', '*', '/', '-', and so on.), Uppercase letters (Uppercase characters are those from A..Z) and Numerical digits ( A digit is any of the Hindu-Arabic numerals from 0..9). Why the output is wrong!

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std ;
int main() {
char text;

[Code] .....

This is my input file This is a possible factorial function in a programming language called LISP

(defun factorial (n)
(if (< n 2)
1
(* n (factorial (1- n)))))

This is my output:

The number of characters = 113
The number of operators = 3
The number of numerical digits = 3
Uppercase letters = 5

I think that "characters" is wrong, but I do not know why !

View 4 Replies View Related

C/C++ :: Assign A Matrix To Submatrix Of A Bigger Matrix?

Feb 27, 2012

I want to assign a matrix to submatrix of a bigger matrix.

ublas::matrix<int> A(8,5);
ublas::matrix<int> B(2,5);
for(size_t i=0;i<A.size1();++i)
for(size_t j=0;j<A.size2();++j)
        A(i,j)=i*A.size2()+j+1;
for(size_t i=0;i<B.size1();++i)
    for(size_t j=0;j<B.size2();++j)
        B(i,j)=i*B.size2()+j+5;
ublas::matrix_range<ublas::matrix<int> > a(A,ublas::range(0,2),ublas::range(0,5));
a=B;  

and it works.

but if the matrix is compressed_matrix type, there's something with it. the error log as below:

Check failed in file boost_1_48_0/boost/numeric/ublas/detail/matrix_assign.hpp at line 1078:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted

I'm not sure this is a bug or not.

View 2 Replies View Related

C :: Program To Accept Only Numerical Values And Gives Error If Character Or Symbol Entered

Nov 11, 2013

How can i make my program to accept only numerical values and gives a error notice if a character or a symbol is entered???

View 4 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

Oct 17, 2014

I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).

The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes.

Header of the function sortMe must be as shown below:

void sortMe(int array[],int sortedIndexes [], int size, char mode)

When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.

Declare and initialize the array array.

Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.

EXAMPLE:

int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');

After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.

notice that the function does not e-arrange the elements in the array.

Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };

[code]...

how to use the other array.

View 5 Replies View Related

C++ :: Find Matrix P For A Square Matrix A

May 25, 2014

I have to prepare a project. But I don t know how can I do this. Program will find a matrix P for a square matrix A such that P^-1 A P ....

View 15 Replies View Related

C++ ::  Virtual Methods With MI

Jan 6, 2014

I have questions about multiple inheritance and virtual methods. I have a class called solid. All objects of this class have hitboxes and can collide with others. I have the following methods:

void testCollision(something begin, something end);
/* This method takes a container's begin and end iterators to test if the object collides with any other object of the list of all the solids currently in the game area. Each time there is a collision, it calls collide(other) and other.collide(*this) */

virtual bool collide(solid& other);
/* This method always returns false and does nothing */

This class will be inherited by another class which will have overloads for a few specific collisions. For example:

class player : public solid{
public:
bool collide(projectile& other);
bool collide(enemy& other);
bool collide(wall& other);
};

My question is quite simple actually. If I have a loop which calls testCollision() with all elements in the list of all solids (a list of pointers to solids to be exact) and there is a collision between the player and a projectile, will testCollision call player::colide(projectile& other) or will it call solid::collide(solid& other). And in any case, did I understand how to use the virtual keyword? If I'm right, it should call the player::colide method if it's there for the specific type, else it will call the solid::colide which only returns 0, ignoring collision.

View 4 Replies View Related

C++ :: CPP File With Methods

Feb 15, 2012

I have h-file with definition of 3 classes. And cpp-file with realization methods of this classes. And when I compile the project errors - LNK2019 is apperead... How make that methods become visible?

View 1 Replies View Related

C++ :: Delete All Parent Methods Of A Given Name?

May 7, 2013

I'm writing a sorted vector implementation and trying to do it as simply as possible.

Right now, I'm declaring the sorted vector with a protected subclass of vector, then using the "using" keyword to explicitly inherit all methods that aren't related to adding new elements to the vector (so I can control the order).

Eg:

Code: template<typename T, class Cmp = std::less<T>>
class sorted_vector : protected std::vector<T>{
public:
typedef typename std::vector<T>::iterator;
using std::vector<T>::operator=;
using std::vector<T>::assign;
using std::vector<T>::get_allocator;
using std::vector<T>::at;
using std::vector<T>::operator[];
//...
};

Obviously, this is annoyingly redundant. So what I'd like to do is something using the new "delete" keyword from C++11. Is there any quick, expressive way of deleting specific methods?

Also, it's pretty annoying to have to typedef base_class::type type to inherit a type from a base class. Is there a shorter way to do that?

View 14 Replies View Related

C++ :: Accessing Setter Methods

Nov 21, 2013

How to i access setter from within a setter?

I know that getter methods can be access like

Code: getAccounts().getAccountNumber();

// for example but for setters how do i do it? this doesnt seem to work though

Code: setAccounts().setAccountNumber(accountNumber);

View 7 Replies View Related

C# :: Package Methods In Struct

Oct 20, 2012

Is it common practice to package methods with other elements(string-s, int-s, float-s, array-s...) of struct?

Than struct acts as a class or is acting similar to class and that have no sense to me? I am new to OOP .

View 4 Replies View Related

C++ :: How To Call Methods Of Class

Feb 27, 2014

how to call the methods of the class.I have an object call v which is an array and I don't how to call the methods of the class. The error is here:

v.readDates(v[a]);

#include "Date.h"
#include <iostream>
using namespace std;
int main(){
int a;
cout << " HOW MANY DATES DO YOU HAVE? " << endl;

[code]....

View 3 Replies View Related

C++ :: Add And Overwrite Class Methods Through Lua

Oct 9, 2013

I'm using lua 5.2.2 with luabind 0.9.

I'd like to be able to add additional class-methods through lua for any classes that I've bound in c++, but I'm unsure how to do it.

The problem is that luabind uses a function as the __index-metamethod for any bound classes instead of a table, so I don't see a way to access the class-methods at all.

e.g., I'm binding my classes like this:

luabind::module(lua) [
luabind::class_<testClass>("TestClass")
.def(luabind::constructor<>())
.def("TestFunc",&TestFunc)
];

What I essentially want to do is to add a lua-function to the list of methods for this class, and be able to overwrite existing ones:

local t = tableOfClassMethods
local r = t.TestFunc -- Reference to the c++-function we've bound
t.SomeFunction = function(o) end -- New function for all objects of this class
t.TestFunc = function(o) end -- Should overwrite the c++-function of the same name

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved