Commit 3d427ad2 authored by Antoine Joncheray's avatar Antoine Joncheray

Initial commit

parents
Pipeline #2163 canceled with stages
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
\ No newline at end of file
{
"files.associations": {
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"type_traits": "cpp",
"cmath": "cpp",
"limits": "cpp",
"new": "cpp",
"complex.h": "c"
}
}
\ No newline at end of file
CC = gcc
all: ./obj/main.o ./obj/complex.o ./obj/transfer.o
gcc ./obj/main.o ./obj/complex.o ./obj/transfer.o -o./bin/main -lm
./obj/main.o: ./src/main.c
gcc ./src/main.c -c -I./include -o./obj/main.o
./obj/complex.o: ./src/complex.c
gcc ./src/complex.c -c -I./include -o./obj/complex.o
./obj/transfer.o: ./src/transfer.c
gcc ./src/transfer.c -c -I./include -o./obj/transfer.o
\ No newline at end of file
# Questions
- [x] Question 1
- [x] Question 2
- [x] Question 3
- [x] Question 4
- [x] Question 5
- [x] Question 5.1
- [x] Question 5.2
- [x] Question 5.3
- [x] Question 5.4
- [x] Question 6
- [x] Question 7
- [x] Question 8
- [x] Question 9
- [ ] Question 10
File added
#if !defined(CMPLX)
#define CMPLX
typedef struct {
// Définition d'un type correspondant aux nombres complexes
double real;
double imag;
} Cmplx, *LPCmplx;
extern int InitCmplx(Cmplx *, double, double);
extern int DisplayCmplx(Cmplx *);
extern int GetCmplx(Cmplx *);
extern int ConjCmplx(Cmplx *, Cmplx *);
extern int ModCmplx(Cmplx *, double *);
extern int ArgCmplx(Cmplx *, double *);
extern int SumCmplx(Cmplx *, Cmplx *, Cmplx *);
extern int SubCmplx(Cmplx *, Cmplx *, Cmplx *);
extern int MulCmplx(Cmplx *, Cmplx *, Cmplx *);
extern int DivCmplx(Cmplx *, Cmplx *, Cmplx *);
extern int PowCmplx(Cmplx *, int, Cmplx *);
extern int EvalPoly(double *, int, Cmplx *, Cmplx *);
#endif
\ No newline at end of file
#if !defined(TRANSFER)
#define TRANSFER
#include "../include/complex.h"
typedef struct {
// Structure correspondant à une fonction de transfert
double *num; // Tableau des coefficients du polynôme numérateur
int degreNum; // Taille du tableau num
double *denum; // Tableau des coefficients du polynôme dénominateur
int degreDenum; // Taille du tableau denum
} Transfer, *LPTransfer;
extern int FreqEval(Transfer *, double, Cmplx *);
extern int GainAndPhase(Transfer *, double, double, double);
#endif
\ No newline at end of file
File added
File added
File added
#include <stdio.h>
#include <math.h>
#include "../include/complex.h"
int InitCmplx(Cmplx *ptr, double real, double imaginary){
ptr->real = real;
ptr->imag = imaginary;
return 0;
}
int DisplayCmplx(Cmplx *complex) {
if(complex->imag >= 0) {
printf("%lf + %lfj\n", complex->real, complex->imag);
} else {
printf("%lf - %lfj\n", complex->real, -(complex->imag));
}
return 0;
}
int GetCmplx(Cmplx *ptr) {
double real;
double imaginary;
printf("Entrez la partie réelle : ");
scanf("%lf", &real);
printf("Entrez la partie imaginaire : ");
scanf("%lf", &imaginary);
InitCmplx(ptr, real, imaginary);
return 0;
}
int ConjCmplx(Cmplx *ptr, Cmplx *conjugate) {
InitCmplx(conjugate, ptr->real, -(ptr->imag));
return 0;
}
int ModCmplx(Cmplx *ptrCmplx, double *ptrDouble) {
*ptrDouble = sqrt(ptrCmplx->real*ptrCmplx->real + ptrCmplx->imag*ptrCmplx->imag);
return 0;
}
int ArgCmplx(Cmplx *ptrCmplx, double *ptrDouble) {
if(ptrCmplx->real > 0) {
*ptrDouble = atan2(ptrCmplx->imag, ptrCmplx->real);
} else if(ptrCmplx->real == 0 && ptrCmplx->imag > 0) {
*ptrDouble = 3.14159/2;
} else if(ptrCmplx->real == 0 && ptrCmplx->imag < 0) {
*ptrDouble = -3.14159/2;
} else if(ptrCmplx->imag == 0 && ptrCmplx->real == 0) {
*ptrDouble = 0;
} else {
*ptrDouble = 3.14159 + atan2(ptrCmplx->imag, ptrCmplx->real);
}
}
int SumCmplx(Cmplx *ptr1, Cmplx *ptr2, Cmplx *newPtr) {
InitCmplx(newPtr, ptr1->real + ptr2->real, ptr1->imag + ptr2->imag);
return 0;
}
int SubCmplx(Cmplx *ptr1, Cmplx *ptr2, Cmplx *newPtr) {
InitCmplx(newPtr, ptr1->real - ptr2->real, ptr1->imag - ptr2->imag);
return 0;
}
int MulCmplx(Cmplx *ptr1, Cmplx *ptr2, Cmplx *newPtr) {
double newReal = (ptr1->real)*(ptr2->real) - (ptr1->imag)*(ptr2->imag);
double newImaginary = (ptr1->imag)*(ptr2->real) + (ptr1->real)*(ptr2->imag);
InitCmplx(newPtr, newReal, newImaginary);
return 0;
}
int ScalarMulCmplx(Cmplx *ptr, double scalar, Cmplx *newPtr) {
InitCmplx(newPtr, ptr->real*scalar, ptr->imag*scalar);
}
int DivCmplx(Cmplx *ptr1, Cmplx *ptr2, Cmplx *newPtr) {
// Divise ptr1 par ptr2
double tempMod;
ModCmplx(ptr2, &tempMod);
tempMod = tempMod * tempMod;
Cmplx tempConjugate;
ConjCmplx(ptr2, &tempConjugate);
MulCmplx(ptr1, &tempConjugate, newPtr);
newPtr->real = newPtr->real / tempMod ;
newPtr->imag = newPtr->imag / tempMod ;
return 0;
}
int PowCmplx(Cmplx *ptr, int power, Cmplx *newPtr) {
if(power == 0) {
InitCmplx(newPtr, 1, 0);
return 0;
} else if(power < 0) {
printf("Mets un entier positif stp\n");
return 0;
} else {
MulCmplx(ptr, ptr, newPtr);
for(int i = 2; i < power; i++) {
MulCmplx(newPtr, ptr, newPtr);
}
return 0;
}
}
int EvalPoly(double *coeff, int degree, Cmplx *point, Cmplx *result) {
InitCmplx(result, coeff[0] + coeff[1]*point->real, coeff[1]*point->imag);
for (int i = 2; i < degree; i++) {
Cmplx tempCmplx;
// Met le point à la puissance correspondante
PowCmplx(point, i, &tempCmplx);
// Multiplie par le coefficient
ScalarMulCmplx(&tempCmplx, coeff[i], &tempCmplx);
// Ajoute le produit au résultat
SumCmplx(result, &tempCmplx, result);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../include/complex.h"
//#include "../include/transfer.h"
int main(void) {
// Test des fonctions multiplier et diviser
Cmplx complex1;
Cmplx complex2;
InitCmplx(&complex1, 1, 1);
InitCmplx(&complex2, 3, 5);
Cmplx multComplex;
MulCmplx(&complex1, &complex2, &multComplex);
Cmplx divComplex;
DivCmplx(&complex1, &complex2, &divComplex);
DisplayCmplx(&multComplex);
DisplayCmplx(&divComplex);
// Test de la fonction puissance
Cmplx testPow;
InitCmplx(&testPow, 3, 1);
Cmplx powComplex;
PowCmplx(&testPow, 2, &powComplex);
DisplayCmplx(&powComplex);
// Test de l'évaluation d'un polynôme en un point
Cmplx testPolynomial;
int degree = 3;
double coefficients[3] = {1, 3, 2};
Cmplx point;
InitCmplx(&point, 2, 1);
EvalPoly(coefficients, degree, &point, &testPolynomial);
printf("Résulat de l'évaluation du polynôme ;\n");
DisplayCmplx(&testPolynomial);
return 0;
}
\ No newline at end of file
#include "../include/complex.h"
#include "../include/transfer.h"
#define PI 3.14159
int FreqEval(Transfer *transfer, double freq, Cmplx *result) {
Cmplx point;
InitCmplx(&point, 0, 2 * PI * freq);
Cmplx valNum;
Cmplx valDenum;
EvalPoly(transfer->num, transfer->degreNum, &point, &valNum);
EvalPoly(transfer->denum, transfer->degreDenum, &point, &valDenum);
// Retourne la division de l'expression du polynôme numérateur
// à la pulsation donnée par l'expression du polynôme dénominateur
DivCmplx(&valNum, &valDenum, result);
return 0;
}
int GainAndPhase(Transfer *transfer, double valInit, double stepFreq, double finalFreq) {
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment