IT 代写 Ulrich Conrad_programs and manifestoes
100%原创包过,高质代写&免费提供Turnitin报告--24小时客服QQ&微信:120591129
Declaration: This is all my own work.
Question 1
Header file
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <malloc.h>
double *makeVector(int N)
{
double *X;
X=(double *)malloc((N)*sizeof(double));
return(X);
}
double *MakeWpowers(int N);
MakeWpowers File
#include "q1_header.h"
double *MakeWpowers(int N)
{
int j;
double *w;
double PI=3.14159265358979323846264338327950288;
w=makeVector(2*N);
for(j=0;j<=N-1;j++)
{
w[j*2]=cos(2*j*PI/N);
w[j*2+1]=sin(2*j*PI/N);
}
return(w);
}
Question 2
Header File
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <malloc.h>
#include "q1_header.h"
void complexMultiply(double * c1,double *c2, double * result)
{
*result=(*c1)*(*c2)-(*(c1+1))*(*(c2+1));
*(result+1)=(*c1)*(*(c2+1))+(*c2)*(*(c1+1));
FmCN++;
FmRN+=4;
FpRN+=2;
}
void complexAdd(double *c1,double * c2,double * result)
{
*result=*c1+*c2;
*(result+1)=*(c1+1)+*(c2+1);
FpCN++;
FpRN+=2;
}
void DFS(double *x, double *y,int N)
{
double **CN;
CN=makeCN(N);
complexMatrixVectorMultiply(CN,y,N,N,x);
}
void FastDFS(double *x,double *y,double *w,double *Wp,int N,int skip);
FastDFS file
#include "q2_header.h"
void FastDFS(double *x,double *y,double *w,double *Wp,int N,int skip)
{
int i,j;
if (N==1)
{
memcpy(x,y,2*sizeof(double));
}
else if (N % 2 && N!=1)
{
/*multiply the matrix directly*/
DFS(x,y,N);
}
else
{
/*place ye and yo in w,from head to tail.*/
for (i=0;i<N;i=i+2)
{
memcpy(w+i,y+2*i,2*sizeof(double));
}
for (i=0;i<N;i=i+2)
{
memcpy(w+(i+N),y+(2*i+2),2*sizeof(double));
}
FastDFS(x,w,y,Wp,N/2,skip*2);//the even half of x, i.e., xe
FastDFS(x+N,w+N,y+N,Wp,N/2,skip*2);//the odd half of x, i.e., xo
memcpy(w,x,sizeof(double)*2*N);//copy the value of xe,xo into w.
for(j=0;j<N;j+=2)
{
double temp[2]={0,0};
complexMultiply(&Wp[j],&w[j+N],&temp);
complexAdd(&w[j],&temp,&x[j]);
complexMultiply(&Wp[j+N],&w[j+N],&temp);
complexAdd(&w[j],&temp,&x[j+N]);
}
}
}