Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Which could be a good method to compute the distance between a cluster and a point to decide if the point can be assigned to the cluster?
I read about Mahalanobis distance that I have implemented in this way:
float mahalanobis(float *cluster, float *point, const float *variance, int d) {
float distance=0;
for (int i = 1; i < d; ++i) {
distance+=pow((point[i] - cluster[i])/variance[i-1], 2);
}
return sqrt(distance);
}
but it seems that the result isn't good. Maybe I'm wrong about the implementation
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
i am making a program in C where i ask the user 10 questions and i have a list of 20 questions. I want the machine to randomly pick and ask any 10 questions. Can anyone help me how to do that?
As an outline:
struct Q {
char *q;
int hasbeenselected;
} q[20];
int n;
//
// fill q with your questions and set hasbeenselected to 0;
srand(time(NULL));
for (int i=0; i<10; i++) {
do {
n= rand()%20;
} while (q[n].hasbeenselected==1);
// now ask question q[n].q
q[n].hasbeenselected= 1;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How can I write 3 cosĀ² 2x with C?
Assuming x is in radians :
3*pow(cos(2*x),2)
Here is a function for your purpose:
#include <math.h>
double f(double x) {
double c = cos(2 * x);
return c * c * 3;
}
First compute cos 2x, then square the result and multiply by 3.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So I need to calculate the determinant matrix on 2x2 matrix, simple one..
If you can, please write the code, because i don't understand like in the other thread, it's like i'm reading an English Literature + Code..
#include<stdio.h>
int main(){
int x[2][2]={{1,2},{3,4}};
int i,j,d;
for(i=0;i<=1;i++){
for(j=0;j<=1;j++){
printf(" %d ", x[i][j]);
}
printf(" \n");
}
return 0;
}
Thank You!
You don't need a loop to calculate the determinant of a 2x2 matrix, simply use:
int result = (x[0][0] * x[1][1]) - (x[0][1] * x[1][0]);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I just wonder how to find mean of two numbers without using division.
do not use these conditions :
int mean = (a + b) >> 1;
four fundamental arithmetic operations
I think this may be helpful -->
int a,b,i,j;
if (a>b)
{
int temp = a;
a = b;
b = temp;
}
for(i=a,j=b;i<j;i++,j--)
continue;
if(i==j)printf("%d\n", i);
else printf("%lf\n", (double)(i)-0.5);
Add them then multiply by 0.5 , no division involved.
If they're both integers, you can use a right shift:
int median = (a + b) >> 1;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am having difficulty getting the real output from a C function. For example:
int max3(int a, int b, int c){
if ((a>b)&&(a>c))
return a;
if ((b>c)&&(b>a))
return b;
return c;
}
Can you give me an idea of how to specify the real output (e.g. tools, algorithms, etc.)?
In this above example, the real output is 6 (in case (a,b,c) = (1,2,6)).
Thank in advance very much.
I'd have probably written it, as it is simple, using the ternary operator:
int max3(int a, int b, int c){
if (a>b)
return (a>c)?a:c;
else
return (b>c)?b:c;
}