C++ :: Construct Truncated Gaussian Distribution In The Range Of (5-20 Microns)?

Apr 19, 2014

I need to construct Truncated Gaussian distribution in the range of (5-20 microns), specifyed by initial standard deviation.

Particularly i need input which comprises of minimum value(5 microns), maximum value(20 microns) and standard deviation of (5,10,20 etc..). In this regard i tried with Box-Muller but it doesn't fulfuil the goal.

View 2 Replies


ADVERTISEMENT

C++ :: Normal Distribution Range - Select Objects On A Vector

May 23, 2014

I'm implementing an normal_distribution to select objects on a vector. The thing is I can't use values greater then 1 or less then -1. Here is what could be done:

gausx=gaus_distributionx(generator);
while((gausx>1) || (gausx<-1))
gausx=gaus_distributionx(generator);

The question is if the distribution would loose it's power to be a normal distribution, because some of the gerated numbers wouldn't be used. Any way to set ranges for the distribution?

View 6 Replies View Related

C :: Large Integer Implicitly Truncated To Unsigned Type

Mar 10, 2014

I am using a structure , and when i am assing values i get the warning message , how do I avoid that ?

Code:

// header file
typedef struct {
unsigned _T_ipset:1;
unsigned RTCSetNewTime:1;
unsigned PassWord:1;
unsigned UserReset:1;
unsigned PCDEBUG:1;
unsigned PWRUP:1;
unsigned HostTaskShift:1;
unsigned TimeToConnMstr:1;
unsigned En_Display_Lcd:1;
}

[code]....

large integer implicitly truncated to unsigned type

View 1 Replies View Related

C :: Display Histogram Of 1000 Gaussian Distributed Numbers

Mar 5, 2013

I'm writing a program to display a histogram of 1000 Gaussian distributed numbers. I've generated the numbers using rand and now need to transform them. I have found the following formula to use

f(x) = exp(-x^2 / (2*sigma^2)) / sqrt(2*pi*sigma)

And I am unsure how to implement this into a function.

View 3 Replies View Related

C/C++ :: Implementing Parallel Gaussian Elimination Using Message Passing

Nov 6, 2014

I'm implementing parallel gaussian elimination using message passing. However, there is a problem with allocations and I don't get the correct answer. The matrix A is decomposed into smaller matrices (ie subA) and used into a buffer.

int n = 2; // for matrix size 1024 (additionally 2048 and 4096 was calculated)
#define MAXN 2
volatile float **a, *b, x[MAXN];
// generate a and b randomly; x is set to 0
void generateMatrix() {

[Code] ....

View 2 Replies View Related

C :: Declaring Array In If-Else Construct

Apr 4, 2013

Code:

if (IS_LEAP_YEAR(year))
const int days_per_month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
else
const int days_per_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; Is it ok to declare the array in this manner or is it bad?

And i have to ask the user for a date to enter in my program. So should I use scanf or should I store the date in a string and then use sscanf. I have to check for valid input for everything like day, month, year etc. I did it as below..

Code:

int assignments;
assignments = scanf("%d / %d / %d", &month, &day, &year);
fflush(stdin);
if (assignments != 3)
{
printf("Retry: ");
}
else
error checking.

View 9 Replies View Related

C :: IF Construct And Printing Strings

Apr 26, 2014

This code i made divided a user input into characters and non character. The problem im having is that if a mixed sentence is created, such as 32B, it will only print the 'char string' and not the 'non char string'. But when the sentence is just non characters like 32 it will print the 'non-char string'. So essentially if a mixed sentences is created both of the strings won't be created or printed.(This is only a function by the way).

Code:

Count_chars( char Input[]) {
int i;
for(i = 0; Input[i]; i++) {
if((Input[i] <= 122) &&(Input[i] >= 97)){
printf("Char %c ",Input[i]);
Char[i] = Input[i];

[Code]...

View 4 Replies View Related

C++ :: Construct Maps Initialization

May 5, 2013

I've a problem with the map construct. I wrote this class in which there are maps:

class Features {
private:
map<const string,GenericFeatureContainer*> featuremap;
map<const string,GenericFeatureContainer*>::iterator it;
int size;
public:
}

And I have the following constructor:

Features::Features() {
map<NULL,NULL> featuremap;
it=NULL;
size=0;
}

Is that correct? otherwise what is the correct syntax?

View 2 Replies View Related

C++ :: Compute Mean / Median / Mode For Map Construct

May 28, 2013

I am writing code, which reads an input file (280 MB) containing a list of words. I would like to compute

1) total # of words
2) total # of unique/distinct words
3) mean/median/mode of word count (Link)

I managed to get done with 1) and 2), but my program crashes for 3). I am not quite sure whether there are memory issues or some bug in the code.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;

[Code] .....

View 2 Replies View Related

C :: Utilizing Type Casting Construct

Apr 13, 2014

This code i made, utilizing the type casting construct, isn't outputting what i wanted. The output for 'Dollars' and 'Cents' are returning '0' for both. instead all i want it to do is seperate the two. for example changing the float value of amount to an integer, giving a dollar value.

Code:

#include <stdio.h>
int main()
{
}

[code]....

View 1 Replies View Related

C++ :: Construct Simple Hash Function?

Jun 3, 2013

How to construct a simple hash function ? When the program executes, it will ask for your name. Type your name and it will print out a "hash code" (a number) from that name.

View 2 Replies View Related

C++ :: Completely Random Distribution Of Numbers

Feb 5, 2014

I'm looking to code a completely random distribution of numbers that doesn't affect performance using rand. I believe this code would be ideal but I don't understand how to use it. Where would I input the range of numbers and the quantity?

double uniform_deviate ( int seed ){
return seed * ( 1.0 / ( RAND_MAX + 1.0 ) );
} int r = M + uniform_deviate ( rand() ) * ( N - M );

And for the seed...

unsigned time_seed(){
time_t now = time ( 0 );
unsigned char *p = (unsigned char *)&now;
unsigned seed = 0;
size_t i;
for ( i = 0; i < sizeof now; i++ )
seed = seed * ( UCHAR_MAX + 2U ) + p[i];
return seed;
} srand ( time_seed() );

View 2 Replies View Related

C++ :: Accessing Poisson Distribution Template?

Jun 21, 2013

I am using QT Creator 2.4.1 based on 4.7.4.

I wanted to generate a standard normal poisson distribution. So I used the template poisson distribution included in the header <random> by setting the value of mean to 0 and variance to 1.

I copied the entire example code for testing it but I get an error like "This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options."

View 4 Replies View Related

C++ :: Use Construct Object (Shape) Efficiently?

Jun 27, 2014

have a problem with my code (I wish for answer with code). The conditions I have to grant:

- **Only** a pointer to an object must be saved in a **standard** class vector (e.g vector<ShapePtr>)
- Base class must be a polymorphic class (I call this class ShapePtr)
- I **must** have a deep copy process
- Constructor is **not** suppose to do a deep copy
- **clone()** is suppose to do the deep copy

Here is the code **provided** to me:

main.cpp
int main() {
typedef shared_ptr<Shape> ShapePtr;
vector<ShapePtr> shapevec;

[Code].....

View 1 Replies View Related

C :: Normal Distribution Histogram - Random Numbers

Feb 6, 2013

Write a function that generates 1000 normally distributed (Gaussian Probability Distribution) random numbers. Range should be between -3 and +3. Numbers should be double floating point.

There's more to it than that, but I've got it from there.

View 7 Replies View Related

C++ :: Generate Skew Distribution Random Number?

May 27, 2013

How to generate a skew distribution random number? Or is there any place having refer the skew distribution random number?

View 2 Replies View Related

C++ :: Generating Random Number Of Normal Distribution

Mar 12, 2013

I am generating random number of normal distribution (0,1) but i suspect maybe I have done it wrong. The generator I use right now is

srand(time(0));
std::random_device rd;
std::mt19937 gen(rd());
std::default_random_engine generator;
std::normal_distribution<double> distribution(0,1);

Am I doing the right thing? Whether this is a real random number generator?

View 4 Replies View Related

C++ :: Triangular Distribution For Creating Momentum Four Vector

Nov 12, 2014

In my problem I am to create a base class to represent a four vector (a concept in physics involving a four dimensional vector) then create a derived class specifically to represent the four momentum of a particle which inherits from the base class. I have been supplied a small piece of code to use to generate a 'random' x y and z component of the momentum magnitude. The code is as follows

#include <cstdlib>
double triangular(double momentum){
double x, y;
do{
x = momentum*rand()/RAND_MAX;
y = x/momentum;
} while (1.0*rand()/RAND_MAX > y);
return x;
}

It is said in my problem that this code is supposed to generate the magnitude, and then randomly split into x, y and z components. This code returns a single value and so I cannot see how it is doing what it says in the problem.

View 2 Replies View Related

C/C++ :: Why Cannot Use Variables Inside A Case In Switch Construct

Feb 26, 2015

If I have an integer variable like int a=9 then in the switch case If i write :

switch(a) {
case 4+a: printf("hii");
}

Then why is this statement a compile-time error that variables cannot be used inside a case statement why does the compiler not subtitutes the values in place of the variables.

View 1 Replies View Related

C :: Void Functions With If Else Construct Not Printing Multiple Lines

Apr 12, 2014

This code i made is a cent converter from 5 to 95 cents. The problem i'm receiving is when the 'cents' function is sent back to the 'main' function it only prints one line. It seems to just print the first if construct that complies with the statement. Is there anyway i can have this function print multiple cent values? For example if 60 cents was entered it would only print '50c', and i want it to print '50c' and '10c' instead.

Code:

#include <stdio.h>
int x;
void check(int x)
{
if( x < 5)
printf("Less then 5 cannot be calculated
");
else if(x > 95)

[code]....

View 3 Replies View Related

C :: Read Characters From User Input And Construct A String

Mar 13, 2013

how to read characters from user and construct a sting and then extract part of it using substring?

View 2 Replies View Related

C++ :: How To Generate Real Random Number From Normal Distribution

Jun 26, 2013

I want to generate random numbers of normal distribution and use scentence like

std::default_random_engine generator;
std::normal_distribution<double> distribution(0,1);
arrayX[i][j]=distribution(generator);

But I find that each time the array I got are the same. So how should I generate random numbers with different seedings with normal distribution?

View 2 Replies View Related

C++ :: Produce Normal Distribution Random Number Several Times

Aug 22, 2014

I wrote the following program shown below that produces a normally distributed random number several times, and then takes the average of them. The problem that I have been having though is that the output it has been producing is 0.0288385 despite the fact that I set the mean of the normal distribution to be 0.1. Why this output value would be so far off from 0.1 despite having averaged over such a large number of random numbers namely 10,000 of them? Also, how to randomly seed this random number generator such that it gives a different value each time its run perhaps by seeding it with the windows timer? Below is the program.

#include <iostream>
#include <random>
using namespace std;
int main() {
default_random_engine generator;
normal_distribution<double> distribution1(0.1,3.0);
double number1,sum,n;

[code].....

View 2 Replies View Related

C++ :: Reducing The Size Of A Compiled Executable For Easier Distribution?

Jun 19, 2014

I am looking at reducing the size of a compiled executable for easier distribution.

What factors affect the size of an output executable?

Would literally having defined and implemented less functions, would make the exec. smaller? Meaning that instead of have a DLL ( yes im on windows ), I would download the source code of a library and comment out the functions ( and code ) that I am not using -- Would this process decrease the size of my exec.?

View 2 Replies View Related

C++ :: Construct A Program Without Main Function That Output Stars

Nov 5, 2013

I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.

void output_stars(int num){
if (num > 0){
cout << "*";
output_stars(num-1)

[Code] ....

The program is working the way it should i just can't figure out how to output the number and a colon. The main function is written as such:

output_stars(1);
output_stars(2);
output_stars(5);
output_stars(3);
output_stars(4);
output_stars(7);

How to get the numbers of the main function to show up with the stars of the previous function.

View 6 Replies View Related

C/C++ :: Irrational Results In Bounded Pareto Distribution Code

Jan 24, 2015

I wrote the bounded pareto distribution and I add it to simulator but I have irrational results (job sizes between 0.00000-1.1111)

double b_pareto(k,q)
double k; // the K vaue represents a lower limit of job size
double q; // the q vaue represents an upper limit of job size {
double a = 1.5; // alpha value
double rv; // the Returened Value

[Code] ....

View 4 Replies View Related







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