1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long choix = 0;
double thf = 0;
long racine = 0;
while(choix==0)
{
system("cls");
cout << "Welcome to the complex roots calculating program\n\n" << endl; // INTRODUCTION
cout << "A complex is a number such as a+ib, where a is the real part, and b the imaginary part.\n\n" << endl;
cout << "-----------------------------------------------------------------------------------------\n\n" << endl;
cout << "!! WARNING : SOLUTIONS ARE GIVEN IN RADIANS !! \n\n" << endl;
long i = -1;
double a = 0;
cout << "a=" << endl; // On demande a, la partie réelle du complexe
cin >> a;
double b = 0;
cout << "b=" << endl; // On demande b, la partie imaginaire du complexe
cin >> b;
if(b<0) // Afichage du complexe selon le signe de la partie imaginaire
{
cout << "The complex number you introduced is : " << a << b << "i" << endl;
}
else
{
cout << "The complex number you introduced is : " << a << "+" << b << "i" << endl;
}
cout << "\n\n" << endl;
cout << "Which root of this complex do you want to compute (integer) ?" << endl; // On demande à l'user quelle racine il veut calculer du complexe ; cette dernière sera stockée dans racine
cin >> racine;
cout << "Computing ..." << endl;
cout << "Calculating tan of theta..." << endl; // Calcul de la tangente de théta, essentielle pour déterminer la forme trigonométrique du complexe
double th = 0;
double tgth = 0;
double PI = 3.14159265358979323846;
if(a==0) // Cas où z = i (car a=0 et b=1)
{
th = PI/2;
}
else // Cas où z est différent de i
{
tgth = (b/a); // Calcul de la tangente de théta
th = atan(tgth); // Calcul de théta (en radians)
}
cout << tgth << endl;
cout << "Calculating theta..." << endl; // Calcul de la tangente de théta, essentielle pour déterminer la forme trigonométrique du complexe
cout << th << endl;
cout << "Calculating ro ... " << endl;
double ro = 0;
ro=sqrt(pow(a, 2)+pow(b, 2)); // Calcul de rô (fonctionnel, non arrondi.)
cout << ro << endl;
cout << "\n" << endl;
cout << "Computing trigonometrical forms ... \n" << endl;
double r = 0;
cout << "z=[" << ro << "].[cos(" << th << "+2k.pi)+i.sin(" << th << "+2k.pi)]" << endl; // Propriété d'un complexe sous sa forme trigonométrique (le complexe z est le complexe dont on veut calculer la racine nième, n étant donné par l'user)
cout << "Z^" << racine << "= [r^" << racine << "].[cos(" << racine << ".beta)" << "+i.sin(" << racine << ".beta)]" << endl; // Le complexe Z est le complexe qui va nous permettre de calculer la racine nième -n étant donné par l'user- du complexe z
cout << "Egalizing real parts ...\n" << endl;
cout << "Calculating r..." << endl;
r=pow(ro, pow(racine, (-1))); // Calcul de r : r^racine = ro ; du coup, r = racine racinième de ro, donc ro^(1/racine)
cout << r << endl;
cout << "Egalizing imaginary parts ... \n" << endl;
cout << "Calculating beta..." << endl;
double bt1 = 0;
bt1=(th)/(racine); // Calcul de béta : béta est en deux parties : la 1ère (bt1), est calculée en divisant théta (th) par la racine, puisque racine.beta = théta
double bt2 = 0;
bt2=(2)/(double) (racine); // Car on démarre toujours avec 2kpi dans la parenthèse : ceci est la deuxième partie de béta (bt2)
cout << bt1 << "+" << bt2 << ".k.pi" << endl;
cout << "Computing a Z expression ...\n" << endl;
cout << "Z_k = [" << r << "].[cos(" << bt1 << "+" << bt2 << ".k.pi)+i.sin(" << bt1 << "+" << bt2 << ".k.pi)]" << endl; // C'est l'expression généralisée d'indice k, où k sera incrémenté plus loin, variant entre 0 et (racine-1)
printf("Calculating roots ... \n");
double k = 0;
while(k<racine)
{
do
{
cout << "Z_0 = [" << r << "].[cos(" << bt1 << ")+i.sin(" << bt1 << ")]" << endl; // Première racine, d'indice 0, et comme l'indice vaut k, k.pi = 0, et bt2 disparaît donc, voilà pourquoi il existe une seule boucle pour Z_0
k++;
}while(k==0);
thf=bt2*k;
while(k<(racine-1)) // On affiche les racines situées entre la deuxième (comprise) et l'avant-dernière (comprise)
{
cout << "Z_" << k << "=[" << r << "].[cos(" << bt1 << "+" << thf << ".pi)+i.sin(" << bt1 << "+" << thf << ".pi)]" << endl;
k++;
}
if(k=(racine-1)) // On affiche la dernière racine du complexe, et le choix de quitter, ou non
{
cout << "Z_" << k << "=[" << r << "].[cos(" << bt1 << "+" << thf << ".pi)+i.sin(" << bt1 << "+" << thf << ".pi)]" << endl;
cout << "This is the end of the program - roots were calculated. Do you want to quit (0 to stay, 1 to quit) ? (0/1)" << endl;
cin >> choix;
if(choix==1)
{
cout << "Goodbye !" << endl; // Si l'user veut quitter
exit(EXIT_SUCCESS);
}
else
{
choix=0;
k=racine+1;
}
}
}
}
} |
Partager