Posts by Alexandre Cartaxo • 1,338 points
24 posts
-
2
votes1
answer115
viewsA: Vector calculus C++
There’s the Boost and the Armadillo. See also "Numerical Recipes in C++" here, a classic of numerical computational analysis that any scientist or engineer should read.…
-
7
votes2
answers1071
viewsA: Show more accuracy in C++
Utilizes setprecision in this way: #include <iostream> #include <cmath> #include <iomanip> #include <limits> // Para ter a máxima precisão using namespace std; int main(){…
-
2
votes3
answers790
viewsA: Increase Precision with Bigdecimal Java
Very succinctly: Mathcad (or other programs) use a different number of significant digits for both calculations and error function values. The values for the function used by Erf.java are here and…
-
1
votes3
answers1888
viewsA: A: Remove columns from a dataframe
There is still another way, a little more obscure: df[setdiff(names(df), "z")]
ranswered Alexandre Cartaxo 1,338 -
2
votes3
answers1888
viewsA: A: Remove columns from a dataframe
The most practical form is as follows: df$z <- NULL.
ranswered Alexandre Cartaxo 1,338 -
6
votes2
answers57
viewsA: A: problems with Sort (NA)
Just do it this way, using na.last=FALSE for the missing values to appear at the beginning, na.last=TRUE to emerge at the end, when na.last=NA is the default value of this parameter: > x [1] "b"…
-
5
votes1
answer4170
viewsA: How to draw elements (select elements randomly) from an array?
To draw, for example, ten values of the vector in question in pseudo-random form, one can do the following: numeros <- c(1,2,45,63,29,100,999,23.45,76.1) sample(numeros,size=10, replace=TRUE)…
ranswered Alexandre Cartaxo 1,338 -
3
votes1
answer592
viewsA: What is a random seed?
Quick response: because they changed the algorithm for the Mersenne Twister. A random seed is any number or vector used to initialize a pseudo-random number generator which, in turn, is a…
random-numbersanswered Alexandre Cartaxo 1,338 -
3
votes2
answers431
viewsA: Count elements in a range of values
It will certainly not be the most concise form, but avoids using a cycle to traverse all elements of the vector. In this case a language algorithm is used (defined in the header <algorithm>)…
-
5
votes2
answers1800
viewsA: Can I use "Cin" and "getline" in the same code?
After using cin with the extractor << should be used cin.ignore(1000,'\n') to remove the \n left in the buffer associated with reading the values entered on the keyboard (not to read…
c++answered Alexandre Cartaxo 1,338 -
2
votes2
answers1954
viewsA: Question about logical operators
Designating, respectively, the numPatos, numCoelhos, numPes and numCabecas the numbers of ducks, rabbits, feet and heads, it is easy to see that 2*numPatos + 4*numCoelhos = numPes and that numPatos…
c++answered Alexandre Cartaxo 1,338 -
6
votes1
answer753
viewsA: How to Classify a Triangle
Just do this: if (a == b && b == c) { cout << "Triangulo equilatero." << endl; } else if(a == b || b == c){ cout << "Triangulo isosceles." << endl; } else cout…
-
4
votes1
answer2062
viewsQ: Exponentiation operator in C++
About a question recently asked and answered: there is some reason - historical or not - why C++ (as well as many other programming languages) does not include an operator for exponentiation? For…
-
6
votes3
answers11601
viewsA: How to calculate the Euclidean distance
I would do so, taking advantage of most of your code, using hypot(x,y) (only from C++11) which returns the square root of the quadratic sum of x and y: #include <iostream> #include…
-
1
votes1
answer672
viewsA: R-Studio - Package installation error
Try to make install.packages(file.choose(), repos=NULL). The command file.choose() will allow you to choose the file .zip concerned.
-
2
votes1
answer1121
viewsA: Package installation in Rstudio
You need to change the permissions of the specified folder (assuming you have permission to do so): goes to the folder in question Right-click on the mouse icon Choose "Properties" Tab "Security"…
rstudioanswered Alexandre Cartaxo 1,338 -
1
votes1
answer2492
viewsA: Recursive functions in C++: examples
Here’s a program I wrote some time ago to teach functions, in particular to exemplify the difference between normal (using an iterative algorithm) and recursive functions. In this case, it is…
-
6
votes2
answers745
viewsA: Set values or not in c++variables
In the presented case, both variables would be initialized with the value 0 (in the first case explicitly and, in the second, because it is the missing value for variables of the type in question).…
-
7
votes1
answer1131
viewsA: Complex numbers in C++
There is yes: #include <iostream> #include <complex> using namespace std; int main(){ complex<double> a={2,7}, b={5,9}; cout << "Soma: " << a+b; }…
-
3
votes3
answers2257
viewsA: Which loop is faster in C: while or for?
The differences - if any - are not significant, even for a large number of data. The choice between one structure and another relates more to the programmer’s style and/or readability of the code…
-
4
votes7
answers1690
viewsA: Hexadecimal for RGB
In C++ // Este programa não converte entre as bases decimal e hexadecimal // Apenas altera a representação dos inteiros #include <iostream> using namespace std; int main(){ unsigned int…
-
8
votes1
answer196
viewsA: Rstudio: do not automatically load variables in Environment
There is. Go to Tools menu -> Global options -> Restore . Rdata into Workspace at startup.
-
3
votes3
answers221
viewsA: C++ challenge, helps with logic
This is the implementation of the programme: #include<iostream> #include <cmath> using namespace std; double serieDePotencias(double x, unsigned int n){ double resultado=0; for (int i=1;…
c++answered Alexandre Cartaxo 1,338 -
1
votes1
answer708
viewsA: How to convert percentages to C?
This is not an answer - I don’t have a reputation for comment yet: it’s just a comment. Your code is very pasty and redundant. I suggest that, first of all, you take the time to reform it. For…
canswered Alexandre Cartaxo 1,338