Wikilivres
frwikibooks
https://fr.wikibooks.org/wiki/Accueil
MediaWiki 1.45.0-wmf.9
first-letter
Média
Spécial
Discussion
Utilisateur
Discussion utilisateur
Wikilivres
Discussion Wikilivres
Fichier
Discussion fichier
MediaWiki
Discussion MediaWiki
Modèle
Discussion modèle
Aide
Discussion aide
Catégorie
Discussion catégorie
Transwiki
Discussion Transwiki
Wikijunior
Discussion Wikijunior
TimedText
TimedText talk
Module
Discussion module
Jouer à World of Warcraft/Instances
0
35835
746448
280016
2025-07-10T13:31:04Z
2A02:8440:7151:B0FF:9364:A9C0:9A52:D7B5
Orthographe
746448
wikitext
text/x-wiki
{{lang|en|''World of Warcraft''}} comporte des « [[Donjon (jeu de rôle)|donjons]] » (aussi appelés {{guil|instances}}) de haut niveau, dites {{guil|HL}} pour {{lang|en|''high-level''}}, réservées aux joueurs disposant de personnages ayant atteint le niveau maximal et possédant un équipement adapté à ce genre d’évènements.
Si avant la sortie de la première extension, les groupes de raid pouvaient atteindre jusqu’à {{nombre|40|joueurs}}, désormais les instances et les raids varient entre 5 et {{nombre|25|joueurs}}.
Les joueurs qui parcourent ces instances y vont généralement en guilde ou en alliance de guildes. La constitution de ces guildes représente la plus grosse difficulté HL. Une fois équilibrée celle-ci peut progresser régulièrement. C’est une conséquence de la difficulté d’implication de nombreux joueurs dans un but unique. Les instances de HL offrent des contenus suffisamment longs pour retenir l’essentiel des guildes jusqu’aux prochaines extensions.
Généralement un joueur désirant finir le jeu devra déposer une candidature auprès d’une guilde puis suivre un entretien et une période d’essai avant d’en devenir membre et de progresser vers la fin du contenu HL. Selon la guilde, le recrutement sera plus ou moins exigeant. Généralement les recruteurs des guildes HL s’intéressent aux contraintes de temps de jeu du joueur, de sa régularité, de sa ponctualité, de son âge, de ses expériences de donjons HL, de sa capacité à s’investir pour la communauté de joueur de sa guilde, de sa progression dans l’équipement de ses personnages… Il n’est pas rare de voir des guildes d’environ {{nombre|100|personnages}} (ce nombre a notablement diminué à la sortie de BC comme il n’y a plus de raid pour {{nombre|40|joueurs}}). Une hiérarchie est de rigueur et nombre d’entre-elles utilisent des outils externes au jeu pour l’organisation (site web, planning, téléphonie internet, rencontre dans le monde réel…). Souvent derrière les grosses guildes HL se cache un noyau dur de joueurs se connaissant en dehors du jeu et capables de mettre en œuvre ces outils externes.
La mort d’un {{lang|en|''World Boss''}} est félicitée, et peut être diffusé sur des sites dédiés à WoW.
Elles sont régulièrement ajoutées au jeu par le biais de [[patch (informatique)|patchs]].
==== Autres rencontres de raid HL ====
Dans {{lang|en|''World of Warcraft''}} classique, des boss sont disponibles en extérieur. Ce sont Kazzak, Azuregos et les dragons du cauchemar (Taerar, Emeriss, Léthon et Ysondre). Ces boss sont appelés {{lang|en|''World Boss''}} (WB).
Avec {{lang|en|''The Burning Crusade''}}, de nouveaux {{lang|en|''World Boss''}} extérieurs ont fait leurs apparitions dans le jeu.
Notamment une nouvelle version du seigneur funeste Kazzak, au nord-est de la péninsule des flammes infernales et Marche Funeste, une machine de guerre créée par la Légion Ardente visible dans la vallée d’Ombrelune.
== Notes et références ==
=== Notes ===
<references group="Note"/>
=== Références ===
<references/>
[[Catégorie:Jouer à World of Warcraft (livre)]]
tdshpqbe7jbxjr9vk04fsnahogpgrgz
Programmation PHP/Fichiers
0
65675
746464
745270
2025-07-11T08:20:52Z
JackPotte
5426
/* Lecture */
746464
wikitext
text/x-wiki
<noinclude>
{{PHP}}
</noinclude>
L'utilisation de fichier peut être utile pour exporter des données à archiver ou accélérer un traitement par un système de cache. Cette page explique comment interagir avec un fichier.
== Dossiers ==
Voici les fonctions usuelles de navigation et manipulation du système de fichier.
=== Lecture ===
* <code>PHP_OS</code> : contient de système d'exploitation courant (ex : WINNT, Linux).
* <code>basename($path)</code> : extraire le nom du fichier à partir de son chemin.
* <code>dirname(__DIR__)</code> : extraire le répertoire parent du dossier en paramètre, au niveau précisé en second paramètre (le parent direct par défaut).
* <code>chdir($dossier)</code> : changer de dossier courant ;
* <code>opendir($dossier)</code> : ouvrir un dossier ;
* <code>closedir($dossier)</code> : fermer le dossier ;
* <code>is_dir($dossier)</code> : vérifier la présence d'un dossier ;
* <code>is_file($fichier)</code> : vérifier la présence d'un fichier ;
* <code>file_exists($fichier)</code> : vérifier la présence d'un fichier ou un dossier local<ref>http://php.net/manual/fr/function.file-exists.php</ref> ;
* <code>filesize($fichier)</code> : renvoie la taille du fichier en octet<ref>https://www.php.net/manual/en/function.filesize.php</ref> ;
* <code>readdir($dossier)</code> : lire le contenu du dossier ligne par ligne ;
* <code>scandir($dossier)</code> : lire le contenu du dossier en une fois ;
* <code>glob($regex)</code> : lire le contenu du dossier courant, avec filtrage regex (ex : *.txt)<ref>http://php.net/manual/fr/function.glob.php</ref>.
* <code>pathinfo($fichier)</code> : renvoie un tableau avec les caractéristiques du fichier : dossier, nom, extension.
* <code>mime_content_type($fichier)</code> : renvoie le type {{w|MIME}}.
==== Récupérer certains fichiers d'un dossier ====
Par exemple, pour trouver tous les fichiers .sql du dossier "sql" :
<syntaxhighlight lang=php>
chdir('sql');
$files = glob('*.sql');
var_dump($files);
</syntaxhighlight>
=== Écriture ===
* <code>shell_exec('pwd')</code> : exécuter n'importe quelle commande [[Programmation Bash|shell]]. Le nom du répertoire courant (pwd) dans cet exemple.
* <code>mkdir()</code> (''make directory'') : créer un dossier.
* <code>rmdir()</code> (''remove directory'') : supprime un dossier non vide.
* <code>touch()</code> : créer un fichier (ou le rafraichir s'il existe).
* <code>rename()</code> : déplacer un fichier.
{{attention|Les commandes du shell_exec dépendent du système d'exploitation. Par exemple, sur Linux <code>shell_exec('ls')</code> fonctionne mais sur Windows il renvoie null et il faut utiliser <code>shell_exec('dir')</code>.
De plus, sachant que les systèmes d'exploitation n'ont pas les mêmes séparateurs de dossiers (sous Windows on utilise "\" et en unixerie c'est "/"), on peut utiliser la constante prédéfinie : <code>DIRECTORY_SEPARATOR</code> qui fonctionne pour les deux<ref>http://php.net/manual/fr/dir.constants.php</ref>.
}}
{{remarque|1=Pour supprimer un dossier non vide<ref>https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty</ref> :
<pre>
array_map('unlink', glob('your/path/*.*'));
rmdir('your/path');
</pre>
}}
== Droits des fichiers ==
=== Windows ===
Sous Windows il suffit de se rendre dans l'onglet sécurité des propriétés d'un fichier, pour cocher les cases autorisant le programme à le lire et/ou le modifier.
=== Unix ===
''chmod'' est le système de droit d'accès a un fichier {{w|Unix}}. Il s'agit d'un [[w:Permissions_Unix|nombre à trois chiffres]] que l’on attribut à un fichier (ex. : 755). Il détermine le droit d'accès au fichier en question, qui peut le modifier.
Selon sa valeur le {{w|système d'exploitation}} autorise ou non la modification du fichier. Sous GNU/Linux, l'utilisateur 'root', (superutilisateur), a tous les droits, c'est-à-dire qu’il peut modifier tous les fichiers.
Lorsque qu'un fichier est créé manuellement, le ''chmod'' du fichier en question est '''755''', avec un tel ''chmod'' nous ne pouvons pas modifier le fichier avec un script PHP. Pour pouvoir le modifier, il suffit juste de changer le ''chmod'' du fichier, en lui donnant la valeur ''766''. Sous Windows, cette notion est masquée et il suffit d’être administrateur de la machine (utilisateur par défaut) pour pouvoir modifier un fichier.
* Pour récupérer les permissions : <code>fileperms($localFilePath) & 0777</code>
* Le propriétaire : <code>fileowner($localFilePath))</code>
== Ouvrir un fichier ==
Pour déclencher l'ouverture d'un fichier chez celui qui exécute le script, on précise son type puis son emplacement :
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename='".$fichier."'");
</syntaxhighlight>
== Télécharger un fichier ==
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='".$fichier."'");
</syntaxhighlight>
{{attention|Le téléchargement ne doit pas être précédé d'affichages (ex : <code>echo</code> ou logs de warning) sinon ils apparaitront dans l'en-tête du fichier, le rendant illisible.|clear=left}}
== Zipper un fichier ==
=== Installation ===
Cette fonctionnalité est fournie nativement depuis PHP 5.2.0. Par contre sur les versions >= 7 sur Linux il faut l'installer :
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
=== Utilisation ===
Pour compresser des fichiers, il faut d'abord créer l'archive vide, puis les y ajouter un par un avec la méthode <code>addFile(Fichier source, Nom du fichier dans l'archive)</code><ref>http://php.net/manual/fr/ziparchive.addfile.php</ref> :
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f, ZipArchive::CREATE) !== true) {
exit('Impossible de créer le .zip');
}
$zip->addFile('../Temp/' . $nomFichier . '.xls', $nomFichier . '.xls');
$zip->close();
</syntaxhighlight>
=== Dézipper un fichier ===
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f) === true) {
$zip->extractTo('../Temp/');
$zip->close();
}
</syntaxhighlight>
Pour les .gz<ref>https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php</ref> :
<syntaxhighlight lang="php">
private function uncompressFile(string $target): void
{
$uncompressedFileName = str_replace('.gz', '', $target);
$file = gzopen($target, 'rb');
$outFile = fopen($uncompressedFileName, 'wb');
while (!gzeof($file)) {
fwrite($outFile, gzread($file, 4096));
}
fclose($outFile);
gzclose($file);
</syntaxhighlight>
== Éditer et fermer un fichier ==
Créer un fichier avec un attribut ''chmod'' de ''766''. Ensuite il faut ouvrir le fichier en question avant de lire/écrire. Pour cela la fonction ''fopen'' est là :
{{Principe|width=60%
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
</syntaxhighlight>
}}
'''Explication :''' La fonction ''fopen'' à besoin de deux paramètres pour pouvoir s'exécuter :
* $nomFichier, il s'agit du chemin du fichier
* $mode, il s'agit du mode de l'ouverture
La fonction ''fopen'' utilise le premier paramètre, pour déterminer le chemin du fichier a ouvrir/créer.
Voici les différents modes d'ouvertures pour la fonction ''fopen'' :
{| class="wikitable"
! Mode !! Description
|-
| align="center" | r
| (read) Ouvre en lecture seule, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | r+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | w
| (write) Ouvre en écriture seule, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | w+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a
| (append) Ouvre en écriture seule, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a+
|Ouvre en lecture et écriture, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | x
| Créé et ouvre le fichier en lecture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer. Ce mode est l'équivalent des options O_EXCL<nowiki>|</nowiki>O_CREAT pour l'appel système open(2) sous-jacente. Cette option est supportée à partir de PHP 4.3.2 et fonctionne uniquement avec des fichiers locaux.
|-
|-
| align="center" | x+
|Crée et ouvre le fichier en lecture et écriture ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en |générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer.
|-
| align="center" | c
| Ouvre le fichier en écriture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, il ne le tronque pas, sinon il le crée.
|-
|-
| align="center" | c+
| Ouvre le fichier en lecture et écriture, puis se comporte comme "c".
|}
Pour le fermer maintenant, il y a la fonction ''fclose''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
fputs($objetFichier, $contenu);
fgets($objetFichier);
fclose($objetFichier);
</syntaxhighlight>
}}
== Copier un fichier ==
<syntaxhighlight lang="php">
if (!copy($ancienFichier, $nouveauFichier)) {
echo 'La copie a échoué.';
}
</syntaxhighlight>
Pour les images il existe aussi <code>imagecopyresampled</code><ref>http://php.net//manual/fr/function.imagecopyresampled.php</ref>.
== Supprimer un fichier ==
<syntaxhighlight lang="php">
if (!unlink($fichier)) {
echo 'La suppression a échoué.';
}
</syntaxhighlight>
== Interagir avec le fichier ==
=== Lecture ===
Une fois ouvert, il existe plusieurs manière de lire le contenu d'un fichier : caractère par caractère, ligne par ligne, jusqu'à une certaine taille, ou tout entier.
==== Tout le fichier ====
===== file =====
Pour stocker le fichier entier dans un tableau, on peut utiliser ''file()'' qui renvoie un tableau séparant chaque ligne du fichier :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$fichier = file($nomFichier); // ou : file("http://MonSite/" . $nomFichier);
</syntaxhighlight>
}}
Ainsi, ''$fichier[0]'' correspond à la première ligne, ''$fichier[1]'' à la seconde, etc.
Si le fichier sature la mémoire, utiliser file_lines() avec les générateurs<ref>https://www.startutorial.com/articles/view/php-generator-reading-file-content</ref>.
===== file_get_contents =====
Pour stocker le fichier entier dans un scalaire, on utilise cette fonction.
===== readfile =====
Pour afficher tout le fichier dans la sortie standard<ref>https://www.php.net/manual/en/function.readfile.php</ref>.
==== Ligne par ligne ====
===== fgets =====
La méthode générale pour lire ligne par ligne avec la fonction ''fgets'', dont la définition est la suivante :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$ligne = fgets($objetFichier);
</syntaxhighlight>
}}
La variable ''$objetFichier'' doit être le résultat de l'ouverture d'un fichier avec ''fopen''. Pour lire un fichier en entier, il suffit d’utiliser ''fgets'' en boucle ; la condition de sortie de la boucle serait alors l'arrivée à la fin de fichier, évènement notifié par la fonction ''feof''.
{{Exemple
| titre=Exemple de parcours d'un fichier ligne par ligne
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$objetFichier = fopen($nomFichier, "r"); //ouverture en lecture
if ($objetFichier) {
//on lit le fichier tant que la fin n'est pas atteinte
while (!feof($objetFichier)) {
$ligne = fgets($objetFichier);
echo $ligne;
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
===== fgetc =====
La fonction équivalente pour lire caractère par caractère se nomme ''fgetc'' :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$caractere = fgetc($objetFichier);
</syntaxhighlight>
}}
Notez que cette fonction retourne FALSE arrivée à la fin du fichier. Lors d'un parcours, il faut donc tester impérativement la valeur avant de l’utiliser, avec un test logique de la forme « $caractere !== FALSE ».
===== fgetcsv =====
Cette fonction fonctionne comme "fgets" sauf qu'en plus elle utilise le séparateur "," (qui peut être changé par le paramètre "delimiter"<ref>http://php.net/manual/fr/function.fgetcsv.php</ref>) pour créer un sous-tableau de champs par ligne.
=== Écriture ===
Une fois le fichier ouvert, l'écriture se fait via la fonction ''fwrite''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fwrite($objetFichier, $chaine);
</syntaxhighlight>
}}
'''Explication''' :
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $chaine : la chaîne à écrire dans le fichier
* retour : le nombre de caractère écrits, ou FALSE si erreur
L'utilisation est alors la même que pour la lecture : ouvrir le fichier, écrire et fermer.
{{Exemple
| titre=Exemple d'écriture
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$chaine = "Je suis une chaine écrite par PHP !\n"
$objetFichier = fopen($nomFichier, "w"); //ouverture en lecture
if ($objetFichier) {
if(fwrite($objetFichier, $chaine) === FALSE) {
echo "Erreur : impossible d'écrire dans le fichier.";
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
'''Attention :''' Si vous ouvrez le fichier avec l'option ''w'' ou ''w+'', le contenu du fichier sera effacé s'il existait. Pour écrire à la fin, il faut ouvrir avec les options ''a'' ou ''a+'' (voir ci-dessus). Enfin, si vous pouvez avec l'option ''r+'', le contenu sera écrasé, puisque le pointeur de fichier sera placé au début.
Par ailleurs, la fonction ''file_put_contents()'' effectue un ''fopen()'', ''fwrite()'' et ''fclose()'' successivement<ref>http://php.net/manual/fr/function.file-put-contents.php</ref>.
=== Se déplacer ===
Parfois, il peut être nécessaire de se déplacer dans le fichier, par exemple pour revenir au début. Pour cela, il faut utiliser la fonction ''fseek'' comme suit :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, $position);
</syntaxhighlight>
}}
'''Explication :'''
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $position : la position à laquelle on veut se déplacer. Pour revenir au début, $position doit valoir zéro.
Pour aller à la fin :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, 0, SEEK_END);
</syntaxhighlight>
}}
== Fichiers uploadés ==
Copier-coller ces lignes dans un fichier vierge ''upload.php'' pour qu’il affiche le nom des fichiers qu'on upload avec :
<syntaxhighlight lang="php">
<?php
echo '
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fichier">
<input type="submit" name="envoyer" value="Uploader">
</form>';
if (isset($_FILES['fichier'])) {
echo $_FILES['fichier']['name'];
}
</syntaxhighlight>
Il existe la fonction is_uploaded_file() pour vérifier si un fichier est bien issu d'un upload<ref>https://www.php.net/manual/en/function.is-uploaded-file.php</ref>, et move_uploaded_file() pour le déplacer.
== Fichiers temporaires ==
Pour créer des fichiers qui seront automatiquement détruits en fin de connexion, le dossier temporaire est accessible avec : <code>sys_get_temp_dir()</code>.
La fonction <code>tempnam()</code> quant-à elle nomme automatiquement un nouveau fichier temporaire avec un nom unique :
<syntaxhighlight lang="php">
$fileName = tempnam(sys_get_temp_dir(), 'MonFichier1');
</syntaxhighlight>
== Fichiers distants ==
=== HTTP ===
Pour lire un fichier en HTTP (par exemple cette page web) :
<syntaxhighlight lang="php">
<?php
$page = file_get_contents("http://fr.wikibooks.org/wiki/PHP/Fichiers");
echo $page;
</syntaxhighlight>
ou<ref>[http://www.developpez.net/forums/d66310/php/langage/syntaxe/lire-contenu-page-web-grace-script-php/ developpez.net]</ref>
<syntaxhighlight lang="php">
<?php
$url = 'http://fr.wikibooks.org/wiki/PHP/Fichiers';
echo htmlspecialchars(implode('', file($url)));
</syntaxhighlight>
Pour tester si un fichier distant existe, utiliser <code>get_headers()</code><ref>http://php.net/manual/fr/function.get-headers.php</ref>.
{{remarque|fonctionne aussi bien avec HTTPS.}}
=== FTP ===
Installation : dans php.ini, décommenter "extension=ftp" (anciennement "extension=php_ftp.dll").
Déposer un fichier (sans vérifier s'il en écrase un)<ref>http://php.net/manual/fr/book.ftp.php</ref> :
<syntaxhighlight lang="php">
<?php
copy('fichier_local.txt', 'ftp://login:password@server/repertoire/fichier_distant.txt');
</syntaxhighlight>
Souvent le répertoire porte le nom de l'utilisateur, et on écrase le fichier s'il existe :
<syntaxhighlight lang="php">
<?php
$serveur = 'serveur1';
$login = 'utilisateur1';
$password = 'mdp1';
$fichier = 'fichier1';
copy($fichier, 'ftp://'.$login.':'.$password.'@'.$serveur.'/'.$login.'/'.$fichier, stream_context_create(array('ftp' => array('overwrite'=>True))));
</syntaxhighlight>
Fonctions propres au FTP, pour lire un serveur distant, y télécharger et déposer des fichiers<ref>http://php.net/manual/fr/function.ftp-nlist.php</ref> :
<syntaxhighlight lang="php">
$cnx = ftp_connect($serveur);
$loginResult = ftp_login($cnx, $login, $password);
// Liste des noms des dossiers et fichiers du dossier distant (dans le désordre)
$dossierDistant = ftp_nlist($cnx, ".");
var_dump($dossierDistant);
// Liste des éléments du dossier distant avec leurs inodes
$dossierDistant2 = ftp_rawlist($cnx, ".");
var_dump($dossierDistant2);
// Change de répertoire :
var_dump(ftp_pwd($cnx));
ftp_chdir($cnx, 'tmp');
var_dump(ftp_pwd($cnx));
// Téléchargement du dernier fichier distant
sort($dossierDistant);
$distant = $dossierDistant[sizeof($dossierDistant)-1];
$local = 'FichierLocal.txt';
if (!ftp_get($cnx, $local, $distant, FTP_BINARY)) {
echo "Erreur ftp_get\n";
} else {
ftp_delete($cnx, $distant);
}
// Téléversement d'un fichier local
$local = 'FichierLocal2.txt';
if (!ftp_put($cnx, $distant, $local, FTP_ASCII)) {
echo "Erreur ftp_put\n";
}
</syntaxhighlight>
Pour définir le timeout, voir <code>ftp_set_option()</code><ref>http://php.net/manual/fr/function.ftp-set-option.php</ref>.
=== SFTP ===
Prérequis : libssh2-1-dev && libssl-dev. Activer ssh2 dans phpinfo.
On utiliser les trois fonctions suivantes pour construire l'URL ouverte par <code>fopen</code><ref>http://php.net/manual/fr/function.ssh2-sftp.php</ref> :
<syntaxhighlight lang="php">
$connection = ssh2_connect('tools-login.wmflabs.org', 22);
ssh2_auth_password($connection, 'monLogin', 'MonMotDePasse');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/monFichier", 'r');
ssh2_disconnect($sftp);
ssh2_disconnect($connection);
</syntaxhighlight>
=== php:// ===
Ce protocole donne accès aux flux (entrant et sortant) de PHP<ref>http://php.net/manual/fr/wrappers.php.php</ref>.
* php://fd : ''{{lang|en|file descriptor}}''.
* php://filter
* php://input : lecture de ce qui est posté.
* php://memory
* php://output : écriture.
* php://stderr
* php://stdin
* php://stdout
* php://temp
== Fichiers structurés ==
Les fichiers structurés comme les PDF, XML, DOCX et XLSX peuvent facilement être manipulés par des bibliothèques et frameworks existant, qui seront abordés dans les chapitres suivants.
== Références ==
<references/>
<noinclude>[[Catégorie:Gestions des fichiers]]</noinclude>
pu7n12rgsam6jrt93jbwqmmvdkrdvex
746465
746464
2025-07-11T08:22:30Z
JackPotte
5426
/* Dossiers */
746465
wikitext
text/x-wiki
<noinclude>
{{PHP}}
</noinclude>
L'utilisation de fichier peut être utile pour exporter des données à archiver ou accélérer un traitement par un système de cache. Cette page explique comment interagir avec un fichier.
== Dossiers ==
Voici les fonctions usuelles de navigation et manipulation du système de fichier.
{{attention|Il est recommandé de ne pas les disperser dans le code, mais de les regrouper dans une classe de manipulation de fichiers, pour pouvoir utiliser le cloud à la place (qui les manipule par des appels HTTP.}}
=== Lecture ===
* <code>PHP_OS</code> : contient de système d'exploitation courant (ex : WINNT, Linux).
* <code>basename($path)</code> : extraire le nom du fichier à partir de son chemin.
* <code>dirname(__DIR__)</code> : extraire le répertoire parent du dossier en paramètre, au niveau précisé en second paramètre (le parent direct par défaut).
* <code>chdir($dossier)</code> : changer de dossier courant ;
* <code>opendir($dossier)</code> : ouvrir un dossier ;
* <code>closedir($dossier)</code> : fermer le dossier ;
* <code>is_dir($dossier)</code> : vérifier la présence d'un dossier ;
* <code>is_file($fichier)</code> : vérifier la présence d'un fichier ;
* <code>file_exists($fichier)</code> : vérifier la présence d'un fichier ou un dossier local<ref>http://php.net/manual/fr/function.file-exists.php</ref> ;
* <code>filesize($fichier)</code> : renvoie la taille du fichier en octet<ref>https://www.php.net/manual/en/function.filesize.php</ref> ;
* <code>readdir($dossier)</code> : lire le contenu du dossier ligne par ligne ;
* <code>scandir($dossier)</code> : lire le contenu du dossier en une fois ;
* <code>glob($regex)</code> : lire le contenu du dossier courant, avec filtrage regex (ex : *.txt)<ref>http://php.net/manual/fr/function.glob.php</ref>.
* <code>pathinfo($fichier)</code> : renvoie un tableau avec les caractéristiques du fichier : dossier, nom, extension.
* <code>mime_content_type($fichier)</code> : renvoie le type {{w|MIME}}.
==== Récupérer certains fichiers d'un dossier ====
Par exemple, pour trouver tous les fichiers .sql du dossier "sql" :
<syntaxhighlight lang=php>
chdir('sql');
$files = glob('*.sql');
var_dump($files);
</syntaxhighlight>
=== Écriture ===
* <code>shell_exec('pwd')</code> : exécuter n'importe quelle commande [[Programmation Bash|shell]]. Le nom du répertoire courant (pwd) dans cet exemple.
* <code>mkdir()</code> (''make directory'') : créer un dossier.
* <code>rmdir()</code> (''remove directory'') : supprime un dossier non vide.
* <code>touch()</code> : créer un fichier (ou le rafraichir s'il existe).
* <code>rename()</code> : déplacer un fichier.
{{attention|Les commandes du shell_exec dépendent du système d'exploitation. Par exemple, sur Linux <code>shell_exec('ls')</code> fonctionne mais sur Windows il renvoie null et il faut utiliser <code>shell_exec('dir')</code>.
De plus, sachant que les systèmes d'exploitation n'ont pas les mêmes séparateurs de dossiers (sous Windows on utilise "\" et en unixerie c'est "/"), on peut utiliser la constante prédéfinie : <code>DIRECTORY_SEPARATOR</code> qui fonctionne pour les deux<ref>http://php.net/manual/fr/dir.constants.php</ref>.
}}
{{remarque|1=Pour supprimer un dossier non vide<ref>https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty</ref> :
<pre>
array_map('unlink', glob('your/path/*.*'));
rmdir('your/path');
</pre>
}}
== Droits des fichiers ==
=== Windows ===
Sous Windows il suffit de se rendre dans l'onglet sécurité des propriétés d'un fichier, pour cocher les cases autorisant le programme à le lire et/ou le modifier.
=== Unix ===
''chmod'' est le système de droit d'accès a un fichier {{w|Unix}}. Il s'agit d'un [[w:Permissions_Unix|nombre à trois chiffres]] que l’on attribut à un fichier (ex. : 755). Il détermine le droit d'accès au fichier en question, qui peut le modifier.
Selon sa valeur le {{w|système d'exploitation}} autorise ou non la modification du fichier. Sous GNU/Linux, l'utilisateur 'root', (superutilisateur), a tous les droits, c'est-à-dire qu’il peut modifier tous les fichiers.
Lorsque qu'un fichier est créé manuellement, le ''chmod'' du fichier en question est '''755''', avec un tel ''chmod'' nous ne pouvons pas modifier le fichier avec un script PHP. Pour pouvoir le modifier, il suffit juste de changer le ''chmod'' du fichier, en lui donnant la valeur ''766''. Sous Windows, cette notion est masquée et il suffit d’être administrateur de la machine (utilisateur par défaut) pour pouvoir modifier un fichier.
* Pour récupérer les permissions : <code>fileperms($localFilePath) & 0777</code>
* Le propriétaire : <code>fileowner($localFilePath))</code>
== Ouvrir un fichier ==
Pour déclencher l'ouverture d'un fichier chez celui qui exécute le script, on précise son type puis son emplacement :
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename='".$fichier."'");
</syntaxhighlight>
== Télécharger un fichier ==
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='".$fichier."'");
</syntaxhighlight>
{{attention|Le téléchargement ne doit pas être précédé d'affichages (ex : <code>echo</code> ou logs de warning) sinon ils apparaitront dans l'en-tête du fichier, le rendant illisible.|clear=left}}
== Zipper un fichier ==
=== Installation ===
Cette fonctionnalité est fournie nativement depuis PHP 5.2.0. Par contre sur les versions >= 7 sur Linux il faut l'installer :
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
=== Utilisation ===
Pour compresser des fichiers, il faut d'abord créer l'archive vide, puis les y ajouter un par un avec la méthode <code>addFile(Fichier source, Nom du fichier dans l'archive)</code><ref>http://php.net/manual/fr/ziparchive.addfile.php</ref> :
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f, ZipArchive::CREATE) !== true) {
exit('Impossible de créer le .zip');
}
$zip->addFile('../Temp/' . $nomFichier . '.xls', $nomFichier . '.xls');
$zip->close();
</syntaxhighlight>
=== Dézipper un fichier ===
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f) === true) {
$zip->extractTo('../Temp/');
$zip->close();
}
</syntaxhighlight>
Pour les .gz<ref>https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php</ref> :
<syntaxhighlight lang="php">
private function uncompressFile(string $target): void
{
$uncompressedFileName = str_replace('.gz', '', $target);
$file = gzopen($target, 'rb');
$outFile = fopen($uncompressedFileName, 'wb');
while (!gzeof($file)) {
fwrite($outFile, gzread($file, 4096));
}
fclose($outFile);
gzclose($file);
</syntaxhighlight>
== Éditer et fermer un fichier ==
Créer un fichier avec un attribut ''chmod'' de ''766''. Ensuite il faut ouvrir le fichier en question avant de lire/écrire. Pour cela la fonction ''fopen'' est là :
{{Principe|width=60%
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
</syntaxhighlight>
}}
'''Explication :''' La fonction ''fopen'' à besoin de deux paramètres pour pouvoir s'exécuter :
* $nomFichier, il s'agit du chemin du fichier
* $mode, il s'agit du mode de l'ouverture
La fonction ''fopen'' utilise le premier paramètre, pour déterminer le chemin du fichier a ouvrir/créer.
Voici les différents modes d'ouvertures pour la fonction ''fopen'' :
{| class="wikitable"
! Mode !! Description
|-
| align="center" | r
| (read) Ouvre en lecture seule, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | r+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | w
| (write) Ouvre en écriture seule, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | w+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a
| (append) Ouvre en écriture seule, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a+
|Ouvre en lecture et écriture, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | x
| Créé et ouvre le fichier en lecture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer. Ce mode est l'équivalent des options O_EXCL<nowiki>|</nowiki>O_CREAT pour l'appel système open(2) sous-jacente. Cette option est supportée à partir de PHP 4.3.2 et fonctionne uniquement avec des fichiers locaux.
|-
|-
| align="center" | x+
|Crée et ouvre le fichier en lecture et écriture ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en |générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer.
|-
| align="center" | c
| Ouvre le fichier en écriture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, il ne le tronque pas, sinon il le crée.
|-
|-
| align="center" | c+
| Ouvre le fichier en lecture et écriture, puis se comporte comme "c".
|}
Pour le fermer maintenant, il y a la fonction ''fclose''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
fputs($objetFichier, $contenu);
fgets($objetFichier);
fclose($objetFichier);
</syntaxhighlight>
}}
== Copier un fichier ==
<syntaxhighlight lang="php">
if (!copy($ancienFichier, $nouveauFichier)) {
echo 'La copie a échoué.';
}
</syntaxhighlight>
Pour les images il existe aussi <code>imagecopyresampled</code><ref>http://php.net//manual/fr/function.imagecopyresampled.php</ref>.
== Supprimer un fichier ==
<syntaxhighlight lang="php">
if (!unlink($fichier)) {
echo 'La suppression a échoué.';
}
</syntaxhighlight>
== Interagir avec le fichier ==
=== Lecture ===
Une fois ouvert, il existe plusieurs manière de lire le contenu d'un fichier : caractère par caractère, ligne par ligne, jusqu'à une certaine taille, ou tout entier.
==== Tout le fichier ====
===== file =====
Pour stocker le fichier entier dans un tableau, on peut utiliser ''file()'' qui renvoie un tableau séparant chaque ligne du fichier :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$fichier = file($nomFichier); // ou : file("http://MonSite/" . $nomFichier);
</syntaxhighlight>
}}
Ainsi, ''$fichier[0]'' correspond à la première ligne, ''$fichier[1]'' à la seconde, etc.
Si le fichier sature la mémoire, utiliser file_lines() avec les générateurs<ref>https://www.startutorial.com/articles/view/php-generator-reading-file-content</ref>.
===== file_get_contents =====
Pour stocker le fichier entier dans un scalaire, on utilise cette fonction.
===== readfile =====
Pour afficher tout le fichier dans la sortie standard<ref>https://www.php.net/manual/en/function.readfile.php</ref>.
==== Ligne par ligne ====
===== fgets =====
La méthode générale pour lire ligne par ligne avec la fonction ''fgets'', dont la définition est la suivante :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$ligne = fgets($objetFichier);
</syntaxhighlight>
}}
La variable ''$objetFichier'' doit être le résultat de l'ouverture d'un fichier avec ''fopen''. Pour lire un fichier en entier, il suffit d’utiliser ''fgets'' en boucle ; la condition de sortie de la boucle serait alors l'arrivée à la fin de fichier, évènement notifié par la fonction ''feof''.
{{Exemple
| titre=Exemple de parcours d'un fichier ligne par ligne
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$objetFichier = fopen($nomFichier, "r"); //ouverture en lecture
if ($objetFichier) {
//on lit le fichier tant que la fin n'est pas atteinte
while (!feof($objetFichier)) {
$ligne = fgets($objetFichier);
echo $ligne;
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
===== fgetc =====
La fonction équivalente pour lire caractère par caractère se nomme ''fgetc'' :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$caractere = fgetc($objetFichier);
</syntaxhighlight>
}}
Notez que cette fonction retourne FALSE arrivée à la fin du fichier. Lors d'un parcours, il faut donc tester impérativement la valeur avant de l’utiliser, avec un test logique de la forme « $caractere !== FALSE ».
===== fgetcsv =====
Cette fonction fonctionne comme "fgets" sauf qu'en plus elle utilise le séparateur "," (qui peut être changé par le paramètre "delimiter"<ref>http://php.net/manual/fr/function.fgetcsv.php</ref>) pour créer un sous-tableau de champs par ligne.
=== Écriture ===
Une fois le fichier ouvert, l'écriture se fait via la fonction ''fwrite''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fwrite($objetFichier, $chaine);
</syntaxhighlight>
}}
'''Explication''' :
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $chaine : la chaîne à écrire dans le fichier
* retour : le nombre de caractère écrits, ou FALSE si erreur
L'utilisation est alors la même que pour la lecture : ouvrir le fichier, écrire et fermer.
{{Exemple
| titre=Exemple d'écriture
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$chaine = "Je suis une chaine écrite par PHP !\n"
$objetFichier = fopen($nomFichier, "w"); //ouverture en lecture
if ($objetFichier) {
if(fwrite($objetFichier, $chaine) === FALSE) {
echo "Erreur : impossible d'écrire dans le fichier.";
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
'''Attention :''' Si vous ouvrez le fichier avec l'option ''w'' ou ''w+'', le contenu du fichier sera effacé s'il existait. Pour écrire à la fin, il faut ouvrir avec les options ''a'' ou ''a+'' (voir ci-dessus). Enfin, si vous pouvez avec l'option ''r+'', le contenu sera écrasé, puisque le pointeur de fichier sera placé au début.
Par ailleurs, la fonction ''file_put_contents()'' effectue un ''fopen()'', ''fwrite()'' et ''fclose()'' successivement<ref>http://php.net/manual/fr/function.file-put-contents.php</ref>.
=== Se déplacer ===
Parfois, il peut être nécessaire de se déplacer dans le fichier, par exemple pour revenir au début. Pour cela, il faut utiliser la fonction ''fseek'' comme suit :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, $position);
</syntaxhighlight>
}}
'''Explication :'''
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $position : la position à laquelle on veut se déplacer. Pour revenir au début, $position doit valoir zéro.
Pour aller à la fin :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, 0, SEEK_END);
</syntaxhighlight>
}}
== Fichiers uploadés ==
Copier-coller ces lignes dans un fichier vierge ''upload.php'' pour qu’il affiche le nom des fichiers qu'on upload avec :
<syntaxhighlight lang="php">
<?php
echo '
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fichier">
<input type="submit" name="envoyer" value="Uploader">
</form>';
if (isset($_FILES['fichier'])) {
echo $_FILES['fichier']['name'];
}
</syntaxhighlight>
Il existe la fonction is_uploaded_file() pour vérifier si un fichier est bien issu d'un upload<ref>https://www.php.net/manual/en/function.is-uploaded-file.php</ref>, et move_uploaded_file() pour le déplacer.
== Fichiers temporaires ==
Pour créer des fichiers qui seront automatiquement détruits en fin de connexion, le dossier temporaire est accessible avec : <code>sys_get_temp_dir()</code>.
La fonction <code>tempnam()</code> quant-à elle nomme automatiquement un nouveau fichier temporaire avec un nom unique :
<syntaxhighlight lang="php">
$fileName = tempnam(sys_get_temp_dir(), 'MonFichier1');
</syntaxhighlight>
== Fichiers distants ==
=== HTTP ===
Pour lire un fichier en HTTP (par exemple cette page web) :
<syntaxhighlight lang="php">
<?php
$page = file_get_contents("http://fr.wikibooks.org/wiki/PHP/Fichiers");
echo $page;
</syntaxhighlight>
ou<ref>[http://www.developpez.net/forums/d66310/php/langage/syntaxe/lire-contenu-page-web-grace-script-php/ developpez.net]</ref>
<syntaxhighlight lang="php">
<?php
$url = 'http://fr.wikibooks.org/wiki/PHP/Fichiers';
echo htmlspecialchars(implode('', file($url)));
</syntaxhighlight>
Pour tester si un fichier distant existe, utiliser <code>get_headers()</code><ref>http://php.net/manual/fr/function.get-headers.php</ref>.
{{remarque|fonctionne aussi bien avec HTTPS.}}
=== FTP ===
Installation : dans php.ini, décommenter "extension=ftp" (anciennement "extension=php_ftp.dll").
Déposer un fichier (sans vérifier s'il en écrase un)<ref>http://php.net/manual/fr/book.ftp.php</ref> :
<syntaxhighlight lang="php">
<?php
copy('fichier_local.txt', 'ftp://login:password@server/repertoire/fichier_distant.txt');
</syntaxhighlight>
Souvent le répertoire porte le nom de l'utilisateur, et on écrase le fichier s'il existe :
<syntaxhighlight lang="php">
<?php
$serveur = 'serveur1';
$login = 'utilisateur1';
$password = 'mdp1';
$fichier = 'fichier1';
copy($fichier, 'ftp://'.$login.':'.$password.'@'.$serveur.'/'.$login.'/'.$fichier, stream_context_create(array('ftp' => array('overwrite'=>True))));
</syntaxhighlight>
Fonctions propres au FTP, pour lire un serveur distant, y télécharger et déposer des fichiers<ref>http://php.net/manual/fr/function.ftp-nlist.php</ref> :
<syntaxhighlight lang="php">
$cnx = ftp_connect($serveur);
$loginResult = ftp_login($cnx, $login, $password);
// Liste des noms des dossiers et fichiers du dossier distant (dans le désordre)
$dossierDistant = ftp_nlist($cnx, ".");
var_dump($dossierDistant);
// Liste des éléments du dossier distant avec leurs inodes
$dossierDistant2 = ftp_rawlist($cnx, ".");
var_dump($dossierDistant2);
// Change de répertoire :
var_dump(ftp_pwd($cnx));
ftp_chdir($cnx, 'tmp');
var_dump(ftp_pwd($cnx));
// Téléchargement du dernier fichier distant
sort($dossierDistant);
$distant = $dossierDistant[sizeof($dossierDistant)-1];
$local = 'FichierLocal.txt';
if (!ftp_get($cnx, $local, $distant, FTP_BINARY)) {
echo "Erreur ftp_get\n";
} else {
ftp_delete($cnx, $distant);
}
// Téléversement d'un fichier local
$local = 'FichierLocal2.txt';
if (!ftp_put($cnx, $distant, $local, FTP_ASCII)) {
echo "Erreur ftp_put\n";
}
</syntaxhighlight>
Pour définir le timeout, voir <code>ftp_set_option()</code><ref>http://php.net/manual/fr/function.ftp-set-option.php</ref>.
=== SFTP ===
Prérequis : libssh2-1-dev && libssl-dev. Activer ssh2 dans phpinfo.
On utiliser les trois fonctions suivantes pour construire l'URL ouverte par <code>fopen</code><ref>http://php.net/manual/fr/function.ssh2-sftp.php</ref> :
<syntaxhighlight lang="php">
$connection = ssh2_connect('tools-login.wmflabs.org', 22);
ssh2_auth_password($connection, 'monLogin', 'MonMotDePasse');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/monFichier", 'r');
ssh2_disconnect($sftp);
ssh2_disconnect($connection);
</syntaxhighlight>
=== php:// ===
Ce protocole donne accès aux flux (entrant et sortant) de PHP<ref>http://php.net/manual/fr/wrappers.php.php</ref>.
* php://fd : ''{{lang|en|file descriptor}}''.
* php://filter
* php://input : lecture de ce qui est posté.
* php://memory
* php://output : écriture.
* php://stderr
* php://stdin
* php://stdout
* php://temp
== Fichiers structurés ==
Les fichiers structurés comme les PDF, XML, DOCX et XLSX peuvent facilement être manipulés par des bibliothèques et frameworks existant, qui seront abordés dans les chapitres suivants.
== Références ==
<references/>
<noinclude>[[Catégorie:Gestions des fichiers]]</noinclude>
30avymmgniqgipj42jpid79830ntxsd
746466
746465
2025-07-11T08:23:41Z
JackPotte
5426
746466
wikitext
text/x-wiki
<noinclude>
{{PHP}}
</noinclude>
L'utilisation de fichier peut être utile pour exporter des données à archiver ou accélérer un traitement par un système de cache. Cette page explique comment interagir avec un fichier.
== Dossiers ==
Voici les fonctions usuelles de navigation et manipulation du système de fichier.
{{attention|Il est recommandé de ne pas les disperser dans le code, mais de les regrouper dans une classe de manipulation de fichiers, pour pouvoir utiliser un stockage cloud alternativement (qui les manipule par des appels HTTP).}}
=== Lecture ===
* <code>PHP_OS</code> : contient de système d'exploitation courant (ex : WINNT, Linux).
* <code>basename($path)</code> : extraire le nom du fichier à partir de son chemin.
* <code>dirname(__DIR__)</code> : extraire le répertoire parent du dossier en paramètre, au niveau précisé en second paramètre (le parent direct par défaut).
* <code>chdir($dossier)</code> : changer de dossier courant ;
* <code>opendir($dossier)</code> : ouvrir un dossier ;
* <code>closedir($dossier)</code> : fermer le dossier ;
* <code>is_dir($dossier)</code> : vérifier la présence d'un dossier ;
* <code>is_file($fichier)</code> : vérifier la présence d'un fichier ;
* <code>file_exists($fichier)</code> : vérifier la présence d'un fichier ou un dossier local<ref>http://php.net/manual/fr/function.file-exists.php</ref> ;
* <code>filesize($fichier)</code> : renvoie la taille du fichier en octet<ref>https://www.php.net/manual/en/function.filesize.php</ref> ;
* <code>readdir($dossier)</code> : lire le contenu du dossier ligne par ligne ;
* <code>scandir($dossier)</code> : lire le contenu du dossier en une fois ;
* <code>glob($regex)</code> : lire le contenu du dossier courant, avec filtrage regex (ex : *.txt)<ref>http://php.net/manual/fr/function.glob.php</ref>.
* <code>pathinfo($fichier)</code> : renvoie un tableau avec les caractéristiques du fichier : dossier, nom, extension.
* <code>mime_content_type($fichier)</code> : renvoie le type {{w|MIME}}.
==== Récupérer certains fichiers d'un dossier ====
Par exemple, pour trouver tous les fichiers .sql du dossier "sql" :
<syntaxhighlight lang=php>
chdir('sql');
$files = glob('*.sql');
var_dump($files);
</syntaxhighlight>
=== Écriture ===
* <code>shell_exec('pwd')</code> : exécuter n'importe quelle commande [[Programmation Bash|shell]]. Le nom du répertoire courant (pwd) dans cet exemple.
* <code>mkdir()</code> (''make directory'') : créer un dossier.
* <code>rmdir()</code> (''remove directory'') : supprime un dossier non vide.
* <code>touch()</code> : créer un fichier (ou le rafraichir s'il existe).
* <code>rename()</code> : déplacer un fichier.
{{attention|Les commandes du shell_exec dépendent du système d'exploitation. Par exemple, sur Linux <code>shell_exec('ls')</code> fonctionne mais sur Windows il renvoie null et il faut utiliser <code>shell_exec('dir')</code>.
De plus, sachant que les systèmes d'exploitation n'ont pas les mêmes séparateurs de dossiers (sous Windows on utilise "\" et en unixerie c'est "/"), on peut utiliser la constante prédéfinie : <code>DIRECTORY_SEPARATOR</code> qui fonctionne pour les deux<ref>http://php.net/manual/fr/dir.constants.php</ref>.
}}
{{remarque|1=Pour supprimer un dossier non vide<ref>https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty</ref> :
<pre>
array_map('unlink', glob('your/path/*.*'));
rmdir('your/path');
</pre>
}}
== Droits des fichiers ==
=== Windows ===
Sous Windows il suffit de se rendre dans l'onglet sécurité des propriétés d'un fichier, pour cocher les cases autorisant le programme à le lire et/ou le modifier.
=== Unix ===
''chmod'' est le système de droit d'accès a un fichier {{w|Unix}}. Il s'agit d'un [[w:Permissions_Unix|nombre à trois chiffres]] que l’on attribut à un fichier (ex. : 755). Il détermine le droit d'accès au fichier en question, qui peut le modifier.
Selon sa valeur le {{w|système d'exploitation}} autorise ou non la modification du fichier. Sous GNU/Linux, l'utilisateur 'root', (superutilisateur), a tous les droits, c'est-à-dire qu’il peut modifier tous les fichiers.
Lorsque qu'un fichier est créé manuellement, le ''chmod'' du fichier en question est '''755''', avec un tel ''chmod'' nous ne pouvons pas modifier le fichier avec un script PHP. Pour pouvoir le modifier, il suffit juste de changer le ''chmod'' du fichier, en lui donnant la valeur ''766''. Sous Windows, cette notion est masquée et il suffit d’être administrateur de la machine (utilisateur par défaut) pour pouvoir modifier un fichier.
* Pour récupérer les permissions : <code>fileperms($localFilePath) & 0777</code>
* Le propriétaire : <code>fileowner($localFilePath))</code>
== Ouvrir un fichier ==
Pour déclencher l'ouverture d'un fichier chez celui qui exécute le script, on précise son type puis son emplacement :
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename='".$fichier."'");
</syntaxhighlight>
== Télécharger un fichier ==
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='".$fichier."'");
</syntaxhighlight>
{{attention|Le téléchargement ne doit pas être précédé d'affichages (ex : <code>echo</code> ou logs de warning) sinon ils apparaitront dans l'en-tête du fichier, le rendant illisible.|clear=left}}
== Zipper un fichier ==
=== Installation ===
Cette fonctionnalité est fournie nativement depuis PHP 5.2.0. Par contre sur les versions >= 7 sur Linux il faut l'installer :
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
=== Utilisation ===
Pour compresser des fichiers, il faut d'abord créer l'archive vide, puis les y ajouter un par un avec la méthode <code>addFile(Fichier source, Nom du fichier dans l'archive)</code><ref>http://php.net/manual/fr/ziparchive.addfile.php</ref> :
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f, ZipArchive::CREATE) !== true) {
exit('Impossible de créer le .zip');
}
$zip->addFile('../Temp/' . $nomFichier . '.xls', $nomFichier . '.xls');
$zip->close();
</syntaxhighlight>
=== Dézipper un fichier ===
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f) === true) {
$zip->extractTo('../Temp/');
$zip->close();
}
</syntaxhighlight>
Pour les .gz<ref>https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php</ref> :
<syntaxhighlight lang="php">
private function uncompressFile(string $target): void
{
$uncompressedFileName = str_replace('.gz', '', $target);
$file = gzopen($target, 'rb');
$outFile = fopen($uncompressedFileName, 'wb');
while (!gzeof($file)) {
fwrite($outFile, gzread($file, 4096));
}
fclose($outFile);
gzclose($file);
</syntaxhighlight>
== Éditer et fermer un fichier ==
Créer un fichier avec un attribut ''chmod'' de ''766''. Ensuite il faut ouvrir le fichier en question avant de lire/écrire. Pour cela la fonction ''fopen'' est là :
{{Principe|width=60%
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
</syntaxhighlight>
}}
'''Explication :''' La fonction ''fopen'' à besoin de deux paramètres pour pouvoir s'exécuter :
* $nomFichier, il s'agit du chemin du fichier
* $mode, il s'agit du mode de l'ouverture
La fonction ''fopen'' utilise le premier paramètre, pour déterminer le chemin du fichier a ouvrir/créer.
Voici les différents modes d'ouvertures pour la fonction ''fopen'' :
{| class="wikitable"
! Mode !! Description
|-
| align="center" | r
| (read) Ouvre en lecture seule, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | r+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | w
| (write) Ouvre en écriture seule, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | w+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a
| (append) Ouvre en écriture seule, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a+
|Ouvre en lecture et écriture, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | x
| Créé et ouvre le fichier en lecture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer. Ce mode est l'équivalent des options O_EXCL<nowiki>|</nowiki>O_CREAT pour l'appel système open(2) sous-jacente. Cette option est supportée à partir de PHP 4.3.2 et fonctionne uniquement avec des fichiers locaux.
|-
|-
| align="center" | x+
|Crée et ouvre le fichier en lecture et écriture ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en |générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer.
|-
| align="center" | c
| Ouvre le fichier en écriture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, il ne le tronque pas, sinon il le crée.
|-
|-
| align="center" | c+
| Ouvre le fichier en lecture et écriture, puis se comporte comme "c".
|}
Pour le fermer maintenant, il y a la fonction ''fclose''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
fputs($objetFichier, $contenu);
fgets($objetFichier);
fclose($objetFichier);
</syntaxhighlight>
}}
== Copier un fichier ==
<syntaxhighlight lang="php">
if (!copy($ancienFichier, $nouveauFichier)) {
echo 'La copie a échoué.';
}
</syntaxhighlight>
Pour les images il existe aussi <code>imagecopyresampled</code><ref>http://php.net//manual/fr/function.imagecopyresampled.php</ref>.
== Supprimer un fichier ==
<syntaxhighlight lang="php">
if (!unlink($fichier)) {
echo 'La suppression a échoué.';
}
</syntaxhighlight>
== Interagir avec le fichier ==
=== Lecture ===
Une fois ouvert, il existe plusieurs manière de lire le contenu d'un fichier : caractère par caractère, ligne par ligne, jusqu'à une certaine taille, ou tout entier.
==== Tout le fichier ====
===== file =====
Pour stocker le fichier entier dans un tableau, on peut utiliser ''file()'' qui renvoie un tableau séparant chaque ligne du fichier :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$fichier = file($nomFichier); // ou : file("http://MonSite/" . $nomFichier);
</syntaxhighlight>
}}
Ainsi, ''$fichier[0]'' correspond à la première ligne, ''$fichier[1]'' à la seconde, etc.
Si le fichier sature la mémoire, utiliser file_lines() avec les générateurs<ref>https://www.startutorial.com/articles/view/php-generator-reading-file-content</ref>.
===== file_get_contents =====
Pour stocker le fichier entier dans un scalaire, on utilise cette fonction.
===== readfile =====
Pour afficher tout le fichier dans la sortie standard<ref>https://www.php.net/manual/en/function.readfile.php</ref>.
==== Ligne par ligne ====
===== fgets =====
La méthode générale pour lire ligne par ligne avec la fonction ''fgets'', dont la définition est la suivante :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$ligne = fgets($objetFichier);
</syntaxhighlight>
}}
La variable ''$objetFichier'' doit être le résultat de l'ouverture d'un fichier avec ''fopen''. Pour lire un fichier en entier, il suffit d’utiliser ''fgets'' en boucle ; la condition de sortie de la boucle serait alors l'arrivée à la fin de fichier, évènement notifié par la fonction ''feof''.
{{Exemple
| titre=Exemple de parcours d'un fichier ligne par ligne
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$objetFichier = fopen($nomFichier, "r"); //ouverture en lecture
if ($objetFichier) {
//on lit le fichier tant que la fin n'est pas atteinte
while (!feof($objetFichier)) {
$ligne = fgets($objetFichier);
echo $ligne;
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
===== fgetc =====
La fonction équivalente pour lire caractère par caractère se nomme ''fgetc'' :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$caractere = fgetc($objetFichier);
</syntaxhighlight>
}}
Notez que cette fonction retourne FALSE arrivée à la fin du fichier. Lors d'un parcours, il faut donc tester impérativement la valeur avant de l’utiliser, avec un test logique de la forme « $caractere !== FALSE ».
===== fgetcsv =====
Cette fonction fonctionne comme "fgets" sauf qu'en plus elle utilise le séparateur "," (qui peut être changé par le paramètre "delimiter"<ref>http://php.net/manual/fr/function.fgetcsv.php</ref>) pour créer un sous-tableau de champs par ligne.
=== Écriture ===
Une fois le fichier ouvert, l'écriture se fait via la fonction ''fwrite''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fwrite($objetFichier, $chaine);
</syntaxhighlight>
}}
'''Explication''' :
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $chaine : la chaîne à écrire dans le fichier
* retour : le nombre de caractère écrits, ou FALSE si erreur
L'utilisation est alors la même que pour la lecture : ouvrir le fichier, écrire et fermer.
{{Exemple
| titre=Exemple d'écriture
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$chaine = "Je suis une chaine écrite par PHP !\n"
$objetFichier = fopen($nomFichier, "w"); //ouverture en lecture
if ($objetFichier) {
if(fwrite($objetFichier, $chaine) === FALSE) {
echo "Erreur : impossible d'écrire dans le fichier.";
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
'''Attention :''' Si vous ouvrez le fichier avec l'option ''w'' ou ''w+'', le contenu du fichier sera effacé s'il existait. Pour écrire à la fin, il faut ouvrir avec les options ''a'' ou ''a+'' (voir ci-dessus). Enfin, si vous pouvez avec l'option ''r+'', le contenu sera écrasé, puisque le pointeur de fichier sera placé au début.
Par ailleurs, la fonction ''file_put_contents()'' effectue un ''fopen()'', ''fwrite()'' et ''fclose()'' successivement<ref>http://php.net/manual/fr/function.file-put-contents.php</ref>.
=== Se déplacer ===
Parfois, il peut être nécessaire de se déplacer dans le fichier, par exemple pour revenir au début. Pour cela, il faut utiliser la fonction ''fseek'' comme suit :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, $position);
</syntaxhighlight>
}}
'''Explication :'''
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $position : la position à laquelle on veut se déplacer. Pour revenir au début, $position doit valoir zéro.
Pour aller à la fin :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, 0, SEEK_END);
</syntaxhighlight>
}}
== Fichiers uploadés ==
Copier-coller ces lignes dans un fichier vierge ''upload.php'' pour qu’il affiche le nom des fichiers qu'on upload avec :
<syntaxhighlight lang="php">
<?php
echo '
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fichier">
<input type="submit" name="envoyer" value="Uploader">
</form>';
if (isset($_FILES['fichier'])) {
echo $_FILES['fichier']['name'];
}
</syntaxhighlight>
Il existe la fonction is_uploaded_file() pour vérifier si un fichier est bien issu d'un upload<ref>https://www.php.net/manual/en/function.is-uploaded-file.php</ref>, et move_uploaded_file() pour le déplacer.
== Fichiers temporaires ==
Pour créer des fichiers qui seront automatiquement détruits en fin de connexion, le dossier temporaire est accessible avec : <code>sys_get_temp_dir()</code>.
La fonction <code>tempnam()</code> quant-à elle nomme automatiquement un nouveau fichier temporaire avec un nom unique :
<syntaxhighlight lang="php">
$fileName = tempnam(sys_get_temp_dir(), 'MonFichier1');
</syntaxhighlight>
== Fichiers distants ==
=== HTTP ===
Pour lire un fichier en HTTP (par exemple cette page web) :
<syntaxhighlight lang="php">
<?php
$page = file_get_contents("http://fr.wikibooks.org/wiki/PHP/Fichiers");
echo $page;
</syntaxhighlight>
ou<ref>[http://www.developpez.net/forums/d66310/php/langage/syntaxe/lire-contenu-page-web-grace-script-php/ developpez.net]</ref>
<syntaxhighlight lang="php">
<?php
$url = 'http://fr.wikibooks.org/wiki/PHP/Fichiers';
echo htmlspecialchars(implode('', file($url)));
</syntaxhighlight>
Pour tester si un fichier distant existe, utiliser <code>get_headers()</code><ref>http://php.net/manual/fr/function.get-headers.php</ref>.
{{remarque|fonctionne aussi bien avec HTTPS.}}
=== FTP ===
Installation : dans php.ini, décommenter "extension=ftp" (anciennement "extension=php_ftp.dll").
Déposer un fichier (sans vérifier s'il en écrase un)<ref>http://php.net/manual/fr/book.ftp.php</ref> :
<syntaxhighlight lang="php">
<?php
copy('fichier_local.txt', 'ftp://login:password@server/repertoire/fichier_distant.txt');
</syntaxhighlight>
Souvent le répertoire porte le nom de l'utilisateur, et on écrase le fichier s'il existe :
<syntaxhighlight lang="php">
<?php
$serveur = 'serveur1';
$login = 'utilisateur1';
$password = 'mdp1';
$fichier = 'fichier1';
copy($fichier, 'ftp://'.$login.':'.$password.'@'.$serveur.'/'.$login.'/'.$fichier, stream_context_create(array('ftp' => array('overwrite'=>True))));
</syntaxhighlight>
Fonctions propres au FTP, pour lire un serveur distant, y télécharger et déposer des fichiers<ref>http://php.net/manual/fr/function.ftp-nlist.php</ref> :
<syntaxhighlight lang="php">
$cnx = ftp_connect($serveur);
$loginResult = ftp_login($cnx, $login, $password);
// Liste des noms des dossiers et fichiers du dossier distant (dans le désordre)
$dossierDistant = ftp_nlist($cnx, ".");
var_dump($dossierDistant);
// Liste des éléments du dossier distant avec leurs inodes
$dossierDistant2 = ftp_rawlist($cnx, ".");
var_dump($dossierDistant2);
// Change de répertoire :
var_dump(ftp_pwd($cnx));
ftp_chdir($cnx, 'tmp');
var_dump(ftp_pwd($cnx));
// Téléchargement du dernier fichier distant
sort($dossierDistant);
$distant = $dossierDistant[sizeof($dossierDistant)-1];
$local = 'FichierLocal.txt';
if (!ftp_get($cnx, $local, $distant, FTP_BINARY)) {
echo "Erreur ftp_get\n";
} else {
ftp_delete($cnx, $distant);
}
// Téléversement d'un fichier local
$local = 'FichierLocal2.txt';
if (!ftp_put($cnx, $distant, $local, FTP_ASCII)) {
echo "Erreur ftp_put\n";
}
</syntaxhighlight>
Pour définir le timeout, voir <code>ftp_set_option()</code><ref>http://php.net/manual/fr/function.ftp-set-option.php</ref>.
=== SFTP ===
Prérequis : libssh2-1-dev && libssl-dev. Activer ssh2 dans phpinfo.
On utiliser les trois fonctions suivantes pour construire l'URL ouverte par <code>fopen</code><ref>http://php.net/manual/fr/function.ssh2-sftp.php</ref> :
<syntaxhighlight lang="php">
$connection = ssh2_connect('tools-login.wmflabs.org', 22);
ssh2_auth_password($connection, 'monLogin', 'MonMotDePasse');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/monFichier", 'r');
ssh2_disconnect($sftp);
ssh2_disconnect($connection);
</syntaxhighlight>
=== php:// ===
Ce protocole donne accès aux flux (entrant et sortant) de PHP<ref>http://php.net/manual/fr/wrappers.php.php</ref>.
* php://fd : ''{{lang|en|file descriptor}}''.
* php://filter
* php://input : lecture de ce qui est posté.
* php://memory
* php://output : écriture.
* php://stderr
* php://stdin
* php://stdout
* php://temp
== Fichiers structurés ==
Les fichiers structurés comme les PDF, XML, DOCX et XLSX peuvent facilement être manipulés par des bibliothèques et frameworks existant, qui seront abordés dans les chapitres suivants.
== Références ==
<references/>
<noinclude>[[Catégorie:Gestions des fichiers]]</noinclude>
n1oris9i0ixprgql57xpjoipx6xkc3z
746467
746466
2025-07-11T08:25:13Z
JackPotte
5426
/* Dossiers */
746467
wikitext
text/x-wiki
<noinclude>
{{PHP}}
</noinclude>
L'utilisation de fichier peut être utile pour exporter des données à archiver ou accélérer un traitement par un système de cache. Cette page explique comment interagir avec un fichier.
== Dossiers ==
Voici les fonctions usuelles de navigation et manipulation du système de fichier.
{{attention|Il est recommandé de ne pas les disperser dans le code, mais de les regrouper dans une classe de manipulation de fichiers, pour pouvoir utiliser un stockage cloud alternativement (qui les manipule par des appels HTTP, dans un stockage "illimité").}}
=== Lecture ===
* <code>PHP_OS</code> : contient de système d'exploitation courant (ex : WINNT, Linux).
* <code>basename($path)</code> : extraire le nom du fichier à partir de son chemin.
* <code>dirname(__DIR__)</code> : extraire le répertoire parent du dossier en paramètre, au niveau précisé en second paramètre (le parent direct par défaut).
* <code>chdir($dossier)</code> : changer de dossier courant ;
* <code>opendir($dossier)</code> : ouvrir un dossier ;
* <code>closedir($dossier)</code> : fermer le dossier ;
* <code>is_dir($dossier)</code> : vérifier la présence d'un dossier ;
* <code>is_file($fichier)</code> : vérifier la présence d'un fichier ;
* <code>file_exists($fichier)</code> : vérifier la présence d'un fichier ou un dossier local<ref>http://php.net/manual/fr/function.file-exists.php</ref> ;
* <code>filesize($fichier)</code> : renvoie la taille du fichier en octet<ref>https://www.php.net/manual/en/function.filesize.php</ref> ;
* <code>readdir($dossier)</code> : lire le contenu du dossier ligne par ligne ;
* <code>scandir($dossier)</code> : lire le contenu du dossier en une fois ;
* <code>glob($regex)</code> : lire le contenu du dossier courant, avec filtrage regex (ex : *.txt)<ref>http://php.net/manual/fr/function.glob.php</ref>.
* <code>pathinfo($fichier)</code> : renvoie un tableau avec les caractéristiques du fichier : dossier, nom, extension.
* <code>mime_content_type($fichier)</code> : renvoie le type {{w|MIME}}.
==== Récupérer certains fichiers d'un dossier ====
Par exemple, pour trouver tous les fichiers .sql du dossier "sql" :
<syntaxhighlight lang=php>
chdir('sql');
$files = glob('*.sql');
var_dump($files);
</syntaxhighlight>
=== Écriture ===
* <code>shell_exec('pwd')</code> : exécuter n'importe quelle commande [[Programmation Bash|shell]]. Le nom du répertoire courant (pwd) dans cet exemple.
* <code>mkdir()</code> (''make directory'') : créer un dossier.
* <code>rmdir()</code> (''remove directory'') : supprime un dossier non vide.
* <code>touch()</code> : créer un fichier (ou le rafraichir s'il existe).
* <code>rename()</code> : déplacer un fichier.
{{attention|Les commandes du shell_exec dépendent du système d'exploitation. Par exemple, sur Linux <code>shell_exec('ls')</code> fonctionne mais sur Windows il renvoie null et il faut utiliser <code>shell_exec('dir')</code>.
De plus, sachant que les systèmes d'exploitation n'ont pas les mêmes séparateurs de dossiers (sous Windows on utilise "\" et en unixerie c'est "/"), on peut utiliser la constante prédéfinie : <code>DIRECTORY_SEPARATOR</code> qui fonctionne pour les deux<ref>http://php.net/manual/fr/dir.constants.php</ref>.
}}
{{remarque|1=Pour supprimer un dossier non vide<ref>https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty</ref> :
<pre>
array_map('unlink', glob('your/path/*.*'));
rmdir('your/path');
</pre>
}}
== Droits des fichiers ==
=== Windows ===
Sous Windows il suffit de se rendre dans l'onglet sécurité des propriétés d'un fichier, pour cocher les cases autorisant le programme à le lire et/ou le modifier.
=== Unix ===
''chmod'' est le système de droit d'accès a un fichier {{w|Unix}}. Il s'agit d'un [[w:Permissions_Unix|nombre à trois chiffres]] que l’on attribut à un fichier (ex. : 755). Il détermine le droit d'accès au fichier en question, qui peut le modifier.
Selon sa valeur le {{w|système d'exploitation}} autorise ou non la modification du fichier. Sous GNU/Linux, l'utilisateur 'root', (superutilisateur), a tous les droits, c'est-à-dire qu’il peut modifier tous les fichiers.
Lorsque qu'un fichier est créé manuellement, le ''chmod'' du fichier en question est '''755''', avec un tel ''chmod'' nous ne pouvons pas modifier le fichier avec un script PHP. Pour pouvoir le modifier, il suffit juste de changer le ''chmod'' du fichier, en lui donnant la valeur ''766''. Sous Windows, cette notion est masquée et il suffit d’être administrateur de la machine (utilisateur par défaut) pour pouvoir modifier un fichier.
* Pour récupérer les permissions : <code>fileperms($localFilePath) & 0777</code>
* Le propriétaire : <code>fileowner($localFilePath))</code>
== Ouvrir un fichier ==
Pour déclencher l'ouverture d'un fichier chez celui qui exécute le script, on précise son type puis son emplacement :
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename='".$fichier."'");
</syntaxhighlight>
== Télécharger un fichier ==
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='".$fichier."'");
</syntaxhighlight>
{{attention|Le téléchargement ne doit pas être précédé d'affichages (ex : <code>echo</code> ou logs de warning) sinon ils apparaitront dans l'en-tête du fichier, le rendant illisible.|clear=left}}
== Zipper un fichier ==
=== Installation ===
Cette fonctionnalité est fournie nativement depuis PHP 5.2.0. Par contre sur les versions >= 7 sur Linux il faut l'installer :
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
=== Utilisation ===
Pour compresser des fichiers, il faut d'abord créer l'archive vide, puis les y ajouter un par un avec la méthode <code>addFile(Fichier source, Nom du fichier dans l'archive)</code><ref>http://php.net/manual/fr/ziparchive.addfile.php</ref> :
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f, ZipArchive::CREATE) !== true) {
exit('Impossible de créer le .zip');
}
$zip->addFile('../Temp/' . $nomFichier . '.xls', $nomFichier . '.xls');
$zip->close();
</syntaxhighlight>
=== Dézipper un fichier ===
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f) === true) {
$zip->extractTo('../Temp/');
$zip->close();
}
</syntaxhighlight>
Pour les .gz<ref>https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php</ref> :
<syntaxhighlight lang="php">
private function uncompressFile(string $target): void
{
$uncompressedFileName = str_replace('.gz', '', $target);
$file = gzopen($target, 'rb');
$outFile = fopen($uncompressedFileName, 'wb');
while (!gzeof($file)) {
fwrite($outFile, gzread($file, 4096));
}
fclose($outFile);
gzclose($file);
</syntaxhighlight>
== Éditer et fermer un fichier ==
Créer un fichier avec un attribut ''chmod'' de ''766''. Ensuite il faut ouvrir le fichier en question avant de lire/écrire. Pour cela la fonction ''fopen'' est là :
{{Principe|width=60%
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
</syntaxhighlight>
}}
'''Explication :''' La fonction ''fopen'' à besoin de deux paramètres pour pouvoir s'exécuter :
* $nomFichier, il s'agit du chemin du fichier
* $mode, il s'agit du mode de l'ouverture
La fonction ''fopen'' utilise le premier paramètre, pour déterminer le chemin du fichier a ouvrir/créer.
Voici les différents modes d'ouvertures pour la fonction ''fopen'' :
{| class="wikitable"
! Mode !! Description
|-
| align="center" | r
| (read) Ouvre en lecture seule, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | r+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | w
| (write) Ouvre en écriture seule, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | w+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a
| (append) Ouvre en écriture seule, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a+
|Ouvre en lecture et écriture, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | x
| Créé et ouvre le fichier en lecture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer. Ce mode est l'équivalent des options O_EXCL<nowiki>|</nowiki>O_CREAT pour l'appel système open(2) sous-jacente. Cette option est supportée à partir de PHP 4.3.2 et fonctionne uniquement avec des fichiers locaux.
|-
|-
| align="center" | x+
|Crée et ouvre le fichier en lecture et écriture ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en |générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer.
|-
| align="center" | c
| Ouvre le fichier en écriture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, il ne le tronque pas, sinon il le crée.
|-
|-
| align="center" | c+
| Ouvre le fichier en lecture et écriture, puis se comporte comme "c".
|}
Pour le fermer maintenant, il y a la fonction ''fclose''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
fputs($objetFichier, $contenu);
fgets($objetFichier);
fclose($objetFichier);
</syntaxhighlight>
}}
== Copier un fichier ==
<syntaxhighlight lang="php">
if (!copy($ancienFichier, $nouveauFichier)) {
echo 'La copie a échoué.';
}
</syntaxhighlight>
Pour les images il existe aussi <code>imagecopyresampled</code><ref>http://php.net//manual/fr/function.imagecopyresampled.php</ref>.
== Supprimer un fichier ==
<syntaxhighlight lang="php">
if (!unlink($fichier)) {
echo 'La suppression a échoué.';
}
</syntaxhighlight>
== Interagir avec le fichier ==
=== Lecture ===
Une fois ouvert, il existe plusieurs manière de lire le contenu d'un fichier : caractère par caractère, ligne par ligne, jusqu'à une certaine taille, ou tout entier.
==== Tout le fichier ====
===== file =====
Pour stocker le fichier entier dans un tableau, on peut utiliser ''file()'' qui renvoie un tableau séparant chaque ligne du fichier :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$fichier = file($nomFichier); // ou : file("http://MonSite/" . $nomFichier);
</syntaxhighlight>
}}
Ainsi, ''$fichier[0]'' correspond à la première ligne, ''$fichier[1]'' à la seconde, etc.
Si le fichier sature la mémoire, utiliser file_lines() avec les générateurs<ref>https://www.startutorial.com/articles/view/php-generator-reading-file-content</ref>.
===== file_get_contents =====
Pour stocker le fichier entier dans un scalaire, on utilise cette fonction.
===== readfile =====
Pour afficher tout le fichier dans la sortie standard<ref>https://www.php.net/manual/en/function.readfile.php</ref>.
==== Ligne par ligne ====
===== fgets =====
La méthode générale pour lire ligne par ligne avec la fonction ''fgets'', dont la définition est la suivante :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$ligne = fgets($objetFichier);
</syntaxhighlight>
}}
La variable ''$objetFichier'' doit être le résultat de l'ouverture d'un fichier avec ''fopen''. Pour lire un fichier en entier, il suffit d’utiliser ''fgets'' en boucle ; la condition de sortie de la boucle serait alors l'arrivée à la fin de fichier, évènement notifié par la fonction ''feof''.
{{Exemple
| titre=Exemple de parcours d'un fichier ligne par ligne
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$objetFichier = fopen($nomFichier, "r"); //ouverture en lecture
if ($objetFichier) {
//on lit le fichier tant que la fin n'est pas atteinte
while (!feof($objetFichier)) {
$ligne = fgets($objetFichier);
echo $ligne;
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
===== fgetc =====
La fonction équivalente pour lire caractère par caractère se nomme ''fgetc'' :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$caractere = fgetc($objetFichier);
</syntaxhighlight>
}}
Notez que cette fonction retourne FALSE arrivée à la fin du fichier. Lors d'un parcours, il faut donc tester impérativement la valeur avant de l’utiliser, avec un test logique de la forme « $caractere !== FALSE ».
===== fgetcsv =====
Cette fonction fonctionne comme "fgets" sauf qu'en plus elle utilise le séparateur "," (qui peut être changé par le paramètre "delimiter"<ref>http://php.net/manual/fr/function.fgetcsv.php</ref>) pour créer un sous-tableau de champs par ligne.
=== Écriture ===
Une fois le fichier ouvert, l'écriture se fait via la fonction ''fwrite''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fwrite($objetFichier, $chaine);
</syntaxhighlight>
}}
'''Explication''' :
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $chaine : la chaîne à écrire dans le fichier
* retour : le nombre de caractère écrits, ou FALSE si erreur
L'utilisation est alors la même que pour la lecture : ouvrir le fichier, écrire et fermer.
{{Exemple
| titre=Exemple d'écriture
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$chaine = "Je suis une chaine écrite par PHP !\n"
$objetFichier = fopen($nomFichier, "w"); //ouverture en lecture
if ($objetFichier) {
if(fwrite($objetFichier, $chaine) === FALSE) {
echo "Erreur : impossible d'écrire dans le fichier.";
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
'''Attention :''' Si vous ouvrez le fichier avec l'option ''w'' ou ''w+'', le contenu du fichier sera effacé s'il existait. Pour écrire à la fin, il faut ouvrir avec les options ''a'' ou ''a+'' (voir ci-dessus). Enfin, si vous pouvez avec l'option ''r+'', le contenu sera écrasé, puisque le pointeur de fichier sera placé au début.
Par ailleurs, la fonction ''file_put_contents()'' effectue un ''fopen()'', ''fwrite()'' et ''fclose()'' successivement<ref>http://php.net/manual/fr/function.file-put-contents.php</ref>.
=== Se déplacer ===
Parfois, il peut être nécessaire de se déplacer dans le fichier, par exemple pour revenir au début. Pour cela, il faut utiliser la fonction ''fseek'' comme suit :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, $position);
</syntaxhighlight>
}}
'''Explication :'''
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $position : la position à laquelle on veut se déplacer. Pour revenir au début, $position doit valoir zéro.
Pour aller à la fin :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, 0, SEEK_END);
</syntaxhighlight>
}}
== Fichiers uploadés ==
Copier-coller ces lignes dans un fichier vierge ''upload.php'' pour qu’il affiche le nom des fichiers qu'on upload avec :
<syntaxhighlight lang="php">
<?php
echo '
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fichier">
<input type="submit" name="envoyer" value="Uploader">
</form>';
if (isset($_FILES['fichier'])) {
echo $_FILES['fichier']['name'];
}
</syntaxhighlight>
Il existe la fonction is_uploaded_file() pour vérifier si un fichier est bien issu d'un upload<ref>https://www.php.net/manual/en/function.is-uploaded-file.php</ref>, et move_uploaded_file() pour le déplacer.
== Fichiers temporaires ==
Pour créer des fichiers qui seront automatiquement détruits en fin de connexion, le dossier temporaire est accessible avec : <code>sys_get_temp_dir()</code>.
La fonction <code>tempnam()</code> quant-à elle nomme automatiquement un nouveau fichier temporaire avec un nom unique :
<syntaxhighlight lang="php">
$fileName = tempnam(sys_get_temp_dir(), 'MonFichier1');
</syntaxhighlight>
== Fichiers distants ==
=== HTTP ===
Pour lire un fichier en HTTP (par exemple cette page web) :
<syntaxhighlight lang="php">
<?php
$page = file_get_contents("http://fr.wikibooks.org/wiki/PHP/Fichiers");
echo $page;
</syntaxhighlight>
ou<ref>[http://www.developpez.net/forums/d66310/php/langage/syntaxe/lire-contenu-page-web-grace-script-php/ developpez.net]</ref>
<syntaxhighlight lang="php">
<?php
$url = 'http://fr.wikibooks.org/wiki/PHP/Fichiers';
echo htmlspecialchars(implode('', file($url)));
</syntaxhighlight>
Pour tester si un fichier distant existe, utiliser <code>get_headers()</code><ref>http://php.net/manual/fr/function.get-headers.php</ref>.
{{remarque|fonctionne aussi bien avec HTTPS.}}
=== FTP ===
Installation : dans php.ini, décommenter "extension=ftp" (anciennement "extension=php_ftp.dll").
Déposer un fichier (sans vérifier s'il en écrase un)<ref>http://php.net/manual/fr/book.ftp.php</ref> :
<syntaxhighlight lang="php">
<?php
copy('fichier_local.txt', 'ftp://login:password@server/repertoire/fichier_distant.txt');
</syntaxhighlight>
Souvent le répertoire porte le nom de l'utilisateur, et on écrase le fichier s'il existe :
<syntaxhighlight lang="php">
<?php
$serveur = 'serveur1';
$login = 'utilisateur1';
$password = 'mdp1';
$fichier = 'fichier1';
copy($fichier, 'ftp://'.$login.':'.$password.'@'.$serveur.'/'.$login.'/'.$fichier, stream_context_create(array('ftp' => array('overwrite'=>True))));
</syntaxhighlight>
Fonctions propres au FTP, pour lire un serveur distant, y télécharger et déposer des fichiers<ref>http://php.net/manual/fr/function.ftp-nlist.php</ref> :
<syntaxhighlight lang="php">
$cnx = ftp_connect($serveur);
$loginResult = ftp_login($cnx, $login, $password);
// Liste des noms des dossiers et fichiers du dossier distant (dans le désordre)
$dossierDistant = ftp_nlist($cnx, ".");
var_dump($dossierDistant);
// Liste des éléments du dossier distant avec leurs inodes
$dossierDistant2 = ftp_rawlist($cnx, ".");
var_dump($dossierDistant2);
// Change de répertoire :
var_dump(ftp_pwd($cnx));
ftp_chdir($cnx, 'tmp');
var_dump(ftp_pwd($cnx));
// Téléchargement du dernier fichier distant
sort($dossierDistant);
$distant = $dossierDistant[sizeof($dossierDistant)-1];
$local = 'FichierLocal.txt';
if (!ftp_get($cnx, $local, $distant, FTP_BINARY)) {
echo "Erreur ftp_get\n";
} else {
ftp_delete($cnx, $distant);
}
// Téléversement d'un fichier local
$local = 'FichierLocal2.txt';
if (!ftp_put($cnx, $distant, $local, FTP_ASCII)) {
echo "Erreur ftp_put\n";
}
</syntaxhighlight>
Pour définir le timeout, voir <code>ftp_set_option()</code><ref>http://php.net/manual/fr/function.ftp-set-option.php</ref>.
=== SFTP ===
Prérequis : libssh2-1-dev && libssl-dev. Activer ssh2 dans phpinfo.
On utiliser les trois fonctions suivantes pour construire l'URL ouverte par <code>fopen</code><ref>http://php.net/manual/fr/function.ssh2-sftp.php</ref> :
<syntaxhighlight lang="php">
$connection = ssh2_connect('tools-login.wmflabs.org', 22);
ssh2_auth_password($connection, 'monLogin', 'MonMotDePasse');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/monFichier", 'r');
ssh2_disconnect($sftp);
ssh2_disconnect($connection);
</syntaxhighlight>
=== php:// ===
Ce protocole donne accès aux flux (entrant et sortant) de PHP<ref>http://php.net/manual/fr/wrappers.php.php</ref>.
* php://fd : ''{{lang|en|file descriptor}}''.
* php://filter
* php://input : lecture de ce qui est posté.
* php://memory
* php://output : écriture.
* php://stderr
* php://stdin
* php://stdout
* php://temp
== Fichiers structurés ==
Les fichiers structurés comme les PDF, XML, DOCX et XLSX peuvent facilement être manipulés par des bibliothèques et frameworks existant, qui seront abordés dans les chapitres suivants.
== Références ==
<references/>
<noinclude>[[Catégorie:Gestions des fichiers]]</noinclude>
po175iwfywvn62l3azny88fm2jxhd2f
746468
746467
2025-07-11T09:21:49Z
JackPotte
5426
/* Lecture */
746468
wikitext
text/x-wiki
<noinclude>
{{PHP}}
</noinclude>
L'utilisation de fichier peut être utile pour exporter des données à archiver ou accélérer un traitement par un système de cache. Cette page explique comment interagir avec un fichier.
== Dossiers ==
Voici les fonctions usuelles de navigation et manipulation du système de fichier.
{{attention|Il est recommandé de ne pas les disperser dans le code, mais de les regrouper dans une classe de manipulation de fichiers, pour pouvoir utiliser un stockage cloud alternativement (qui les manipule par des appels HTTP, dans un stockage "illimité").}}
=== Lecture ===
* <code>PHP_OS</code> : contient de système d'exploitation courant (ex : WINNT, Linux).
* <code>basename($path)</code> : extraire le nom du fichier à partir de son chemin.
* <code>dirname(__DIR__)</code> : extraire le répertoire parent du dossier en paramètre, au niveau précisé en second paramètre (le parent direct par défaut).
* <code>chdir($dossier)</code> : changer de dossier courant ;
* <code>opendir($dossier)</code> : ouvrir un dossier ;
* <code>closedir($dossier)</code> : fermer le dossier ;
* <code>is_dir($dossier)</code> : vérifier la présence d'un dossier ;
* <code>is_file($fichier)</code> : vérifier la présence d'un fichier ;
* <code>file_exists($fichier)</code> : vérifier la présence d'un fichier ou un dossier local<ref>http://php.net/manual/fr/function.file-exists.php</ref> ;
* <code>filesize($fichier)</code> : renvoie la taille du fichier en octet<ref>https://www.php.net/manual/en/function.filesize.php</ref> ;
* <code>readdir($dossier)</code> : lire le contenu du dossier ligne par ligne ;
* <code>scandir($dossier)</code> : lire le contenu du dossier en une fois ;
* <code>glob($regex)</code> : lire le contenu du dossier courant, avec filtrage regex (ex : *.txt)<ref>http://php.net/manual/fr/function.glob.php</ref>.
* <code>pathinfo($fichier)</code> : renvoie un tableau avec les caractéristiques du fichier : dossier, nom, extension.
* <code>mime_content_type($fichier)</code> : renvoie le type {{w|MIME}}.
{{attention|1=Généralement le suffixe du type MIME et identique à l'extension du <code>pathinfo</code>, mais il y a des exceptions, car le premier se base sur le contenu du fichier alors que le second sur son nom. Ex :
<pre>
$filePath = 'test.jpg';
var_dump(pathinfo($filePath, PATHINFO_EXTENSION)); // jpg
var_dump(mime_content_type($filePath)); // image/jpeg
</pre>
==== Récupérer certains fichiers d'un dossier ====
Par exemple, pour trouver tous les fichiers .sql du dossier "sql" :
<syntaxhighlight lang=php>
chdir('sql');
$files = glob('*.sql');
var_dump($files);
</syntaxhighlight>
=== Écriture ===
* <code>shell_exec('pwd')</code> : exécuter n'importe quelle commande [[Programmation Bash|shell]]. Le nom du répertoire courant (pwd) dans cet exemple.
* <code>mkdir()</code> (''make directory'') : créer un dossier.
* <code>rmdir()</code> (''remove directory'') : supprime un dossier non vide.
* <code>touch()</code> : créer un fichier (ou le rafraichir s'il existe).
* <code>rename()</code> : déplacer un fichier.
{{attention|Les commandes du shell_exec dépendent du système d'exploitation. Par exemple, sur Linux <code>shell_exec('ls')</code> fonctionne mais sur Windows il renvoie null et il faut utiliser <code>shell_exec('dir')</code>.
De plus, sachant que les systèmes d'exploitation n'ont pas les mêmes séparateurs de dossiers (sous Windows on utilise "\" et en unixerie c'est "/"), on peut utiliser la constante prédéfinie : <code>DIRECTORY_SEPARATOR</code> qui fonctionne pour les deux<ref>http://php.net/manual/fr/dir.constants.php</ref>.
}}
{{remarque|1=Pour supprimer un dossier non vide<ref>https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty</ref> :
<pre>
array_map('unlink', glob('your/path/*.*'));
rmdir('your/path');
</pre>
}}
== Droits des fichiers ==
=== Windows ===
Sous Windows il suffit de se rendre dans l'onglet sécurité des propriétés d'un fichier, pour cocher les cases autorisant le programme à le lire et/ou le modifier.
=== Unix ===
''chmod'' est le système de droit d'accès a un fichier {{w|Unix}}. Il s'agit d'un [[w:Permissions_Unix|nombre à trois chiffres]] que l’on attribut à un fichier (ex. : 755). Il détermine le droit d'accès au fichier en question, qui peut le modifier.
Selon sa valeur le {{w|système d'exploitation}} autorise ou non la modification du fichier. Sous GNU/Linux, l'utilisateur 'root', (superutilisateur), a tous les droits, c'est-à-dire qu’il peut modifier tous les fichiers.
Lorsque qu'un fichier est créé manuellement, le ''chmod'' du fichier en question est '''755''', avec un tel ''chmod'' nous ne pouvons pas modifier le fichier avec un script PHP. Pour pouvoir le modifier, il suffit juste de changer le ''chmod'' du fichier, en lui donnant la valeur ''766''. Sous Windows, cette notion est masquée et il suffit d’être administrateur de la machine (utilisateur par défaut) pour pouvoir modifier un fichier.
* Pour récupérer les permissions : <code>fileperms($localFilePath) & 0777</code>
* Le propriétaire : <code>fileowner($localFilePath))</code>
== Ouvrir un fichier ==
Pour déclencher l'ouverture d'un fichier chez celui qui exécute le script, on précise son type puis son emplacement :
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename='".$fichier."'");
</syntaxhighlight>
== Télécharger un fichier ==
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='".$fichier."'");
</syntaxhighlight>
{{attention|Le téléchargement ne doit pas être précédé d'affichages (ex : <code>echo</code> ou logs de warning) sinon ils apparaitront dans l'en-tête du fichier, le rendant illisible.|clear=left}}
== Zipper un fichier ==
=== Installation ===
Cette fonctionnalité est fournie nativement depuis PHP 5.2.0. Par contre sur les versions >= 7 sur Linux il faut l'installer :
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
=== Utilisation ===
Pour compresser des fichiers, il faut d'abord créer l'archive vide, puis les y ajouter un par un avec la méthode <code>addFile(Fichier source, Nom du fichier dans l'archive)</code><ref>http://php.net/manual/fr/ziparchive.addfile.php</ref> :
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f, ZipArchive::CREATE) !== true) {
exit('Impossible de créer le .zip');
}
$zip->addFile('../Temp/' . $nomFichier . '.xls', $nomFichier . '.xls');
$zip->close();
</syntaxhighlight>
=== Dézipper un fichier ===
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f) === true) {
$zip->extractTo('../Temp/');
$zip->close();
}
</syntaxhighlight>
Pour les .gz<ref>https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php</ref> :
<syntaxhighlight lang="php">
private function uncompressFile(string $target): void
{
$uncompressedFileName = str_replace('.gz', '', $target);
$file = gzopen($target, 'rb');
$outFile = fopen($uncompressedFileName, 'wb');
while (!gzeof($file)) {
fwrite($outFile, gzread($file, 4096));
}
fclose($outFile);
gzclose($file);
</syntaxhighlight>
== Éditer et fermer un fichier ==
Créer un fichier avec un attribut ''chmod'' de ''766''. Ensuite il faut ouvrir le fichier en question avant de lire/écrire. Pour cela la fonction ''fopen'' est là :
{{Principe|width=60%
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
</syntaxhighlight>
}}
'''Explication :''' La fonction ''fopen'' à besoin de deux paramètres pour pouvoir s'exécuter :
* $nomFichier, il s'agit du chemin du fichier
* $mode, il s'agit du mode de l'ouverture
La fonction ''fopen'' utilise le premier paramètre, pour déterminer le chemin du fichier a ouvrir/créer.
Voici les différents modes d'ouvertures pour la fonction ''fopen'' :
{| class="wikitable"
! Mode !! Description
|-
| align="center" | r
| (read) Ouvre en lecture seule, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | r+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | w
| (write) Ouvre en écriture seule, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | w+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a
| (append) Ouvre en écriture seule, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a+
|Ouvre en lecture et écriture, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | x
| Créé et ouvre le fichier en lecture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer. Ce mode est l'équivalent des options O_EXCL<nowiki>|</nowiki>O_CREAT pour l'appel système open(2) sous-jacente. Cette option est supportée à partir de PHP 4.3.2 et fonctionne uniquement avec des fichiers locaux.
|-
|-
| align="center" | x+
|Crée et ouvre le fichier en lecture et écriture ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en |générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer.
|-
| align="center" | c
| Ouvre le fichier en écriture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, il ne le tronque pas, sinon il le crée.
|-
|-
| align="center" | c+
| Ouvre le fichier en lecture et écriture, puis se comporte comme "c".
|}
Pour le fermer maintenant, il y a la fonction ''fclose''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
fputs($objetFichier, $contenu);
fgets($objetFichier);
fclose($objetFichier);
</syntaxhighlight>
}}
== Copier un fichier ==
<syntaxhighlight lang="php">
if (!copy($ancienFichier, $nouveauFichier)) {
echo 'La copie a échoué.';
}
</syntaxhighlight>
Pour les images il existe aussi <code>imagecopyresampled</code><ref>http://php.net//manual/fr/function.imagecopyresampled.php</ref>.
== Supprimer un fichier ==
<syntaxhighlight lang="php">
if (!unlink($fichier)) {
echo 'La suppression a échoué.';
}
</syntaxhighlight>
== Interagir avec le fichier ==
=== Lecture ===
Une fois ouvert, il existe plusieurs manière de lire le contenu d'un fichier : caractère par caractère, ligne par ligne, jusqu'à une certaine taille, ou tout entier.
==== Tout le fichier ====
===== file =====
Pour stocker le fichier entier dans un tableau, on peut utiliser ''file()'' qui renvoie un tableau séparant chaque ligne du fichier :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$fichier = file($nomFichier); // ou : file("http://MonSite/" . $nomFichier);
</syntaxhighlight>
}}
Ainsi, ''$fichier[0]'' correspond à la première ligne, ''$fichier[1]'' à la seconde, etc.
Si le fichier sature la mémoire, utiliser file_lines() avec les générateurs<ref>https://www.startutorial.com/articles/view/php-generator-reading-file-content</ref>.
===== file_get_contents =====
Pour stocker le fichier entier dans un scalaire, on utilise cette fonction.
===== readfile =====
Pour afficher tout le fichier dans la sortie standard<ref>https://www.php.net/manual/en/function.readfile.php</ref>.
==== Ligne par ligne ====
===== fgets =====
La méthode générale pour lire ligne par ligne avec la fonction ''fgets'', dont la définition est la suivante :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$ligne = fgets($objetFichier);
</syntaxhighlight>
}}
La variable ''$objetFichier'' doit être le résultat de l'ouverture d'un fichier avec ''fopen''. Pour lire un fichier en entier, il suffit d’utiliser ''fgets'' en boucle ; la condition de sortie de la boucle serait alors l'arrivée à la fin de fichier, évènement notifié par la fonction ''feof''.
{{Exemple
| titre=Exemple de parcours d'un fichier ligne par ligne
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$objetFichier = fopen($nomFichier, "r"); //ouverture en lecture
if ($objetFichier) {
//on lit le fichier tant que la fin n'est pas atteinte
while (!feof($objetFichier)) {
$ligne = fgets($objetFichier);
echo $ligne;
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
===== fgetc =====
La fonction équivalente pour lire caractère par caractère se nomme ''fgetc'' :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$caractere = fgetc($objetFichier);
</syntaxhighlight>
}}
Notez que cette fonction retourne FALSE arrivée à la fin du fichier. Lors d'un parcours, il faut donc tester impérativement la valeur avant de l’utiliser, avec un test logique de la forme « $caractere !== FALSE ».
===== fgetcsv =====
Cette fonction fonctionne comme "fgets" sauf qu'en plus elle utilise le séparateur "," (qui peut être changé par le paramètre "delimiter"<ref>http://php.net/manual/fr/function.fgetcsv.php</ref>) pour créer un sous-tableau de champs par ligne.
=== Écriture ===
Une fois le fichier ouvert, l'écriture se fait via la fonction ''fwrite''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fwrite($objetFichier, $chaine);
</syntaxhighlight>
}}
'''Explication''' :
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $chaine : la chaîne à écrire dans le fichier
* retour : le nombre de caractère écrits, ou FALSE si erreur
L'utilisation est alors la même que pour la lecture : ouvrir le fichier, écrire et fermer.
{{Exemple
| titre=Exemple d'écriture
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$chaine = "Je suis une chaine écrite par PHP !\n"
$objetFichier = fopen($nomFichier, "w"); //ouverture en lecture
if ($objetFichier) {
if(fwrite($objetFichier, $chaine) === FALSE) {
echo "Erreur : impossible d'écrire dans le fichier.";
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
'''Attention :''' Si vous ouvrez le fichier avec l'option ''w'' ou ''w+'', le contenu du fichier sera effacé s'il existait. Pour écrire à la fin, il faut ouvrir avec les options ''a'' ou ''a+'' (voir ci-dessus). Enfin, si vous pouvez avec l'option ''r+'', le contenu sera écrasé, puisque le pointeur de fichier sera placé au début.
Par ailleurs, la fonction ''file_put_contents()'' effectue un ''fopen()'', ''fwrite()'' et ''fclose()'' successivement<ref>http://php.net/manual/fr/function.file-put-contents.php</ref>.
=== Se déplacer ===
Parfois, il peut être nécessaire de se déplacer dans le fichier, par exemple pour revenir au début. Pour cela, il faut utiliser la fonction ''fseek'' comme suit :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, $position);
</syntaxhighlight>
}}
'''Explication :'''
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $position : la position à laquelle on veut se déplacer. Pour revenir au début, $position doit valoir zéro.
Pour aller à la fin :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, 0, SEEK_END);
</syntaxhighlight>
}}
== Fichiers uploadés ==
Copier-coller ces lignes dans un fichier vierge ''upload.php'' pour qu’il affiche le nom des fichiers qu'on upload avec :
<syntaxhighlight lang="php">
<?php
echo '
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fichier">
<input type="submit" name="envoyer" value="Uploader">
</form>';
if (isset($_FILES['fichier'])) {
echo $_FILES['fichier']['name'];
}
</syntaxhighlight>
Il existe la fonction is_uploaded_file() pour vérifier si un fichier est bien issu d'un upload<ref>https://www.php.net/manual/en/function.is-uploaded-file.php</ref>, et move_uploaded_file() pour le déplacer.
== Fichiers temporaires ==
Pour créer des fichiers qui seront automatiquement détruits en fin de connexion, le dossier temporaire est accessible avec : <code>sys_get_temp_dir()</code>.
La fonction <code>tempnam()</code> quant-à elle nomme automatiquement un nouveau fichier temporaire avec un nom unique :
<syntaxhighlight lang="php">
$fileName = tempnam(sys_get_temp_dir(), 'MonFichier1');
</syntaxhighlight>
== Fichiers distants ==
=== HTTP ===
Pour lire un fichier en HTTP (par exemple cette page web) :
<syntaxhighlight lang="php">
<?php
$page = file_get_contents("http://fr.wikibooks.org/wiki/PHP/Fichiers");
echo $page;
</syntaxhighlight>
ou<ref>[http://www.developpez.net/forums/d66310/php/langage/syntaxe/lire-contenu-page-web-grace-script-php/ developpez.net]</ref>
<syntaxhighlight lang="php">
<?php
$url = 'http://fr.wikibooks.org/wiki/PHP/Fichiers';
echo htmlspecialchars(implode('', file($url)));
</syntaxhighlight>
Pour tester si un fichier distant existe, utiliser <code>get_headers()</code><ref>http://php.net/manual/fr/function.get-headers.php</ref>.
{{remarque|fonctionne aussi bien avec HTTPS.}}
=== FTP ===
Installation : dans php.ini, décommenter "extension=ftp" (anciennement "extension=php_ftp.dll").
Déposer un fichier (sans vérifier s'il en écrase un)<ref>http://php.net/manual/fr/book.ftp.php</ref> :
<syntaxhighlight lang="php">
<?php
copy('fichier_local.txt', 'ftp://login:password@server/repertoire/fichier_distant.txt');
</syntaxhighlight>
Souvent le répertoire porte le nom de l'utilisateur, et on écrase le fichier s'il existe :
<syntaxhighlight lang="php">
<?php
$serveur = 'serveur1';
$login = 'utilisateur1';
$password = 'mdp1';
$fichier = 'fichier1';
copy($fichier, 'ftp://'.$login.':'.$password.'@'.$serveur.'/'.$login.'/'.$fichier, stream_context_create(array('ftp' => array('overwrite'=>True))));
</syntaxhighlight>
Fonctions propres au FTP, pour lire un serveur distant, y télécharger et déposer des fichiers<ref>http://php.net/manual/fr/function.ftp-nlist.php</ref> :
<syntaxhighlight lang="php">
$cnx = ftp_connect($serveur);
$loginResult = ftp_login($cnx, $login, $password);
// Liste des noms des dossiers et fichiers du dossier distant (dans le désordre)
$dossierDistant = ftp_nlist($cnx, ".");
var_dump($dossierDistant);
// Liste des éléments du dossier distant avec leurs inodes
$dossierDistant2 = ftp_rawlist($cnx, ".");
var_dump($dossierDistant2);
// Change de répertoire :
var_dump(ftp_pwd($cnx));
ftp_chdir($cnx, 'tmp');
var_dump(ftp_pwd($cnx));
// Téléchargement du dernier fichier distant
sort($dossierDistant);
$distant = $dossierDistant[sizeof($dossierDistant)-1];
$local = 'FichierLocal.txt';
if (!ftp_get($cnx, $local, $distant, FTP_BINARY)) {
echo "Erreur ftp_get\n";
} else {
ftp_delete($cnx, $distant);
}
// Téléversement d'un fichier local
$local = 'FichierLocal2.txt';
if (!ftp_put($cnx, $distant, $local, FTP_ASCII)) {
echo "Erreur ftp_put\n";
}
</syntaxhighlight>
Pour définir le timeout, voir <code>ftp_set_option()</code><ref>http://php.net/manual/fr/function.ftp-set-option.php</ref>.
=== SFTP ===
Prérequis : libssh2-1-dev && libssl-dev. Activer ssh2 dans phpinfo.
On utiliser les trois fonctions suivantes pour construire l'URL ouverte par <code>fopen</code><ref>http://php.net/manual/fr/function.ssh2-sftp.php</ref> :
<syntaxhighlight lang="php">
$connection = ssh2_connect('tools-login.wmflabs.org', 22);
ssh2_auth_password($connection, 'monLogin', 'MonMotDePasse');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/monFichier", 'r');
ssh2_disconnect($sftp);
ssh2_disconnect($connection);
</syntaxhighlight>
=== php:// ===
Ce protocole donne accès aux flux (entrant et sortant) de PHP<ref>http://php.net/manual/fr/wrappers.php.php</ref>.
* php://fd : ''{{lang|en|file descriptor}}''.
* php://filter
* php://input : lecture de ce qui est posté.
* php://memory
* php://output : écriture.
* php://stderr
* php://stdin
* php://stdout
* php://temp
== Fichiers structurés ==
Les fichiers structurés comme les PDF, XML, DOCX et XLSX peuvent facilement être manipulés par des bibliothèques et frameworks existant, qui seront abordés dans les chapitres suivants.
== Références ==
<references/>
<noinclude>[[Catégorie:Gestions des fichiers]]</noinclude>
dh5iva24fsivd13kkn679k0dc1ympjv
746469
746468
2025-07-11T09:22:11Z
JackPotte
5426
/* Lecture */
746469
wikitext
text/x-wiki
<noinclude>
{{PHP}}
</noinclude>
L'utilisation de fichier peut être utile pour exporter des données à archiver ou accélérer un traitement par un système de cache. Cette page explique comment interagir avec un fichier.
== Dossiers ==
Voici les fonctions usuelles de navigation et manipulation du système de fichier.
{{attention|Il est recommandé de ne pas les disperser dans le code, mais de les regrouper dans une classe de manipulation de fichiers, pour pouvoir utiliser un stockage cloud alternativement (qui les manipule par des appels HTTP, dans un stockage "illimité").}}
=== Lecture ===
* <code>PHP_OS</code> : contient de système d'exploitation courant (ex : WINNT, Linux).
* <code>basename($path)</code> : extraire le nom du fichier à partir de son chemin.
* <code>dirname(__DIR__)</code> : extraire le répertoire parent du dossier en paramètre, au niveau précisé en second paramètre (le parent direct par défaut).
* <code>chdir($dossier)</code> : changer de dossier courant ;
* <code>opendir($dossier)</code> : ouvrir un dossier ;
* <code>closedir($dossier)</code> : fermer le dossier ;
* <code>is_dir($dossier)</code> : vérifier la présence d'un dossier ;
* <code>is_file($fichier)</code> : vérifier la présence d'un fichier ;
* <code>file_exists($fichier)</code> : vérifier la présence d'un fichier ou un dossier local<ref>http://php.net/manual/fr/function.file-exists.php</ref> ;
* <code>filesize($fichier)</code> : renvoie la taille du fichier en octet<ref>https://www.php.net/manual/en/function.filesize.php</ref> ;
* <code>readdir($dossier)</code> : lire le contenu du dossier ligne par ligne ;
* <code>scandir($dossier)</code> : lire le contenu du dossier en une fois ;
* <code>glob($regex)</code> : lire le contenu du dossier courant, avec filtrage regex (ex : *.txt)<ref>http://php.net/manual/fr/function.glob.php</ref>.
* <code>pathinfo($fichier)</code> : renvoie un tableau avec les caractéristiques du fichier : dossier, nom, extension.
* <code>mime_content_type($fichier)</code> : renvoie le type {{w|MIME}}.
{{attention|1=Généralement le suffixe du type MIME et identique à l'extension du <code>pathinfo</code>, mais il y a des exceptions, car le premier se base sur le contenu du fichier alors que le second sur son nom. Ex :
<pre>
$filePath = 'test.jpg';
var_dump(pathinfo($filePath, PATHINFO_EXTENSION)); // jpg
var_dump(mime_content_type($filePath)); // image/jpeg
</pre>
}}
==== Récupérer certains fichiers d'un dossier ====
Par exemple, pour trouver tous les fichiers .sql du dossier "sql" :
<syntaxhighlight lang=php>
chdir('sql');
$files = glob('*.sql');
var_dump($files);
</syntaxhighlight>
=== Écriture ===
* <code>shell_exec('pwd')</code> : exécuter n'importe quelle commande [[Programmation Bash|shell]]. Le nom du répertoire courant (pwd) dans cet exemple.
* <code>mkdir()</code> (''make directory'') : créer un dossier.
* <code>rmdir()</code> (''remove directory'') : supprime un dossier non vide.
* <code>touch()</code> : créer un fichier (ou le rafraichir s'il existe).
* <code>rename()</code> : déplacer un fichier.
{{attention|Les commandes du shell_exec dépendent du système d'exploitation. Par exemple, sur Linux <code>shell_exec('ls')</code> fonctionne mais sur Windows il renvoie null et il faut utiliser <code>shell_exec('dir')</code>.
De plus, sachant que les systèmes d'exploitation n'ont pas les mêmes séparateurs de dossiers (sous Windows on utilise "\" et en unixerie c'est "/"), on peut utiliser la constante prédéfinie : <code>DIRECTORY_SEPARATOR</code> qui fonctionne pour les deux<ref>http://php.net/manual/fr/dir.constants.php</ref>.
}}
{{remarque|1=Pour supprimer un dossier non vide<ref>https://stackoverflow.com/questions/1653771/how-do-i-remove-a-directory-that-is-not-empty</ref> :
<pre>
array_map('unlink', glob('your/path/*.*'));
rmdir('your/path');
</pre>
}}
== Droits des fichiers ==
=== Windows ===
Sous Windows il suffit de se rendre dans l'onglet sécurité des propriétés d'un fichier, pour cocher les cases autorisant le programme à le lire et/ou le modifier.
=== Unix ===
''chmod'' est le système de droit d'accès a un fichier {{w|Unix}}. Il s'agit d'un [[w:Permissions_Unix|nombre à trois chiffres]] que l’on attribut à un fichier (ex. : 755). Il détermine le droit d'accès au fichier en question, qui peut le modifier.
Selon sa valeur le {{w|système d'exploitation}} autorise ou non la modification du fichier. Sous GNU/Linux, l'utilisateur 'root', (superutilisateur), a tous les droits, c'est-à-dire qu’il peut modifier tous les fichiers.
Lorsque qu'un fichier est créé manuellement, le ''chmod'' du fichier en question est '''755''', avec un tel ''chmod'' nous ne pouvons pas modifier le fichier avec un script PHP. Pour pouvoir le modifier, il suffit juste de changer le ''chmod'' du fichier, en lui donnant la valeur ''766''. Sous Windows, cette notion est masquée et il suffit d’être administrateur de la machine (utilisateur par défaut) pour pouvoir modifier un fichier.
* Pour récupérer les permissions : <code>fileperms($localFilePath) & 0777</code>
* Le propriétaire : <code>fileowner($localFilePath))</code>
== Ouvrir un fichier ==
Pour déclencher l'ouverture d'un fichier chez celui qui exécute le script, on précise son type puis son emplacement :
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename='".$fichier."'");
</syntaxhighlight>
== Télécharger un fichier ==
<syntaxhighlight lang="php">
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename='".$fichier."'");
</syntaxhighlight>
{{attention|Le téléchargement ne doit pas être précédé d'affichages (ex : <code>echo</code> ou logs de warning) sinon ils apparaitront dans l'en-tête du fichier, le rendant illisible.|clear=left}}
== Zipper un fichier ==
=== Installation ===
Cette fonctionnalité est fournie nativement depuis PHP 5.2.0. Par contre sur les versions >= 7 sur Linux il faut l'installer :
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
=== Utilisation ===
Pour compresser des fichiers, il faut d'abord créer l'archive vide, puis les y ajouter un par un avec la méthode <code>addFile(Fichier source, Nom du fichier dans l'archive)</code><ref>http://php.net/manual/fr/ziparchive.addfile.php</ref> :
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f, ZipArchive::CREATE) !== true) {
exit('Impossible de créer le .zip');
}
$zip->addFile('../Temp/' . $nomFichier . '.xls', $nomFichier . '.xls');
$zip->close();
</syntaxhighlight>
=== Dézipper un fichier ===
<syntaxhighlight lang="php">
$zip = new ZipArchive();
$f = '../Temp/'.$nomFichier . '.zip';
if ($zip->open($f) === true) {
$zip->extractTo('../Temp/');
$zip->close();
}
</syntaxhighlight>
Pour les .gz<ref>https://stackoverflow.com/questions/11265914/how-can-i-extract-or-uncompress-gzip-file-using-php</ref> :
<syntaxhighlight lang="php">
private function uncompressFile(string $target): void
{
$uncompressedFileName = str_replace('.gz', '', $target);
$file = gzopen($target, 'rb');
$outFile = fopen($uncompressedFileName, 'wb');
while (!gzeof($file)) {
fwrite($outFile, gzread($file, 4096));
}
fclose($outFile);
gzclose($file);
</syntaxhighlight>
== Éditer et fermer un fichier ==
Créer un fichier avec un attribut ''chmod'' de ''766''. Ensuite il faut ouvrir le fichier en question avant de lire/écrire. Pour cela la fonction ''fopen'' est là :
{{Principe|width=60%
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
</syntaxhighlight>
}}
'''Explication :''' La fonction ''fopen'' à besoin de deux paramètres pour pouvoir s'exécuter :
* $nomFichier, il s'agit du chemin du fichier
* $mode, il s'agit du mode de l'ouverture
La fonction ''fopen'' utilise le premier paramètre, pour déterminer le chemin du fichier a ouvrir/créer.
Voici les différents modes d'ouvertures pour la fonction ''fopen'' :
{| class="wikitable"
! Mode !! Description
|-
| align="center" | r
| (read) Ouvre en lecture seule, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | r+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier.
|-
|-
| align="center" | w
| (write) Ouvre en écriture seule, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | w+
|Ouvre en lecture et écriture, et place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a
| (append) Ouvre en écriture seule, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | a+
|Ouvre en lecture et écriture, et place le pointeur de fichier à la fin du fichier. Si le fichier n'existe pas, on tente de le créer.
|-
|-
| align="center" | x
| Créé et ouvre le fichier en lecture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer. Ce mode est l'équivalent des options O_EXCL<nowiki>|</nowiki>O_CREAT pour l'appel système open(2) sous-jacente. Cette option est supportée à partir de PHP 4.3.2 et fonctionne uniquement avec des fichiers locaux.
|-
|-
| align="center" | x+
|Crée et ouvre le fichier en lecture et écriture ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, fopen() va échouer, en retournant FALSE et en |générant une erreur de niveau E_WARNING.
Si le fichier n'existe pas, fopen() tente de le créer.
|-
| align="center" | c
| Ouvre le fichier en écriture seule ; place le pointeur de fichier au début du fichier.
Si le fichier existe déjà, il ne le tronque pas, sinon il le crée.
|-
|-
| align="center" | c+
| Ouvre le fichier en lecture et écriture, puis se comporte comme "c".
|}
Pour le fermer maintenant, il y a la fonction ''fclose''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$objetFichier = fopen($nomFichier, $mode);
fputs($objetFichier, $contenu);
fgets($objetFichier);
fclose($objetFichier);
</syntaxhighlight>
}}
== Copier un fichier ==
<syntaxhighlight lang="php">
if (!copy($ancienFichier, $nouveauFichier)) {
echo 'La copie a échoué.';
}
</syntaxhighlight>
Pour les images il existe aussi <code>imagecopyresampled</code><ref>http://php.net//manual/fr/function.imagecopyresampled.php</ref>.
== Supprimer un fichier ==
<syntaxhighlight lang="php">
if (!unlink($fichier)) {
echo 'La suppression a échoué.';
}
</syntaxhighlight>
== Interagir avec le fichier ==
=== Lecture ===
Une fois ouvert, il existe plusieurs manière de lire le contenu d'un fichier : caractère par caractère, ligne par ligne, jusqu'à une certaine taille, ou tout entier.
==== Tout le fichier ====
===== file =====
Pour stocker le fichier entier dans un tableau, on peut utiliser ''file()'' qui renvoie un tableau séparant chaque ligne du fichier :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$fichier = file($nomFichier); // ou : file("http://MonSite/" . $nomFichier);
</syntaxhighlight>
}}
Ainsi, ''$fichier[0]'' correspond à la première ligne, ''$fichier[1]'' à la seconde, etc.
Si le fichier sature la mémoire, utiliser file_lines() avec les générateurs<ref>https://www.startutorial.com/articles/view/php-generator-reading-file-content</ref>.
===== file_get_contents =====
Pour stocker le fichier entier dans un scalaire, on utilise cette fonction.
===== readfile =====
Pour afficher tout le fichier dans la sortie standard<ref>https://www.php.net/manual/en/function.readfile.php</ref>.
==== Ligne par ligne ====
===== fgets =====
La méthode générale pour lire ligne par ligne avec la fonction ''fgets'', dont la définition est la suivante :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$ligne = fgets($objetFichier);
</syntaxhighlight>
}}
La variable ''$objetFichier'' doit être le résultat de l'ouverture d'un fichier avec ''fopen''. Pour lire un fichier en entier, il suffit d’utiliser ''fgets'' en boucle ; la condition de sortie de la boucle serait alors l'arrivée à la fin de fichier, évènement notifié par la fonction ''feof''.
{{Exemple
| titre=Exemple de parcours d'un fichier ligne par ligne
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$objetFichier = fopen($nomFichier, "r"); //ouverture en lecture
if ($objetFichier) {
//on lit le fichier tant que la fin n'est pas atteinte
while (!feof($objetFichier)) {
$ligne = fgets($objetFichier);
echo $ligne;
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
===== fgetc =====
La fonction équivalente pour lire caractère par caractère se nomme ''fgetc'' :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
$caractere = fgetc($objetFichier);
</syntaxhighlight>
}}
Notez que cette fonction retourne FALSE arrivée à la fin du fichier. Lors d'un parcours, il faut donc tester impérativement la valeur avant de l’utiliser, avec un test logique de la forme « $caractere !== FALSE ».
===== fgetcsv =====
Cette fonction fonctionne comme "fgets" sauf qu'en plus elle utilise le séparateur "," (qui peut être changé par le paramètre "delimiter"<ref>http://php.net/manual/fr/function.fgetcsv.php</ref>) pour créer un sous-tableau de champs par ligne.
=== Écriture ===
Une fois le fichier ouvert, l'écriture se fait via la fonction ''fwrite''.
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fwrite($objetFichier, $chaine);
</syntaxhighlight>
}}
'''Explication''' :
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $chaine : la chaîne à écrire dans le fichier
* retour : le nombre de caractère écrits, ou FALSE si erreur
L'utilisation est alors la même que pour la lecture : ouvrir le fichier, écrire et fermer.
{{Exemple
| titre=Exemple d'écriture
| contenu =
<syntaxhighlight lang="php">
<?php
$nomFichier = "chemin_ou_nom_de_fichier";
$chaine = "Je suis une chaine écrite par PHP !\n"
$objetFichier = fopen($nomFichier, "w"); //ouverture en lecture
if ($objetFichier) {
if(fwrite($objetFichier, $chaine) === FALSE) {
echo "Erreur : impossible d'écrire dans le fichier.";
}
fclose($objetFichier);
} else {
echo "Erreur : impossible d'ouvrir le fichier.";
}
</syntaxhighlight>
}}
'''Attention :''' Si vous ouvrez le fichier avec l'option ''w'' ou ''w+'', le contenu du fichier sera effacé s'il existait. Pour écrire à la fin, il faut ouvrir avec les options ''a'' ou ''a+'' (voir ci-dessus). Enfin, si vous pouvez avec l'option ''r+'', le contenu sera écrasé, puisque le pointeur de fichier sera placé au début.
Par ailleurs, la fonction ''file_put_contents()'' effectue un ''fopen()'', ''fwrite()'' et ''fclose()'' successivement<ref>http://php.net/manual/fr/function.file-put-contents.php</ref>.
=== Se déplacer ===
Parfois, il peut être nécessaire de se déplacer dans le fichier, par exemple pour revenir au début. Pour cela, il faut utiliser la fonction ''fseek'' comme suit :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, $position);
</syntaxhighlight>
}}
'''Explication :'''
* $objetFichier : variable pointant vers un fichier ouvert avec ''fopen''
* $position : la position à laquelle on veut se déplacer. Pour revenir au début, $position doit valoir zéro.
Pour aller à la fin :
{{Principe
| contenu =
<syntaxhighlight lang="php">
<?php
fseek($objetFichier, 0, SEEK_END);
</syntaxhighlight>
}}
== Fichiers uploadés ==
Copier-coller ces lignes dans un fichier vierge ''upload.php'' pour qu’il affiche le nom des fichiers qu'on upload avec :
<syntaxhighlight lang="php">
<?php
echo '
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fichier">
<input type="submit" name="envoyer" value="Uploader">
</form>';
if (isset($_FILES['fichier'])) {
echo $_FILES['fichier']['name'];
}
</syntaxhighlight>
Il existe la fonction is_uploaded_file() pour vérifier si un fichier est bien issu d'un upload<ref>https://www.php.net/manual/en/function.is-uploaded-file.php</ref>, et move_uploaded_file() pour le déplacer.
== Fichiers temporaires ==
Pour créer des fichiers qui seront automatiquement détruits en fin de connexion, le dossier temporaire est accessible avec : <code>sys_get_temp_dir()</code>.
La fonction <code>tempnam()</code> quant-à elle nomme automatiquement un nouveau fichier temporaire avec un nom unique :
<syntaxhighlight lang="php">
$fileName = tempnam(sys_get_temp_dir(), 'MonFichier1');
</syntaxhighlight>
== Fichiers distants ==
=== HTTP ===
Pour lire un fichier en HTTP (par exemple cette page web) :
<syntaxhighlight lang="php">
<?php
$page = file_get_contents("http://fr.wikibooks.org/wiki/PHP/Fichiers");
echo $page;
</syntaxhighlight>
ou<ref>[http://www.developpez.net/forums/d66310/php/langage/syntaxe/lire-contenu-page-web-grace-script-php/ developpez.net]</ref>
<syntaxhighlight lang="php">
<?php
$url = 'http://fr.wikibooks.org/wiki/PHP/Fichiers';
echo htmlspecialchars(implode('', file($url)));
</syntaxhighlight>
Pour tester si un fichier distant existe, utiliser <code>get_headers()</code><ref>http://php.net/manual/fr/function.get-headers.php</ref>.
{{remarque|fonctionne aussi bien avec HTTPS.}}
=== FTP ===
Installation : dans php.ini, décommenter "extension=ftp" (anciennement "extension=php_ftp.dll").
Déposer un fichier (sans vérifier s'il en écrase un)<ref>http://php.net/manual/fr/book.ftp.php</ref> :
<syntaxhighlight lang="php">
<?php
copy('fichier_local.txt', 'ftp://login:password@server/repertoire/fichier_distant.txt');
</syntaxhighlight>
Souvent le répertoire porte le nom de l'utilisateur, et on écrase le fichier s'il existe :
<syntaxhighlight lang="php">
<?php
$serveur = 'serveur1';
$login = 'utilisateur1';
$password = 'mdp1';
$fichier = 'fichier1';
copy($fichier, 'ftp://'.$login.':'.$password.'@'.$serveur.'/'.$login.'/'.$fichier, stream_context_create(array('ftp' => array('overwrite'=>True))));
</syntaxhighlight>
Fonctions propres au FTP, pour lire un serveur distant, y télécharger et déposer des fichiers<ref>http://php.net/manual/fr/function.ftp-nlist.php</ref> :
<syntaxhighlight lang="php">
$cnx = ftp_connect($serveur);
$loginResult = ftp_login($cnx, $login, $password);
// Liste des noms des dossiers et fichiers du dossier distant (dans le désordre)
$dossierDistant = ftp_nlist($cnx, ".");
var_dump($dossierDistant);
// Liste des éléments du dossier distant avec leurs inodes
$dossierDistant2 = ftp_rawlist($cnx, ".");
var_dump($dossierDistant2);
// Change de répertoire :
var_dump(ftp_pwd($cnx));
ftp_chdir($cnx, 'tmp');
var_dump(ftp_pwd($cnx));
// Téléchargement du dernier fichier distant
sort($dossierDistant);
$distant = $dossierDistant[sizeof($dossierDistant)-1];
$local = 'FichierLocal.txt';
if (!ftp_get($cnx, $local, $distant, FTP_BINARY)) {
echo "Erreur ftp_get\n";
} else {
ftp_delete($cnx, $distant);
}
// Téléversement d'un fichier local
$local = 'FichierLocal2.txt';
if (!ftp_put($cnx, $distant, $local, FTP_ASCII)) {
echo "Erreur ftp_put\n";
}
</syntaxhighlight>
Pour définir le timeout, voir <code>ftp_set_option()</code><ref>http://php.net/manual/fr/function.ftp-set-option.php</ref>.
=== SFTP ===
Prérequis : libssh2-1-dev && libssl-dev. Activer ssh2 dans phpinfo.
On utiliser les trois fonctions suivantes pour construire l'URL ouverte par <code>fopen</code><ref>http://php.net/manual/fr/function.ssh2-sftp.php</ref> :
<syntaxhighlight lang="php">
$connection = ssh2_connect('tools-login.wmflabs.org', 22);
ssh2_auth_password($connection, 'monLogin', 'MonMotDePasse');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/monFichier", 'r');
ssh2_disconnect($sftp);
ssh2_disconnect($connection);
</syntaxhighlight>
=== php:// ===
Ce protocole donne accès aux flux (entrant et sortant) de PHP<ref>http://php.net/manual/fr/wrappers.php.php</ref>.
* php://fd : ''{{lang|en|file descriptor}}''.
* php://filter
* php://input : lecture de ce qui est posté.
* php://memory
* php://output : écriture.
* php://stderr
* php://stdin
* php://stdout
* php://temp
== Fichiers structurés ==
Les fichiers structurés comme les PDF, XML, DOCX et XLSX peuvent facilement être manipulés par des bibliothèques et frameworks existant, qui seront abordés dans les chapitres suivants.
== Références ==
<references/>
<noinclude>[[Catégorie:Gestions des fichiers]]</noinclude>
efc50wrjcds5ur2qfulsdpz2471zgs6
Mathc complexes/069
0
82609
746470
746420
2025-07-11T09:57:29Z
Xhungab
23827
746470
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/a26| '''Gauss-Jordan''']]
:
{{Partie{{{type|}}}|L'équation d'un polynôme}}
:
Copier la bibliothèque dans votre répertoire de travail avec les fichiers des parties précédentes :
*[[Mathc complexes/062| '''d.h ..................... Déclaration des fichiers h''']]
Ne pas conserver le fichier d.h avec la bibliothèque après avoir testé les exemples.
'''Présentation :'''
<syntaxhighlight lang="c">
Calculons les coefficients d'un polynôme.
y = ax**2 + bx + c
qui passe par ces trois points.
x[1], y[1]
x[2], y[2]
x[3], y[3]
En utilisant les points nous obtenons la matrice :
x**2 x**1 x**0 y
x[1]**2 x[1]**1 x[1]**0 y[1]
x[2]**2 x[2]**1 x[2]**0 y[2]
x[3]**2 x[3]**1 x[3]**0 y[3]
Que nous pouvons écrire :
x**2 x 1 y
x[1]**2 x[1] 1 y[1]
x[2]**2 x[2] 1 y[2]
x[3]**2 x[3] 1 y[3]
Utilisons la fonction gj_TP_mR(Ab); pour résoudre
le système qui va nous donner les coefficients a,b,c
</syntaxhighlight>
Les exemples :
* [[Mathc complexes/063|c00a.c ]], [[Mathc complexes/06w| QR ]], [[Mathc complexes/072| XVD:PseudoInverse ]], [[Mathc complexes/07f| '''inv_mZ() invgj_mZ()''' ]]..... y = ax**2 + bx + c
* [[Mathc complexes/064|c00b.c ]], [[Mathc complexes/06x| QR ]], [[Mathc complexes/073| XVD:PseudoInverse ]], [[Mathc complexes/07g| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/065|c00c.c ]], [[Mathc complexes/06y| QR ]], [[Mathc complexes/074| XVD:PseudoInverse ]], [[Mathc complexes/07h| '''inv_mZ() invgj_mZ()''' ]] ..... y = ax**3 + bx**2 + cx + d
* [[Mathc complexes/066|c00d.c ]], [[Mathc complexes/06z| QR ]], [[Mathc complexes/075| XVD:PseudoInverse ]], [[Mathc complexes/07i| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/067|c00e.c ]], [[Mathc complexes/070| QR ]], ................................... [[Mathc complexes/07j| '''inv_mZ() invgj_mZ()''' ]] ..... y = ax**4 + bx**3 + cx**2 + dx + e
* [[Mathc complexes/068|c00f.c ]], [[Mathc complexes/071| QR ]], .................................... [[Mathc complexes/07k| '''inv_mZ() invgj_mZ()''' ]]
{{AutoCat}}
3keuco1ysoiawsecugmtme9bevids5v
Mathc complexes/06a
0
82617
746457
746421
2025-07-10T21:24:20Z
Xhungab
23827
746457
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/a26| '''Gauss-Jordan''']]
:
:
{{Partie{{{type|}}}|L'équation d'un conique }}
:
Copier la bibliothèque dans votre répertoire de travail avec les fichiers des parties précédentes :
*[[Mathc complexes/06b| '''d.h ..................... Déclaration des fichiers h''']]
Ne pas conserver le fichier d.h avec la bibliothèque après avoir testé les exemples.
'''Présentation :'''
<syntaxhighlight lang="C">
Trouver les coefficients a, b, c, d, e du conique,
ax**2 + by**2 + cx + dy + e = 0
qui passe par ces quatre points.
(x[1],y[1]) (x[2],y[2]) (x[3],y[3]) (x[4],y[4])
En utilisant les quatre points nous obtenons la matrice.
(a)x**2 (b)y**2 (c)x (d)y (e) = 0
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
x[4]**2 y[4]**2 x[4] y[4] 1 0
Ce système à quatre lignes et cinq inconnus (a, b, c, d, e).
C'est un système homogène, il a donc une infinité de solution.
Pour trouver une solution j'ai choisi de poser que a = 1.
Nous avons donc cinq lignes et cinq inconnus.
1 0 0 0 0 1
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
x[4]**2 y[4]**2 x[4] y[4] 1 0
Il suffit maintenant de résoudre le système.
</syntaxhighlight>
Quelques exemples :
* [[Mathc complexes/06c|c00a.c ]], [[Mathc complexes/06h| '''QR''' ]], [[Mathc matrices/07j| XVD:PseudoInverse ]], [[Mathc complexes/07a| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06d|c00b.c ]], [[Mathc complexes/06i| '''QR''' ]], [[Mathc matrices/07k| XVD:PseudoInverse ]], [[Mathc complexes/07b| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06e|c00c.c ]], [[Mathc complexes/06j| '''QR''' ]], [[Mathc matrices/07l| XVD:PseudoInverse ]], [[Mathc complexes/07c| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06f|c00d.c ]], [[Mathc complexes/06k| '''QR''' ]], [[Mathc matrices/07m| XVD:PseudoInverse ]], [[Mathc complexes/07d| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06g|c00e.c ]], [[Mathc complexes/06l| '''QR''' ]], [[Mathc matrices/07n| XVD:PseudoInverse ]], [[Mathc complexes/07e| '''inv_mZ() invgj_mZ()''' ]]
{{AutoCat}}
btxbpto01dmc1ur5r4nj835pby7vhxg
746463
746457
2025-07-10T21:41:25Z
Xhungab
23827
746463
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/a26| '''Gauss-Jordan''']]
:
:
{{Partie{{{type|}}}|L'équation d'un conique }}
:
Copier la bibliothèque dans votre répertoire de travail avec les fichiers des parties précédentes :
*[[Mathc complexes/06b| '''d.h ..................... Déclaration des fichiers h''']]
Ne pas conserver le fichier d.h avec la bibliothèque après avoir testé les exemples.
'''Présentation :'''
<syntaxhighlight lang="C">
Trouver les coefficients a, b, c, d, e du conique,
ax**2 + by**2 + cx + dy + e = 0
qui passe par ces quatre points.
(x[1],y[1]) (x[2],y[2]) (x[3],y[3]) (x[4],y[4])
En utilisant les quatre points nous obtenons la matrice.
(a)x**2 (b)y**2 (c)x (d)y (e) = 0
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
x[4]**2 y[4]**2 x[4] y[4] 1 0
Ce système à quatre lignes et cinq inconnus (a, b, c, d, e).
C'est un système homogène, il a donc une infinité de solution.
Pour trouver une solution j'ai choisi de poser que a = 1.
Nous avons donc cinq lignes et cinq inconnus.
1 0 0 0 0 1
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
x[4]**2 y[4]**2 x[4] y[4] 1 0
Il suffit maintenant de résoudre le système.
</syntaxhighlight>
'''Exemples avec :''' gj_TP_mZ(); '''QR_mZ();''' X_U_mZ();X_V_mZ();
* [[Mathc complexes/06c|c00a.c ]], [[Mathc complexes/06h| '''QR''' ]], [[Mathc matrices/07j| XVD:PseudoInverse ]], [[Mathc complexes/07a| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06d|c00b.c ]], [[Mathc complexes/06i| '''QR''' ]], [[Mathc matrices/07k| XVD:PseudoInverse ]], [[Mathc complexes/07b| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06e|c00c.c ]], [[Mathc complexes/06j| '''QR''' ]], [[Mathc matrices/07l| XVD:PseudoInverse ]], [[Mathc complexes/07c| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06f|c00d.c ]], [[Mathc complexes/06k| '''QR''' ]], [[Mathc matrices/07m| XVD:PseudoInverse ]], [[Mathc complexes/07d| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06g|c00e.c ]], [[Mathc complexes/06l| '''QR''' ]], [[Mathc matrices/07n| XVD:PseudoInverse ]], [[Mathc complexes/07e| '''inv_mZ() invgj_mZ()''' ]]
{{AutoCat}}
5m53h1yy6vpt08822pv4foq9whayujv
Mathc complexes/06m
0
82629
746449
746422
2025-07-10T20:52:27Z
Xhungab
23827
746449
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/a26| '''Gauss-Jordan''']]
:
{{Partie{{{type|}}}|L'équation d'un cercle}}
:
Copier la bibliothèque dans votre répertoire de travail avec les fichiers des parties précédentes :
*[[Mathc complexes/06n| '''d.h ..................... Déclaration des fichiers h''']]
Ne pas conserver le fichier d.h avec la bibliothèque après avoir testé les exemples.
'''Présentation :'''
<syntaxhighlight lang="C">
Calculons les coefficients a, b, c, d d'un cercle,
ax**2 + ay**2 + bx + cy + d = 0
Qui passe par ces trois points.
(x[1],y[1]) (x[2],y[2]) (x[3],y[3])
En utilisant ces trois points nous avons cette matrice.
(a)x**2 (a)y**2 (b)x (c)y (d) = 0
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
Ce système a trois lignes et quatre inconnues.
Il est homogène, donc il a une infinité de solution.
Pour trouver une solution j'ai choisi que a = 1.
Nous obtenons cette matrice.
(a)x**2 (a)y**2
1 0 0 0 0 1
0 1 0 0 0 1
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
Il suffit de resoudre le système.
</syntaxhighlight>
Deux exemples :
* [[Mathc complexes/06o|c00a.c ]], [[Mathc complexes/06s| '''QR''' ]], [[Mathc matrices/07f| XVD:PseudoInverse ]], [[Mathc complexes/076| '''inv_mR() invgj_mR()''' ]]
* [[Mathc complexes/06p|c00b.c ]], [[Mathc complexes/06t| '''QR''' ]], [[Mathc matrices/07g| XVD:PseudoInverse ]], [[Mathc complexes/077| '''inv_mR() invgj_mR()''' ]]
* [[Mathc complexes/06q|c00c.c ]], [[Mathc complexes/06u| '''QR''' ]], [[Mathc matrices/07h| XVD:PseudoInverse ]], [[Mathc complexes/078| '''inv_mR() invgj_mR()''' ]]
* [[Mathc complexes/06r|c00d.c ]], [[Mathc complexes/06v| '''QR''' ]], [[Mathc matrices/07i| XVD:PseudoInverse ]], [[Mathc complexes/079| '''inv_mR() invgj_mR()''' ]]
{{AutoCat}}
hntaekhktc1et4x0pal9mjsxmyh1ukq
746455
746449
2025-07-10T21:04:57Z
Xhungab
23827
746455
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/a26| '''Gauss-Jordan''']]
:
{{Partie{{{type|}}}|L'équation d'un cercle}}
:
Copier la bibliothèque dans votre répertoire de travail avec les fichiers des parties précédentes :
*[[Mathc complexes/06n| '''d.h ..................... Déclaration des fichiers h''']]
Ne pas conserver le fichier d.h avec la bibliothèque après avoir testé les exemples.
'''Présentation :'''
<syntaxhighlight lang="C">
Calculons les coefficients a, b, c, d d'un cercle,
ax**2 + ay**2 + bx + cy + d = 0
Qui passe par ces trois points.
(x[1],y[1]) (x[2],y[2]) (x[3],y[3])
En utilisant ces trois points nous avons cette matrice.
(a)x**2 (a)y**2 (b)x (c)y (d) = 0
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
Ce système a trois lignes et quatre inconnues.
Il est homogène, donc il a une infinité de solution.
Pour trouver une solution j'ai choisi que a = 1.
Nous obtenons cette matrice.
(a)x**2 (a)y**2
1 0 0 0 0 1
0 1 0 0 0 1
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
Il suffit de resoudre le système.
</syntaxhighlight>
'''Exemples avec :''' gj_TP_mZ(); '''QR_mZ();''' X_U_mZ();X_V_mZ();
* [[Mathc complexes/06o|c00a.c ]], [[Mathc complexes/06s| '''QR''' ]], [[Mathc matrices/07f| XVD:PseudoInverse ]], [[Mathc complexes/076| '''inv_mR() invgj_mR()''' ]]
* [[Mathc complexes/06p|c00b.c ]], [[Mathc complexes/06t| '''QR''' ]], [[Mathc matrices/07g| XVD:PseudoInverse ]], [[Mathc complexes/077| '''inv_mR() invgj_mR()''' ]]
* [[Mathc complexes/06q|c00c.c ]], [[Mathc complexes/06u| '''QR''' ]], [[Mathc matrices/07h| XVD:PseudoInverse ]], [[Mathc complexes/078| '''inv_mR() invgj_mR()''' ]]
* [[Mathc complexes/06r|c00d.c ]], [[Mathc complexes/06v| '''QR''' ]], [[Mathc matrices/07i| XVD:PseudoInverse ]], [[Mathc complexes/079| '''inv_mR() invgj_mR()''' ]]
{{AutoCat}}
70gfm0pdtdh93osfy1roxd669bmwhki
746456
746455
2025-07-10T21:06:00Z
Xhungab
23827
746456
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/a26| '''Gauss-Jordan''']]
:
{{Partie{{{type|}}}|L'équation d'un cercle}}
:
Copier la bibliothèque dans votre répertoire de travail avec les fichiers des parties précédentes :
*[[Mathc complexes/06n| '''d.h ..................... Déclaration des fichiers h''']]
Ne pas conserver le fichier d.h avec la bibliothèque après avoir testé les exemples.
'''Présentation :'''
<syntaxhighlight lang="C">
Calculons les coefficients a, b, c, d d'un cercle,
ax**2 + ay**2 + bx + cy + d = 0
Qui passe par ces trois points.
(x[1],y[1]) (x[2],y[2]) (x[3],y[3])
En utilisant ces trois points nous avons cette matrice.
(a)x**2 (a)y**2 (b)x (c)y (d) = 0
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
Ce système a trois lignes et quatre inconnues.
Il est homogène, donc il a une infinité de solution.
Pour trouver une solution j'ai choisi que a = 1.
Nous obtenons cette matrice.
(a)x**2 (a)y**2
1 0 0 0 0 1
0 1 0 0 0 1
x[1]**2 y[1]**2 x[1] y[1] 1 0
x[2]**2 y[2]**2 x[2] y[2] 1 0
x[3]**2 y[3]**2 x[3] y[3] 1 0
Il suffit de resoudre le système.
</syntaxhighlight>
'''Exemples avec :''' gj_TP_mZ(); '''QR_mZ();''' X_U_mZ();X_V_mZ();
* [[Mathc complexes/06o|c00a.c ]], [[Mathc complexes/06s| '''QR''' ]], [[Mathc matrices/07f| XVD:PseudoInverse ]], [[Mathc complexes/076| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06p|c00b.c ]], [[Mathc complexes/06t| '''QR''' ]], [[Mathc matrices/07g| XVD:PseudoInverse ]], [[Mathc complexes/077| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06q|c00c.c ]], [[Mathc complexes/06u| '''QR''' ]], [[Mathc matrices/07h| XVD:PseudoInverse ]], [[Mathc complexes/078| '''inv_mZ() invgj_mZ()''' ]]
* [[Mathc complexes/06r|c00d.c ]], [[Mathc complexes/06v| '''QR''' ]], [[Mathc matrices/07i| XVD:PseudoInverse ]], [[Mathc complexes/079| '''inv_mZ() invgj_mZ()''' ]]
{{AutoCat}}
ok9x60sbqrkqvhi2o9fewqyki5ee3mq
Mathc complexes/06w
0
82639
746482
746222
2025-07-11T11:12:05Z
Xhungab
23827
746482
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00a.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R3*(C2*C2)] ={
1,0, 6,0,
2,0, 3,0,
3,0, 5,0 };
double ab[RA*((CA+Cb)*C2)]={
/* x**2 x**1 x**0 = y */
+1,0, +1,0, +1,0, +6,0,
+4,0, +2,0, +1,0, +3,0,
+9,0, +3,0, +1,0, +5,0
};
double **XY = ca_A_mZ(xy,i_mZ(R3,C2));
double **Ab = ca_A_mZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x = invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c of the curve \n\n");
printf(" y = ax**2 + bx + c (x**0 = 1) \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n\n");
printf(" x**2 x**1 x**0 = y");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P2,C6);
printf(" The coefficients a, b, c, of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f \n\n"
,x[R1][C1],x[R2][C1],x[R3][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c of the curve
y = ax**2 + bx + c (x**0 = 1)
that passes through the points.
x y
+1 +6
+2 +3
+3 +5
Using the given XY, we obtain this matrix.
x**2 x**1 x**0 = y
+1.00 +1.00 +1.00 +6.00
+4.00 +2.00 +1.00 +3.00
+9.00 +3.00 +1.00 +5.00
Press return to continue.
Q :
+0.1010 +0.7184 +0.6882
+0.4041 +0.6025 -0.6882
+0.9091 -0.3476 +0.2294
R :
+9.8995 +3.6365 +1.4142
-0.0000 +0.8806 +0.9733
+0.0000 +0.0000 +0.2294
Q_T :
+1.0102e-01 +4.0406e-01 +9.0914e-01
+7.1841e-01 +6.0254e-01 -3.4762e-01
+6.8825e-01 -6.8825e-01 +2.2942e-01
invR :
+1.0102e-01 -4.1714e-01 +1.1471e+00
+0.0000e+00 +1.1355e+00 -4.8177e+00
+0.0000e+00 -0.0000e+00 +4.3589e+00
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
+2.50
-10.50
+14.00
The coefficients a, b, c, of the curve are :
y = +2.50x**2 -10.50x +14.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
apadtsj1tu2kpxje1zfynvowtc54dha
Mathc complexes/06x
0
82640
746483
746225
2025-07-11T11:13:14Z
Xhungab
23827
746483
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00b.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R3*(C2*C2)] ={
1,0, -9,0,
2,0, 8,0,
3,0, -8,0 };
double ab[RA*((CA+Cb)*C2)]={
/* x**2 x**1 x**0 = y */
+1,0, +1,0, +1,0, -9,0,
+4,0, +2,0, +1,0, +8,0,
+9,0, +3,0, +1,0, -8,0,
};
double **XY = ca_A_mZ(xy,i_mZ(R3,C2));
double **Ab = ca_A_mZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x = invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c of the curve \n\n");
printf(" y = ax**2 + bx + c (x**0 = 1) \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n\n");
printf(" x**2 x**1 x**0 = y");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P2,C6);
printf(" The coefficients a, b, c, of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f \n\n"
,x[R1][C1],x[R2][C1],x[R3][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c of the curve
y = ax**2 + bx + c (x**0 = 1)
that passes through the points.
x y
+1 -9
+2 +8
+3 -8
Using the given XY, we obtain this matrix.
x**2 x**1 x**0 = y
+1.00 +1.00 +1.00 -9.00
+4.00 +2.00 +1.00 +8.00
+9.00 +3.00 +1.00 -8.00
Press return to continue.
Q :
+0.1010 +0.7184 +0.6882
+0.4041 +0.6025 -0.6882
+0.9091 -0.3476 +0.2294
R :
+9.8995 +3.6365 +1.4142
-0.0000 +0.8806 +0.9733
+0.0000 +0.0000 +0.2294
Q_T :
+1.0102e-01 +4.0406e-01 +9.0914e-01
+7.1841e-01 +6.0254e-01 -3.4762e-01
+6.8825e-01 -6.8825e-01 +2.2942e-01
invR :
+1.0102e-01 -4.1714e-01 +1.1471e+00
+0.0000e+00 +1.1355e+00 -4.8177e+00
+0.0000e+00 -0.0000e+00 +4.3589e+00
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
-16.50
+66.50
-59.00
The coefficients a, b, c, of the curve are :
y = -16.50x**2 +66.50x -59.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
g4sy70m9ycmz1uv16awuec919lesxlt
Mathc complexes/06y
0
82641
746484
746229
2025-07-11T11:13:47Z
Xhungab
23827
746484
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00c.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
-5,0, -3,0,
-2,0, 0,0,
2,0, 3,0,
3,0, -2,0 };
double ab[RA*((CA+Cb)*C2)]={
/* x**3 x**2 x**1 x**0 y */
-125,0, +25,0, -5,0, +1,0, -3,0,
-8,0, +4,0, -2,0, +1,0, +0,0,
+8,0, +4,0, +2,0, +1,0, +3,0,
+27,0, +9,0, +3,0, +1,0, -2,0,
};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **Ab = ca_A_mZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d of the curve \n\n");
printf(" y = ax**3 + bx**2 + cx + d \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n");
printf(" x**3 x**2 x**1 x**0 y\n");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
stop();
clrscrn();
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P3,C6);
printf(" The coefficients a, b, c, d of the curve are : \n\n"
" y = %+.3fx**3 %+.3fx**2 %+.3fx %+.3f\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d of the curve
y = ax**3 + bx**2 + cx + d
that passes through the points.
x y
-5 -3
-2 +0
+2 +3
+3 -2
Using the given XY, we obtain this matrix.
x**3 x**2 x**1 x**0 y
-125.00 +25.00 -5.00 +1.00 -3.00
-8.00 +4.00 -2.00 +1.00 +0.00
+8.00 +4.00 +2.00 +1.00 +3.00
+27.00 +9.00 +3.00 +1.00 -2.00
Press return to continue.
Q :
-0.9737 +0.2054 +0.0819 -0.0556
-0.0623 +0.1700 -0.9033 +0.3889
+0.0623 +0.3529 +0.4209 +0.8333
+0.2103 +0.8969 -0.0131 -0.3889
R :
+128.3822 -22.4486 +5.7485 -0.7633
+0.0000 +15.2990 +2.0292 +1.6252
-0.0000 +0.0000 +2.1995 -0.4136
-0.0000 +0.0000 -0.0000 +0.7778
Press return to continue.
Q_T :
-9.7365e-01 -6.2314e-02 +6.2314e-02 +2.1031e-01
+2.0543e-01 +1.7002e-01 +3.5289e-01 +8.9686e-01
+8.1914e-02 -9.0331e-01 +4.2088e-01 -1.3124e-02
-5.5556e-02 +3.8889e-01 +8.3333e-01 -3.8889e-01
invR :
+7.7892e-03 +1.1429e-02 -3.0902e-02 -3.2672e-02
+0.0000e+00 +6.5364e-02 -6.0304e-02 -1.6865e-01
+0.0000e+00 -0.0000e+00 +4.5466e-01 +2.4180e-01
-0.0000e+00 +0.0000e+00 -0.0000e+00 +1.2857e+00
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
-0.139
-0.732
+1.307
+4.429
The coefficients a, b, c, d of the curve are :
y = -0.139x**3 -0.732x**2 +1.307x +4.429
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
0uxpbwxe78qp45z7pwpg419q3eplhwf
Mathc complexes/06z
0
82642
746485
746231
2025-07-11T11:14:24Z
Xhungab
23827
746485
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00d.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
-5,0, -8,0,
-2,0, 8,0,
2,0, -8,0,
5,0, 8,0};
double ab[RA*((CA+Cb)*C2)]={
/* x**3 x**2 x**1 x**0 y */
-125,0, +25,0, -5,0, +1,0, -8,0,
-8,0, +4,0, -2,0, +1,0, +8,0,
+8,0, +4,0, +2,0, +1,0, -8,0,
+125,0, +25,0, +5,0, +1,0, +8,0,
};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **Ab = ca_A_mZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d of the curve \n\n");
printf(" y = ax**3 + bx**2 + cx + d \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n");
printf(" x**3 x**2 x**1 x**0 y\n");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
stop();
clrscrn();
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P3,C6);
printf(" The coefficients a, b, c, d of the curve are : \n\n"
" y = %+.3fx**3 %+.3fx \n\n"
,x[R1][C1],x[R3][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d of the curve
y = ax**3 + bx**2 + cx + d
that passes through the points.
x y
-5 -8
-2 +8
+2 -8
+5 +8
Using the given XY, we obtain this matrix.
x**3 x**2 x**1 x**0 y
-125.00 +25.00 -5.00 +1.00 -8.00
-8.00 +4.00 -2.00 +1.00 +8.00
+8.00 +4.00 +2.00 +1.00 -8.00
+125.00 +25.00 +5.00 +1.00 +8.00
Press return to continue.
Q :
-0.7057 +0.6982 +0.0452 -0.1117
-0.0452 +0.1117 -0.7057 +0.6982
+0.0452 +0.1117 +0.7057 +0.6982
+0.7057 +0.6982 -0.0452 -0.1117
R :
+177.1384 +0.0000 +7.2373 +0.0000
+0.0000 +35.8050 +0.0000 +1.6199
-0.0000 +0.0000 +2.3710 +0.0000
-0.0000 +0.0000 +0.0000 +1.1730
Press return to continue.
Q_T :
-7.0566e-01 -4.5162e-02 +4.5162e-02 +7.0566e-01
+6.9823e-01 +1.1172e-01 +1.1172e-01 +6.9823e-01
+4.5162e-02 -7.0566e-01 +7.0566e-01 -4.5162e-02
-1.1172e-01 +6.9823e-01 +6.9823e-01 -1.1172e-01
invR :
+5.6453e-03 +0.0000e+00 -1.7232e-02 +0.0000e+00
+0.0000e+00 +2.7929e-02 +0.0000e+00 -3.8569e-02
+0.0000e+00 -0.0000e+00 +4.2176e-01 -0.0000e+00
-0.0000e+00 +0.0000e+00 -0.0000e+00 +8.5250e-01
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
+0.267
+0.000
-5.067
+0.000
The coefficients a, b, c, d of the curve are :
y = +0.267x**3 -5.067x
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
e9cuksy7c7txknn7qpb62ru6brh9wm5
Mathc complexes/070
0
82643
746486
746237
2025-07-11T11:15:04Z
Xhungab
23827
746486
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00e.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00e.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R10*(C2*C2)] ={
1,0, -5,0,
2,0, 8,0,
3,0, -7,0,
4,0, 1,0,
5,0, -4,0 };
double ab[RA*((CA+Cb)*C2)]={
/* x**4 x**3 x**2 x**1 x**0 y */
+1,0, +1,0, +1,0, +1,0, +1,0, -5,0,
+16,0, +8,0, +4,0, +2,0, +1,0, +8,0,
+81,0, +27,0, +9,0, +3,0, +1,0, -7,0,
+256,0, +64,0, +16,0, +4,0, +1,0, +1,0,
+625,0, +125,0, +25,0, +5,0, +1,0, -4,0,
};
double **XY = ca_A_mZ(xy,i_mZ(R5,C2));
double **Ab = ca_A_mZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x = invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c of the curve \n\n");
printf(" y = ax**4 + bx**3 + cx**2 + dx + e \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n");
printf(" x**4 x**3 x**2 x**1 x**0 y");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
stop();
clrscrn();
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P3,C6);
printf(" The coefficients a, b, c, d of the curve are : \n\n"
" y = %+.3fx**4 %+.3fx**3 %+.3fx**2 %+.3fx %+.3f\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c of the curve
y = ax**4 + bx**3 + cx**2 + dx + e
that passes through the points.
x y
+1 -5
+2 +8
+3 -7
+4 +1
+5 -4
Using the given XY, we obtain this matrix.
x**4 x**3 x**2 x**1 x**0 y
+1.00 +1.00 +1.00 +1.00 +1.00 -5.00
+16.00 +8.00 +4.00 +2.00 +1.00 +8.00
+81.00 +27.00 +9.00 +3.00 +1.00 -7.00
+256.00 +64.00 +16.00 +4.00 +1.00 +1.00
+625.00 +125.00 +25.00 +5.00 +1.00 -4.00
Press return to continue.
Q :
+0.0015 +0.0485 +0.4216 +0.8487 +0.3156
+0.0235 +0.2856 +0.7083 -0.1335 -0.6312
+0.1190 +0.6174 +0.2365 -0.3877 +0.6312
+0.3762 +0.6420 -0.4915 +0.3242 -0.3156
+0.9185 -0.3504 +0.1519 -0.0805 +0.0631
R :
+680.4256 +142.3006 +30.1502 +6.5033 +1.4388
+0.0000 +16.2950 +8.2602 +3.2880 +1.2431
-0.0000 -0.0000 +1.3158 +1.3410 +1.0268
+0.0000 +0.0000 +0.0000 +0.3128 +0.5711
-0.0000 -0.0000 -0.0000 -0.0000 +0.0631
Press return to continue.
Q_T :
+1.4697e-03 +2.3515e-02 +1.1904e-01 +3.7624e-01 +9.1854e-01
+4.8534e-02 +2.8560e-01 +6.1737e-01 +6.4201e-01 -3.5037e-01
+4.2165e-01 +7.0827e-01 +2.3651e-01 -4.9150e-01 +1.5186e-01
+8.4868e-01 -1.3354e-01 -3.8774e-01 +3.2419e-01 -8.0475e-02
+3.1560e-01 -6.3119e-01 +6.3119e-01 -3.1560e-01 +6.3119e-02
invR :
+1.4697e-03 -1.2834e-02 +4.6895e-02 -9.6700e-02 +3.3138e-01
+0.0000e+00 +6.1368e-02 -3.8527e-01 +1.0067e+00 -4.0502e+00
+0.0000e+00 -0.0000e+00 +7.6002e-01 -3.2586e+00 +1.7121e+01
+0.0000e+00 +0.0000e+00 +0.0000e+00 +3.1973e+00 -2.8930e+01
+0.0000e+00 -0.0000e+00 +0.0000e+00 +0.0000e+00 +1.5843e+01
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
-3.625
+44.750
-191.875
+329.750
-184.000
The coefficients a, b, c, d of the curve are :
y = -3.625x**4 +44.750x**3 -191.875x**2 +329.750x -184.000
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
13cx3tmeqdq9132z80g74fspavdhr6j
Mathc complexes/071
0
82644
746487
746239
2025-07-11T11:15:39Z
Xhungab
23827
746487
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00f.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00f.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[R10*(C2*C2)] ={
1,0, -2,0,
2,0, -2,0,
3,0, 3,0,
4,0, -9,0,
5,0, 4,0 };
double ab[RA*((CA+Cb)*C2)]={
/* x**4 x**3 x**2 x**1 x**0 y */
+1,0, +1,0, +1,0, +1,0, +1,0, -2,0,
+16,0, +8,0, +4,0, +2,0, +1,0, -2,0,
+81,0, +27,0, +9,0, +3,0, +1,0, +3,0,
+256,0, +64,0, +16,0, +4,0, +1,0, -9,0,
+625,0, +125,0, +25,0, +5,0, +1,0, +4,0,
};
double **XY = ca_A_mZ(xy,i_mZ(R5,C2));
double **Ab = ca_A_mZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));
double **Q = i_mZ(RA,CA);
double **R = i_mZ(CA,CA);
double **invR = i_mZ(CA,CA);
double **Q_T = i_mZ(CA,RA);
double **invR_Q_T = i_mZ(CA,RA);
double **x = i_mZ(CA,Cb); // x = invR * Q_T * b
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c of the curve \n\n");
printf(" y = ax**4 + bx**3 + cx**2 + dx + e \n\n");
printf(" that passes through the points. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf("\n");
printf(" Using the given XY, we obtain this matrix.\n");
printf(" x**4 x**3 x**2 x**1 x**0 y");
p_mRZ(Ab,S7,P2,C6);
stop();
clrscrn();
QR_mZ(A,Q,R);
printf(" Q :");
p_mRZ(Q,S10,P4,C6);
printf(" R :");
p_mRZ(R,S10,P4,C6);
stop();
clrscrn();
transpose_mZ(Q,Q_T);
printf(" Q_T :");
pE_mRZ(Q_T,S12,P4,C6);
inv_mZ(R,invR);
printf(" invR :");
pE_mRZ(invR,S12,P4,C6);
stop();
clrscrn();
printf(" Solving this system yields a unique\n"
" least squares solution, namely \n\n");
mul_mZ(invR,Q_T,invR_Q_T);
mul_mZ(invR_Q_T,b,x);
printf(" x = invR * Q_T * b :");
p_mRZ(x,S10,P3,C6);
printf(" The coefficients a, b, c, d of the curve are : \n\n"
" y = %+.3fx**4 %+.3fx**3 %+.3fx**2 %+.3fx %+.3f\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Ab);
f_mZ(Q);
f_mZ(Q_T);
f_mZ(R);
f_mZ(invR);
f_mZ(invR_Q_T);
f_mZ(x);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c of the curve
y = ax**4 + bx**3 + cx**2 + dx + e
that passes through the points.
x y
+1 -2
+2 -2
+3 +3
+4 -9
+5 +4
Using the given XY, we obtain this matrix.
x**4 x**3 x**2 x**1 x**0 y
+1.00 +1.00 +1.00 +1.00 +1.00 -2.00
+16.00 +8.00 +4.00 +2.00 +1.00 -2.00
+81.00 +27.00 +9.00 +3.00 +1.00 +3.00
+256.00 +64.00 +16.00 +4.00 +1.00 -9.00
+625.00 +125.00 +25.00 +5.00 +1.00 +4.00
Press return to continue.
Q :
+0.0015 +0.0485 +0.4216 +0.8487 +0.3156
+0.0235 +0.2856 +0.7083 -0.1335 -0.6312
+0.1190 +0.6174 +0.2365 -0.3877 +0.6312
+0.3762 +0.6420 -0.4915 +0.3242 -0.3156
+0.9185 -0.3504 +0.1519 -0.0805 +0.0631
R :
+680.4256 +142.3006 +30.1502 +6.5033 +1.4388
+0.0000 +16.2950 +8.2602 +3.2880 +1.2431
-0.0000 -0.0000 +1.3158 +1.3410 +1.0268
+0.0000 +0.0000 +0.0000 +0.3128 +0.5711
-0.0000 -0.0000 -0.0000 -0.0000 +0.0631
Press return to continue.
Q_T :
+1.4697e-03 +2.3515e-02 +1.1904e-01 +3.7624e-01 +9.1854e-01
+4.8534e-02 +2.8560e-01 +6.1737e-01 +6.4201e-01 -3.5037e-01
+4.2165e-01 +7.0827e-01 +2.3651e-01 -4.9150e-01 +1.5186e-01
+8.4868e-01 -1.3354e-01 -3.8774e-01 +3.2419e-01 -8.0475e-02
+3.1560e-01 -6.3119e-01 +6.3119e-01 -3.1560e-01 +6.3119e-02
invR :
+1.4697e-03 -1.2834e-02 +4.6895e-02 -9.6700e-02 +3.3138e-01
+0.0000e+00 +6.1368e-02 -3.8527e-01 +1.0067e+00 -4.0502e+00
+0.0000e+00 -0.0000e+00 +7.6002e-01 -3.2586e+00 +1.7121e+01
+0.0000e+00 +0.0000e+00 +0.0000e+00 +3.1973e+00 -2.8930e+01
+0.0000e+00 -0.0000e+00 +0.0000e+00 +0.0000e+00 +1.5843e+01
Press return to continue.
Solving this system yields a unique
least squares solution, namely
x = invR * Q_T * b :
+2.667
-30.333
+117.833
-181.167
+89.000
The coefficients a, b, c, d of the curve are :
y = +2.667x**4 -30.333x**3 +117.833x**2 -181.167x +89.000
</syntaxhighlight>
{{AutoCat}}
7ex5mgvne8gmmz2k2wsxrrdi6cub88l
Mathc complexes/072
0
82674
746488
746393
2025-07-11T11:16:32Z
Xhungab
23827
746488
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00a.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Xave as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
/* ------------------------------------ */
#define FACTOR_E +1.E-2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
+1,0, +1,0, +1,0,
+4,0, +2,0, +1,0,
+9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
+6,0,
+3,0,
+5,0
};
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **A_T = ctranspose_mZ(A, i_mZ(CA,RA));
double **b = ca_A_mZ(tb, i_mZ(RA,C1));
double **x = i_mZ(CA,C1);
double **V = i_mZ(CA,CA);
double **V_T = i_mZ(CA,CA);
double **U = i_mZ(RA,CA);
double **U_T = i_mZ(CA,RA);
double **U_TA = i_mZ(CA,CA); // CA,RA RA,CA :CA,CA
double **U_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **invU_TAV = i_mZ(CA,CA); // :CA,CA
double **V_invU_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **Pinv = i_mZ(CA,RA);
// Pinv = V_invU_TAV * U_T // CA,CA CA,RA :CA,RA
clrscrn();
printf(" A :");
p_mRZ(A, S10,P2, C6);
printf(" b :");
p_mRZ(b, S10,P2, C6);
printf(" U :");
X_U_mZ(A_T,U,FACTOR_E);
p_mRZ(U, S10,P4, C6);
printf(" V :");
X_V_mZ(A_T,V,FACTOR_E);
p_mRZ(V, S10,P4, C6);
ctranspose_mZ(U,U_T);
ctranspose_mZ(V,V_T);
stop();
clrscrn();
printf(" U_TAV :");
mul_mZ(U_T, A, U_TA); // U_TA CA,RA RA,CA :CA,CA
mul_mZ(U_TA, V, U_TAV ); // V :CA,CA
p_mRZ(U_TAV, S11,P4, C6); // U_TAV CA,CA CA,CA :CA,CA
printf(" inv(U_TAV) :");
X_inv_mZ(U_TAV, invU_TAV);
pE_mRZ(invU_TAV, S10,P4, C6);
printf(" Pinv = V * inv(U_TAV) * U_T:");
mul_mZ(V, invU_TAV, V_invU_TAV);
mul_mZ(V_invU_TAV, U_T, Pinv);
pE_mRZ(Pinv, S13,P4, C6);
stop();
clrscrn();
printf(" A x = b \n"
" Pinv A x = Pinv b \n"
" Ide x = Pinv b \n\n"
" x = Pinv b ");
mul_mZ(Pinv, b, x);
p_mRZ(x, S12,P4, C6);
printf(" The coefficients a, b, c, of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1]);
stop();
f_mZ(A);
f_mZ(A_T);
f_mZ(b);
f_mZ(x);
f_mZ(V);
f_mZ(V_T);
f_mZ(U);
f_mZ(U_T);
f_mZ(U_TA);
f_mZ(invU_TAV);
f_mZ(V_invU_TAV);
f_mZ(Pinv);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
A :
+1.00 +1.00 +1.00
+4.00 +2.00 +1.00
+9.00 +3.00 +1.00
b :
+6.00
+3.00
+5.00
U :
+0.1324 -0.8014 +0.5833
+0.4264 -0.4852 -0.7634
+0.8948 +0.3498 +0.2775
V :
+0.9288 -0.3244 +0.1793
+0.3446 +0.5777 -0.7400
+0.1365 +0.7490 +0.6483
Press return to continue.
U_TAV :
+10.6496 +0.0000 -0.0000
-0.0000 -1.2507 +0.0000
+0.0000 -0.0000 +0.1502
inv(U_TAV) :
+9.3901e-02 +0.0000e+00 +0.0000e+00
+0.0000e+00 -7.9955e-01 +0.0000e+00
+0.0000e+00 +0.0000e+00 +6.6597e+00
Pinv = V * inv(U_TAV) * U_T:
+5.0000e-01 -1.0000e+00 +5.0000e-01
-2.5000e+00 +4.0000e+00 -1.5000e+00
+3.0000e+00 -3.0000e+00 +1.0000e+00
Press return to continue.
A x = b
Pinv A x = Pinv b
Ide x = Pinv b
x = Pinv b
+2.5000
-10.5000
+14.0000
The coefficients a, b, c, of the curve are :
y = +2.50x**2 -10.50x +14.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
g6mvxybon4n2z0dsiouvphdl3mcb9pw
Mathc complexes/073
0
82675
746489
746394
2025-07-11T11:17:06Z
Xhungab
23827
746489
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00b.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Xave as : c00b.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
/* ------------------------------------ */
#define FACTOR_E +1.E-2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
+1,0, +1,0, +1,0,
+4,0, +2,0, +1,0,
+9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
-9,0,
+8,0,
-8,0,
};
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **A_T = ctranspose_mZ(A, i_mZ(CA,RA));
double **b = ca_A_mZ(tb, i_mZ(RA,C1));
double **x = i_mZ(CA,C1);
double **V = i_mZ(CA,CA);
double **V_T = i_mZ(CA,CA);
double **U = i_mZ(RA,CA);
double **U_T = i_mZ(CA,RA);
double **U_TA = i_mZ(CA,CA); // CA,RA RA,CA :CA,CA
double **U_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **invU_TAV = i_mZ(CA,CA); // :CA,CA
double **V_invU_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **Pinv = i_mZ(CA,RA);
// Pinv = V_invU_TAV * U_T // CA,CA CA,RA :CA,RA
clrscrn();
printf(" A :");
p_mRZ(A, S10,P2, C6);
printf(" b :");
p_mRZ(b, S10,P2, C6);
printf(" U :");
X_U_mZ(A_T,U,FACTOR_E);
p_mRZ(U, S10,P4, C6);
printf(" V :");
X_V_mZ(A_T,V,FACTOR_E);
p_mRZ(V, S10,P4, C6);
ctranspose_mZ(U,U_T);
ctranspose_mZ(V,V_T);
stop();
clrscrn();
printf(" U_TAV :");
mul_mZ(U_T, A, U_TA); // U_TA CA,RA RA,CA :CA,CA
mul_mZ(U_TA, V, U_TAV ); // V :CA,CA
p_mRZ(U_TAV, S11,P4, C6); // U_TAV CA,CA CA,CA :CA,CA
printf(" inv(U_TAV) :");
X_inv_mZ(U_TAV, invU_TAV);
pE_mRZ(invU_TAV, S10,P4, C6);
printf(" Pinv = V * inv(U_TAV) * U_T:");
mul_mZ(V, invU_TAV, V_invU_TAV);
mul_mZ(V_invU_TAV, U_T, Pinv);
pE_mRZ(Pinv, S13,P4, C6);
stop();
clrscrn();
printf(" A x = b \n"
" Pinv A x = Pinv b \n"
" Ide x = Pinv b \n\n"
" x = Pinv b ");
mul_mZ(Pinv, b, x);
p_mRZ(x, S12,P4, C6);
printf(" The coefficients a, b, c, of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1]);
stop();
f_mZ(A);
f_mZ(A_T);
f_mZ(b);
f_mZ(x);
f_mZ(V);
f_mZ(V_T);
f_mZ(U);
f_mZ(U_T);
f_mZ(U_TA);
f_mZ(invU_TAV);
f_mZ(V_invU_TAV);
f_mZ(Pinv);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
A :
+1.00 +1.00 +1.00
+4.00 +2.00 +1.00
+9.00 +3.00 +1.00
b :
-9.00
+8.00
-8.00
U :
+0.1324 -0.8014 +0.5833
+0.4264 -0.4852 -0.7634
+0.8948 +0.3498 +0.2775
V :
+0.9288 -0.3244 +0.1793
+0.3446 +0.5777 -0.7400
+0.1365 +0.7490 +0.6483
Press return to continue.
U_TAV :
+10.6496 +0.0000 -0.0000
-0.0000 -1.2507 +0.0000
+0.0000 -0.0000 +0.1502
inv(U_TAV) :
+9.3901e-02 +0.0000e+00 +0.0000e+00
+0.0000e+00 -7.9955e-01 +0.0000e+00
+0.0000e+00 +0.0000e+00 +6.6597e+00
Pinv = V * inv(U_TAV) * U_T:
+5.0000e-01 -1.0000e+00 +5.0000e-01
-2.5000e+00 +4.0000e+00 -1.5000e+00
+3.0000e+00 -3.0000e+00 +1.0000e+00
Press return to continue.
A x = b
Pinv A x = Pinv b
Ide x = Pinv b
x = Pinv b
-16.5000
+66.5000
-59.0000
The coefficients a, b, c, of the curve are :
y = -16.50x**2 +66.50x -59.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
7qaypmq6slprn2mep4hzo08lkdlvzs3
Mathc complexes/074
0
82676
746490
746395
2025-07-11T11:17:48Z
Xhungab
23827
746490
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00c.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Xave as : c00c.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
/* ------------------------------------ */
#define FACTOR_E +1.E-2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
-125,0, +25,0, -5,0, +1,0,
-8,0, +4,0, -2,0, +1,0,
+8,0, +4,0, +2,0, +1,0,
+27,0, +9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
-3,0,
+0,0,
+3,0,
-2,0,
};
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **A_T = ctranspose_mZ(A, i_mZ(CA,RA));
double **b = ca_A_mZ(tb, i_mZ(RA,C1));
double **x = i_mZ(CA,C1);
double **V = i_mZ(CA,CA);
double **V_T = i_mZ(CA,CA);
double **U = i_mZ(RA,CA);
double **U_T = i_mZ(CA,RA);
double **U_TA = i_mZ(CA,CA); // CA,RA RA,CA :CA,CA
double **U_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **invU_TAV = i_mZ(CA,CA); // :CA,CA
double **V_invU_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **Pinv = i_mZ(CA,RA);
// Pinv = V_invU_TAV * U_T // CA,CA CA,RA :CA,RA
clrscrn();
printf(" A :");
p_mRZ(A, S10,P2, C6);
printf(" b :");
p_mRZ(b, S10,P2, C6);
printf(" U :");
X_U_mZ(A_T,U,FACTOR_E);
p_mRZ(U, S10,P4, C6);
printf(" V :");
X_V_mZ(A_T,V,FACTOR_E);
p_mRZ(V, S10,P4, C6);
ctranspose_mZ(U,U_T);
ctranspose_mZ(V,V_T);
stop();
clrscrn();
printf(" U_TAV :");
mul_mZ(U_T, A, U_TA); // U_TA CA,RA RA,CA :CA,CA
mul_mZ(U_TA, V, U_TAV ); // V :CA,CA
p_mRZ(U_TAV, S11,P4, C6); // U_TAV CA,CA CA,CA :CA,CA
printf(" inv(U_TAV) :");
X_inv_mZ(U_TAV, invU_TAV);
pE_mRZ(invU_TAV, S10,P4, C6);
printf(" Pinv = V * inv(U_TAV) * U_T:");
mul_mZ(V, invU_TAV, V_invU_TAV);
mul_mZ(V_invU_TAV, U_T, Pinv);
pE_mRZ(Pinv, S13,P4, C6);
stop();
clrscrn();
printf(" A x = b \n"
" Pinv A x = Pinv b \n"
" Ide x = Pinv b \n\n"
" x = Pinv b ");
mul_mZ(Pinv, b, x);
p_mRZ(x, S12,P3, C6);
printf(" The coefficients a, b, c, d of the curve are : \n\n"
" y = %+.3fx**3 %+.3fx**2 %+.3fx %+.3f\n\n"
,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1]);
stop();
f_mZ(A);
f_mZ(A_T);
f_mZ(b);
f_mZ(x);
f_mZ(V);
f_mZ(V_T);
f_mZ(U);
f_mZ(U_T);
f_mZ(U_TA);
f_mZ(invU_TAV);
f_mZ(V_invU_TAV);
f_mZ(Pinv);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
A :
-125.00 +25.00 -5.00 +1.00
-8.00 +4.00 -2.00 +1.00
+8.00 +4.00 +2.00 +1.00
+27.00 +9.00 +3.00 +1.00
b :
-3.00
+0.00
+3.00
-2.00
U :
-0.9775 +0.1872 +0.0836 +0.0502
-0.0664 +0.1549 -0.9338 -0.3157
+0.0556 +0.3659 +0.3479 -0.8614
+0.1925 +0.8984 +0.0019 +0.3948
V :
-0.9837 +0.1662 +0.0633 -0.0265
+0.1743 +0.9701 +0.1068 -0.1310
-0.0438 +0.1425 -0.9665 +0.2091
+0.0061 +0.1049 +0.2248 +0.9687
Press return to continue.
U_TAV :
-130.4844 +0.0000 -0.0000 -0.0000
+0.0000 +15.3066 -0.0000 -0.0000
-0.0000 -0.0000 -2.2259 +0.0000
-0.0000 +0.0000 -0.0000 -0.7558
inv(U_TAV) :
-7.6638e-03 +0.0000e+00 +0.0000e+00 +0.0000e+00
+0.0000e+00 +6.5331e-02 +0.0000e+00 +0.0000e+00
+0.0000e+00 +0.0000e+00 -4.4926e-01 +0.0000e+00
+0.0000e+00 +0.0000e+00 +0.0000e+00 -1.3231e+00
Pinv = V * inv(U_TAV) * U_T:
-5.9524e-03 +1.6667e-02 -3.5714e-02 +2.5000e-02
+1.7857e-02 -2.4321e-14 -1.4286e-01 +1.2500e-01
+2.3810e-02 -3.1667e-01 +3.9286e-01 -1.0000e-01
-7.1429e-02 +5.0000e-01 +1.0714e+00 -5.0000e-01
Press return to continue.
A x = b
Pinv A x = Pinv b
Ide x = Pinv b
x = Pinv b
-0.139
-0.732
+1.307
+4.429
The coefficients a, b, c, d of the curve are :
y = -0.139x**3 -0.732x**2 +1.307x +4.429
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
dvj9twsg8eclarjvoqdva6sfe2wd31x
Mathc complexes/075
0
82677
746491
746396
2025-07-11T11:18:23Z
Xhungab
23827
746491
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00d.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Xave as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
/* ------------------------------------ */
#define FACTOR_E +1.E-2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
-125,0, +25,0, -5,0, +1,0,
-8,0, +4,0, -2,0, +1,0,
+8,0, +4,0, +2,0, +1,0,
+125,0, +25,0, +5,0, +1,0,};
double tb[RA*(Cb*C2)]={
-8,0,
+8,0,
-8,0,
+8,0,
};
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **A_T = ctranspose_mZ(A, i_mZ(CA,RA));
double **b = ca_A_mZ(tb, i_mZ(RA,C1));
double **x = i_mZ(CA,C1);
double **V = i_mZ(CA,CA);
double **V_T = i_mZ(CA,CA);
double **U = i_mZ(RA,CA);
double **U_T = i_mZ(CA,RA);
double **U_TA = i_mZ(CA,CA); // CA,RA RA,CA :CA,CA
double **U_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **invU_TAV = i_mZ(CA,CA); // :CA,CA
double **V_invU_TAV = i_mZ(CA,CA); // CA,CA CA,CA :CA,CA
double **Pinv = i_mZ(CA,RA);
// Pinv = V_invU_TAV * U_T // CA,CA CA,RA :CA,RA
clrscrn();
printf(" A :");
p_mRZ(A, S10,P2, C6);
printf(" b :");
p_mRZ(b, S10,P2, C6);
printf(" U :");
X_U_mZ(A_T,U,FACTOR_E);
p_mRZ(U, S10,P4, C6);
printf(" V :");
X_V_mZ(A_T,V,FACTOR_E);
p_mRZ(V, S10,P4, C6);
ctranspose_mZ(U,U_T);
ctranspose_mZ(V,V_T);
stop();
clrscrn();
printf(" U_TAV :");
mul_mZ(U_T, A, U_TA); // U_TA CA,RA RA,CA :CA,CA
mul_mZ(U_TA, V, U_TAV ); // V :CA,CA
p_mRZ(U_TAV, S11,P4, C6); // U_TAV CA,CA CA,CA :CA,CA
printf(" inv(U_TAV) :");
X_inv_mZ(U_TAV, invU_TAV);
pE_mRZ(invU_TAV, S10,P4, C6);
printf(" Pinv = V * inv(U_TAV) * U_T:");
mul_mZ(V, invU_TAV, V_invU_TAV);
mul_mZ(V_invU_TAV, U_T, Pinv);
pE_mRZ(Pinv, S13,P4, C6);
stop();
clrscrn();
printf(" A x = b \n"
" Pinv A x = Pinv b \n"
" Ide x = Pinv b \n\n"
" x = Pinv b ");
mul_mZ(Pinv, b, x);
p_mRZ(x, S12,P3, C6);
printf(" The coefficients a, b, c, of the curve are : \n\n"
" y = %+.3fx**3 %+.3fx \n\n"
,x[R1][C1],x[R3][C1]);
stop();
f_mZ(A);
f_mZ(A_T);
f_mZ(b);
f_mZ(x);
f_mZ(V);
f_mZ(V_T);
f_mZ(U);
f_mZ(U_T);
f_mZ(U_TA);
f_mZ(invU_TAV);
f_mZ(V_invU_TAV);
f_mZ(Pinv);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
A :
-125.00 +25.00 -5.00 +1.00
-8.00 +4.00 -2.00 +1.00
+8.00 +4.00 +2.00 +1.00
+125.00 +25.00 +5.00 +1.00
b :
-8.00
+8.00
-8.00
+8.00
U :
-0.7056 +0.6981 -0.0455 +0.1127
-0.0455 +0.1127 +0.7056 -0.6981
+0.0455 +0.1127 -0.7056 -0.6981
+0.7056 +0.6981 +0.0455 +0.1127
V :
+0.9992 +0.0000 -0.0408 +0.0000
+0.0000 +0.9990 +0.0000 -0.0452
+0.0408 +0.0000 +0.9992 +0.0000
+0.0000 +0.0452 +0.0000 +0.9990
Press return to continue.
U_TAV :
+177.2862 +0.0000 -0.0000 -0.0000
-0.0000 +35.8417 -0.0000 +0.0000
+0.0000 +0.0000 -2.3691 -0.0000
-0.0000 -0.0000 -0.0000 -1.1718
inv(U_TAV) :
+5.6406e-03 +0.0000e+00 +0.0000e+00 +0.0000e+00
+0.0000e+00 +2.7900e-02 +0.0000e+00 +0.0000e+00
+0.0000e+00 +0.0000e+00 -4.2211e-01 +0.0000e+00
+0.0000e+00 +0.0000e+00 +0.0000e+00 -8.5337e-01
Pinv = V * inv(U_TAV) * U_T:
-4.7619e-03 +1.1905e-02 -1.1905e-02 +4.7619e-03
+2.3810e-02 -2.3810e-02 -2.3810e-02 +2.3810e-02
+1.9048e-02 -2.9762e-01 +2.9762e-01 -1.9048e-02
-9.5238e-02 +5.9524e-01 +5.9524e-01 -9.5238e-02
Press return to continue.
A x = b
Pinv A x = Pinv b
Ide x = Pinv b
x = Pinv b
+0.267
+0.000
-5.067
-0.000
The coefficients a, b, c, of the curve are :
y = +0.267x**3 -5.067x
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
klvwziedbr127gd41pjjh1nx2k3iwfl
Mathc complexes/076
0
82701
746450
2025-07-10T20:56:43Z
Xhungab
23827
news
746450
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/06m| '''Application''']]
:
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00a.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R3*(C2*C2)] ={
1,0, -2,0,
2,0, -3,0,
3,0, 6,0 };
double ta[RA*(CA*C2)]={
/* x**2 y**2 x y e */
+1,0, +0,0, +0,0, +0,0, +0,0,
+0,0, +1,0, +0,0, +0,0, +0,0,
+1,0, +4,0, +1,0, -2,0, +1,0,
+4,0, +9,0, +2,0, -3,0, +1,0,
+9,0, +36,0, +3,0, +6,0, +1,0,};
double tb[RA*(Cb*C2)]={
+1,0,
+1,0,
+0,0,
+0,0,
+0,0, };
double **XY = ca_A_mZ(xy,i_mZ(R3,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, of a circle \n\n");
printf(" ax**2 + ay**2 + bx + cy + d = 0 \n\n");
printf(" that passes through these three XY. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
stop();
clrscrn();
printf(" Using the given XY, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv :");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" Inv :");
p_mRZ(Inv,S10,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, of a circle
ax**2 + ay**2 + bx + cy + d = 0
that passes through these three XY.
x y
+1 -2
+2 -3
+3 +6
Press return to continue.
Using the given XY, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+0.00 +1.00 +0.00 +0.00 +0.00
+1.00 +4.00 +1.00 -2.00 +1.00
+4.00 +9.00 +2.00 -3.00 +1.00
+9.00 +36.00 +3.00 +6.00 +1.00
b :
+1.00
+1.00
+0.00
+0.00
+0.00
Inv :
+1.0000e+00 -0.0000e+00 -0.0000e+00 +0.0000e+00 -0.0000e+00
-0.0000e+00 +1.0000e+00 +0.0000e+00 +0.0000e+00 +0.0000e+00
-3.2000e+00 -7.2000e+00 -9.0000e-01 +8.0000e-01 +1.0000e-01
-2.0000e-01 -2.2000e+00 +1.0000e-01 -2.0000e-01 +1.0000e-01
+1.8000e+00 -1.2000e+00 +2.1000e+00 -1.2000e+00 +1.0000e-01
Press return to continue.
Inv :
+1.0000 -0.0000 -0.0000 +0.0000 -0.0000
-0.0000 +1.0000 +0.0000 +0.0000 +0.0000
-3.2000 -7.2000 -0.9000 +0.8000 +0.1000
-0.2000 -2.2000 +0.1000 -0.2000 +0.1000
+1.8000 -1.2000 +2.1000 -1.2000 +0.1000
x = Inv * b
+1.0000
+1.0000
-10.4000
-2.4000
+0.6000
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 +1.00y**2 -10.40x -2.40y +0.60 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
ixe5idtewzmj4k9pu0vko3k5dulgsop
Mathc complexes/077
0
82702
746451
2025-07-10T20:58:28Z
Xhungab
23827
news
746451
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/06m| '''Application''']]
:
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00b.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R3*(C2*C2)] ={
1,0, -2,0,
2,0, -3,0,
3,0, 6,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 */
+1,+0, +0,+0, +0,+0, +0,+0, +0,+0,
+0,+0, +1,+0, +0,+0, +0,+0, +0,+0,
+1,+0, +1,+0, +1,+0, -1,+0, +1,+0,
+4,+0, +81,+0, +2,+0, -9,+0, +1,+0,
+9,+0, +64,+0, +3,+0, -8,+0, +1,+0,};
double tb[RA*(Cb*C2)]={
+1,0,
+1,0,
+0,0,
+0,0,
+0,0, };
double **XY = ca_A_mZ(xy,i_mZ(R3,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, of a circle \n\n");
printf(" ax**2 + ay**2 + bx + cy + d = 0 \n\n");
printf(" that passes through these three XY. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
stop();
clrscrn();
printf(" Using the given XY, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv :");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" Inv :");
p_mRZ(Inv,S10,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, of a circle
ax**2 + ay**2 + bx + cy + d = 0
that passes through these three XY.
x y
+1 -2
+2 -3
+3 +6
Press return to continue.
Using the given XY, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+0.00 +1.00 +0.00 +0.00 +0.00
+1.00 +1.00 +1.00 -1.00 +1.00
+4.00 +81.00 +2.00 -9.00 +1.00
+9.00 +64.00 +3.00 -8.00 +1.00
b :
+1.00
+1.00
+0.00
+0.00
+0.00
Inv :
+1.0000e+00 -0.0000e+00 +0.0000e+00 +0.0000e+00 +0.0000e+00
+0.0000e+00 +1.0000e+00 -0.0000e+00 +0.0000e+00 -0.0000e+00
-4.7778e+00 +6.2222e+00 -1.1111e-01 -7.7778e-01 +8.8889e-01
-2.2222e-01 +1.0778e+01 +1.1111e-01 -2.2222e-01 +1.1111e-01
+3.5556e+00 +3.5556e+00 +1.2222e+00 +5.5556e-01 -7.7778e-01
Press return to continue.
Inv :
+1.0000 -0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +1.0000 -0.0000 +0.0000 -0.0000
-4.7778 +6.2222 -0.1111 -0.7778 +0.8889
-0.2222 +10.7778 +0.1111 -0.2222 +0.1111
+3.5556 +3.5556 +1.2222 +0.5556 -0.7778
x = Inv * b
+1.0000
+1.0000
+1.4444
+10.5556
+7.1111
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 +1.00y**2 +1.44x +10.56y +7.11 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
r3f1zvj8vljm2gqialux0mb8v184n78
Mathc complexes/078
0
82703
746452
2025-07-10T21:00:29Z
Xhungab
23827
news
746452
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/06m| '''Application''']]
:
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00c.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R3*(C2*C2)] ={
1,0, 10,0,
2,0, 1,0,
3,0, -10,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 */
+1,+0, +0,+0, +0,+0, +0,+0, +0,+0,
+0,+0, +1,+0, +0,+0, +0,+0, +0,+0,
+1,+0, +100,+0, +1,+0, +10,+0, +1,+0,
+4,+0, +1,+0, +2,+0, +1,+0, +1,+0,
+9,+0, +100,+0, +3,+0, -10,+0, +1,+0, };
double tb[RA*(Cb*C2)]={
+1,0,
+1,0,
+0,0,
+0,0,
+0,0, };
double **XY = ca_A_mZ(xy,i_mZ(R3,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, of a circle \n\n");
printf(" ax**2 + ay**2 + bx + cy + d = 0 \n\n");
printf(" that passes through these three XY. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
stop();
clrscrn();
printf(" Using the given XY, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv :");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" Inv :");
p_mRZ(Inv,S10,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, of a circle
ax**2 + ay**2 + bx + cy + d = 0
that passes through these three XY.
x y
+1 +10
+2 +1
+3 -10
Press return to continue.
Using the given XY, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+0.00 +1.00 +0.00 +0.00 +0.00
+1.00 +100.00 +1.00 +10.00 +1.00
+4.00 +1.00 +2.00 +1.00 +1.00
+9.00 +100.00 +3.00 -10.00 +1.00
b :
+1.00
+1.00
+0.00
+0.00
+0.00
Inv :
+1.0000e+00 +0.0000e+00 +0.0000e+00 +0.0000e+00 +0.0000e+00
+0.0000e+00 +1.0000e+00 -0.0000e+00 +0.0000e+00 -0.0000e+00
+6.0000e+00 +9.9000e+02 -5.5000e+00 +1.0000e+01 -4.5000e+00
+1.0000e+00 +9.9000e+01 -5.0000e-01 +1.0000e+00 -5.0000e-01
-1.7000e+01 -2.0800e+03 +1.1500e+01 -2.0000e+01 +9.5000e+00
Press return to continue.
Inv :
+1.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +1.0000 -0.0000 +0.0000 -0.0000
+6.0000 +990.0000 -5.5000 +10.0000 -4.5000
+1.0000 +99.0000 -0.5000 +1.0000 -0.5000
-17.0000 -2080.0000 +11.5000 -20.0000 +9.5000
x = Inv * b
+1.0000
+1.0000
+996.0000
+100.0000
-2097.0000
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 +1.00y**2 +996.00x +100.00y -2097.00 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
73hbv6us4jxaomoi0utnbbtduvsouwg
Discussion Wikijunior:Petits nombres/8
103
82704
746453
2025-07-10T21:01:20Z
2600:1700:BC00:DB70:CC4E:6353:39C:A246
/* pattes du crabes */ nouvelle section
746453
wikitext
text/x-wiki
== pattes du crabes ==
tous les vrais crabes ont dix pattes. Une crabe de cocotier à hiut pattes: Le crabe de cocotier n'est pas un vrai crabe. [[Spécial:Contributions/2600:1700:BC00:DB70:CC4E:6353:39C:A246|2600:1700:BC00:DB70:CC4E:6353:39C:A246]] 10 juillet 2025 à 23:01 (CEST)
25p8itwqtnuq3xsiqrcxrj0zyw77jxn
Mathc complexes/079
0
82705
746454
2025-07-10T21:02:27Z
Xhungab
23827
news
746454
wikitext
text/x-wiki
__NOTOC__
[[Catégorie:Mathc complexes (livre)]]
:
[[Mathc complexes/06m| '''Application''']]
:
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00d.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R3*(C2*C2)] ={
10,0, 10,0,
-5,0, 1,0,
7,0, -10,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 */
+1,+0, +0,+0, +0,+0, +0,+0, +0,+0,
+0,+0, +1,+0, +0,+0, +0,+0, +0,+0,
+100,+0, +100,+0, +10,+0, +10,+0, +1,+0,
+25,+0, +1,+0, -5,+0, +1,+0, +1,+0,
+49,+0, +100,+0, +7,+0, -10,+0, +1,+0, };
double tb[RA*(Cb*C2)]={
+1,0,
+1,0,
+0,0,
+0,0,
+0,0, };
double **XY = ca_A_mZ(xy,i_mZ(R3,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, of a circle \n\n");
printf(" ax**2 + ay**2 + bx + cy + d = 0 \n\n");
printf(" that passes through these three XY. \n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
stop();
clrscrn();
printf(" Using the given XY, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv :");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" Inv :");
p_mRZ(Inv,S10,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(A);
f_mZ(b);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, of a circle
ax**2 + ay**2 + bx + cy + d = 0
that passes through these three XY.
x y
+10 +10
-5 +1
+7 -10
Press return to continue.
Using the given XY, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+0.00 +1.00 +0.00 +0.00 +0.00
+100.00 +100.00 +10.00 +10.00 +1.00
+25.00 +1.00 -5.00 +1.00 +1.00
+49.00 +100.00 +7.00 -10.00 +1.00
b :
+1.00
+1.00
+0.00
+0.00
+0.00
Inv :
+1.0000e+00 +0.0000e+00 -0.0000e+00 +0.0000e+00 -0.0000e+00
+0.0000e+00 +1.0000e+00 +0.0000e+00 -0.0000e+00 +0.0000e+00
-3.8132e+00 -7.2527e+00 +4.0293e-02 -7.3260e-02 +3.2967e-02
-1.9780e+00 +1.0879e+00 +4.3956e-02 +1.0989e-02 -5.4945e-02
-4.2088e+01 -3.8352e+01 +1.5751e-01 +6.2271e-01 +2.1978e-01
Press return to continue.
Inv :
+1.0000 +0.0000 -0.0000 +0.0000 -0.0000
+0.0000 +1.0000 +0.0000 -0.0000 +0.0000
-3.8132 -7.2527 +0.0403 -0.0733 +0.0330
-1.9780 +1.0879 +0.0440 +0.0110 -0.0549
-42.0879 -38.3516 +0.1575 +0.6227 +0.2198
x = Inv * b
+1.0000
+1.0000
-11.0659
-0.8901
-80.4396
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 +1.00y**2 -11.07x -0.89y -80.44 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
r0gzq41x1duw3rd8ur6kg67u37604fv
Mathc complexes/07a
0
82706
746458
2025-07-10T21:29:21Z
Xhungab
23827
news
746458
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/06a| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00a.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
1,0, 0,0,
2,0, 3,0,
3,0, 4,0,
4,0, 0,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 = +0 */
+1,0, +0,0, +0,0, +0,0, +0,0,
+1,0, +0,0, +1,0, +0,0, +1,0,
+4,0, +9,0, +2,0, +3,0, +1,0,
+9,0, +16,0, +3,0, +4,0, +1,0,
+16,0, +0,0, +4,0, +0,0, +1,0,};
double tb[RA*(Cb*C2)]={
+1,0,
+0,0,
+0,0,
+0,0,
+0,0,};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
printf(" that passes through these four points.\n\n");
printf(" x y");
p_mRZ(XY,S10,P0,C6);
stop();
clrscrn();
printf(" Using the given points, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv ");
// inv_mZ(A,Inv);
invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, e, of the curve
ax**2 + by**2 + cx + dy + e = 0
that passes through these four points.
x y
+1 +0
+2 +3
+3 +4
+4 +0
Press return to continue.
Using the given points, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+1.00 +0.00 +1.00 +0.00 +1.00
+4.00 +9.00 +2.00 +3.00 +1.00
+9.00 +16.00 +3.00 +4.00 +1.00
+16.00 +0.00 +4.00 +0.00 +1.00
b :
+1.00
+0.00
+0.00
+0.00
+0.00
Inv
+1.0000e+00 +0.0000e+00 +0.0000e+00 +0.0000e+00 +3.4694e-18
-1.6667e-01 +1.3889e-01 -3.3333e-01 +2.5000e-01 -5.5556e-02
-5.0000e+00 -3.3333e-01 +0.0000e+00 +0.0000e+00 +3.3333e-01
+1.1667e+00 -6.3889e-01 +1.3333e+00 -7.5000e-01 +5.5556e-02
+4.0000e+00 +1.3333e+00 +0.0000e+00 +0.0000e+00 -3.3333e-01
Press return to continue.
x = Inv * b
+1.0000
-0.1667
-5.0000
+1.1667
+4.0000
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 -0.17y**2 -5.00x +1.17y +4.00 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
knmvpa0zxmqomhjmry9fwyudjxlal25
Mathc complexes/07b
0
82707
746459
2025-07-10T21:31:18Z
Xhungab
23827
news
746459
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/06a| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00b.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
1,0, 1,0,
2,0, 4,0,
3,0, 9,0,
4,0, 16,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 = +0 */
+1,0, +0,0, +0,0, +0,0, +0,0,
+1,0, +1,0, +1,0, +1,0, +1,0,
+4,0, +16,0, +2,0, +4,0, +1,0,
+9,0, +81,0, +3,0, +9,0, +1,0,
+16,0, +256,0, +4,0, +16,0, +1,0,};
double tb[RA*(Cb*C2)]={
+1,0,
+0,0,
+0,0,
+0,0,
+0,0,};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
printf(" that passes through these four points.\n\n");
printf(" x y");
p_mRZ(XY,S10,P0,C6);
stop();
clrscrn();
printf(" Using the given points, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv ");
// inv_mZ(A,Inv);
invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy = 0\n\n"
,Invb[R1][C1], Invb[R4][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, e, of the curve
ax**2 + by**2 + cx + dy + e = 0
that passes through these four points.
x y
+1 +1
+2 +4
+3 +9
+4 +16
Press return to continue.
Using the given points, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+1.00 +1.00 +1.00 +1.00 +1.00
+4.00 +16.00 +2.00 +4.00 +1.00
+9.00 +81.00 +3.00 +9.00 +1.00
+16.00 +256.00 +4.00 +16.00 +1.00
b :
+1.00
+0.00
+0.00
+0.00
+0.00
Inv
+1.0000e+00 +1.1102e-16 +4.4409e-16 +2.2204e-16 +5.5511e-17
+0.0000e+00 -1.6667e-02 +5.0000e-02 -5.0000e-02 +1.6667e-02
-5.4401e-15 -3.5000e+00 +7.0000e+00 -4.5000e+00 +1.0000e+00
-1.0000e+00 +9.1667e-01 -2.2500e+00 +1.7500e+00 -4.1667e-01
+3.4639e-15 +3.6000e+00 -4.8000e+00 +2.8000e+00 -6.0000e-01
Press return to continue.
x = Inv * b
+1.0000
+0.0000
-0.0000
-1.0000
+0.0000
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 -1.00y = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
g5kskzwg1h18t89d3xopnr6xun3vs70
Mathc complexes/07c
0
82708
746460
2025-07-10T21:33:28Z
Xhungab
23827
news
746460
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/06a| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00c.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
1,0, -8,0,
2,0, 2,0,
3,0, 1,0,
4,0, 2,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 = +0 */
+1,0, +0,0, +0,0, +0,0, +0,0,
+1,0, +64,0, +1,0, -8,0, +1,0,
+4,0, +4,0, +2,0, +2,0, +1,0,
+9,0, +1,0, +3,0, +1,0, +1,0,
+16,0, +4,0, +4,0, +2,0, +1,0,};
double tb[RA*(Cb*C2)]={
+1,0,
+0,0,
+0,0,
+0,0,
+0,0,};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
printf(" that passes through these four points.\n\n");
printf(" x y");
p_mRZ(XY,S10,P0,C6);
stop();
clrscrn();
printf(" Using the given points, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv ");
// inv_mZ(A,Inv);
invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, e, of the curve
ax**2 + by**2 + cx + dy + e = 0
that passes through these four points.
x y
+1 -8
+2 +2
+3 +1
+4 +2
Press return to continue.
Using the given points, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+1.00 +64.00 +1.00 -8.00 +1.00
+4.00 +4.00 +2.00 +2.00 +1.00
+9.00 +1.00 +3.00 +1.00 +1.00
+16.00 +4.00 +4.00 +2.00 +1.00
b :
+1.00
+0.00
+0.00
+0.00
+0.00
Inv
+1.0000e+00 +0.0000e+00 +2.0817e-17 +1.3878e-17 -1.3878e-17
-1.4444e-01 +1.1111e-02 +3.8889e-02 -1.1111e-01 +6.1111e-02
-6.0000e+00 -5.2042e-18 -5.0000e-01 -2.2204e-16 +5.0000e-01
-5.6667e-01 -3.3333e-02 +3.8333e-01 -6.6667e-01 +3.1667e-01
+9.7111e+00 +2.2222e-02 +1.0778e+00 +1.7778e+00 -1.8778e+00
Press return to continue.
x = Inv * b
+1.0000
-0.1444
-6.0000
-0.5667
+9.7111
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 -0.14y**2 -6.00x -0.57y +9.71 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
rt1qgguyp9j2swa5c904wlcqilhfgw2
Mathc complexes/07d
0
82709
746461
2025-07-10T21:36:09Z
Xhungab
23827
news
746461
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/06a| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00d.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
1,0, 4,0,
2,0, 5,0,
3,0, -7,0,
4,0, 5,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 = +0 */
+1,0, +0,0, +0,0, +0,0, +0,0,
+1,0, +64,0, +1,0, -8,0, +1,0,
+4,0, +4,0, +2,0, +2,0, +1,0,
+9,0, +1,0, +3,0, +1,0, +1,0,
+16,0, +4,0, +4,0, +2,0, +1,0,};
double tb[RA*(Cb*C2)]={
+1,0,
+0,0,
+0,0,
+0,0,
+0,0,};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
printf(" that passes through these four points.\n\n");
printf(" x y");
p_mRZ(XY,S10,P0,C6);
stop();
clrscrn();
printf(" Using the given points, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv ");
// inv_mZ(A,Inv);
invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, e, of the curve
ax**2 + by**2 + cx + dy + e = 0
that passes through these four points.
x y
+1 +4
+2 +5
+3 -7
+4 +5
Press return to continue.
Using the given points, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+1.00 +64.00 +1.00 -8.00 +1.00
+4.00 +4.00 +2.00 +2.00 +1.00
+9.00 +1.00 +3.00 +1.00 +1.00
+16.00 +4.00 +4.00 +2.00 +1.00
b :
+1.00
+0.00
+0.00
+0.00
+0.00
Inv
+1.0000e+00 +0.0000e+00 +2.0817e-17 +1.3878e-17 -1.3878e-17
-1.4444e-01 +1.1111e-02 +3.8889e-02 -1.1111e-01 +6.1111e-02
-6.0000e+00 -5.2042e-18 -5.0000e-01 -2.2204e-16 +5.0000e-01
-5.6667e-01 -3.3333e-02 +3.8333e-01 -6.6667e-01 +3.1667e-01
+9.7111e+00 +2.2222e-02 +1.0778e+00 +1.7778e+00 -1.8778e+00
Press return to continue.
x = Inv * b
+1.0000
-0.1444
-6.0000
-0.5667
+9.7111
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 -0.14y**2 -6.00x -0.57y +9.71 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
7cs5j5rt0wxxeeu7pka0diayssm9lj1
Mathc complexes/07e
0
82710
746462
2025-07-10T21:39:21Z
Xhungab
23827
news
746462
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/06a| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00e.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00e.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
/* ------------------------------------ */
int main(void)
{
double xy[R4*(C2*C2)] ={
1,0, 2,0,
2,0, -8,0,
3,0, -8,0,
4,0, -3,0 };
double ta[RA*(CA*C2)] ={
/* x**2 y**2 x y x**0 = +0 */
+1,0, +0,0, +0,0, +0,0, +0,0,
+1,0, +4,0, +1,0, +2,0, +1,0,
+4,0, +64,0, +2,0, -8,0, +1,0,
+9,0, +64,0, +3,0, -8,0, +1,0,
+16,0, +9,0, +4,0, -3,0, +1,0,};
double tb[RA*(Cb*C2)]={
+1,0,
+0,0,
+0,0,
+0,0,
+0,0,};
double **XY = ca_A_mZ(xy,i_mZ(R4,C2));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf("\n");
printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
printf(" ax**2 + by**2 + cx + dy + e = 0 \n\n");
printf(" that passes through these four points.\n\n");
printf(" x y");
p_mRZ(XY,S10,P0,C6);
stop();
clrscrn();
printf(" Using the given points, we obtain this matrix.\n");
printf(" (a = 1. This is my choice)\n\n");
printf(" A :");
p_mRZ(A,S10,P2,C7);
printf(" b :");
p_mRZ(b,S10,P2,C7);
printf(" Inv ");
// inv_mZ(A,Inv);
invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
stop();
clrscrn();
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
" %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Find the coefficients a, b, c, d, e, of the curve
ax**2 + by**2 + cx + dy + e = 0
that passes through these four points.
x y
+1 +2
+2 -8
+3 -8
+4 -3
Press return to continue.
Using the given points, we obtain this matrix.
(a = 1. This is my choice)
A :
+1.00 +0.00 +0.00 +0.00 +0.00
+1.00 +4.00 +1.00 +2.00 +1.00
+4.00 +64.00 +2.00 -8.00 +1.00
+9.00 +64.00 +3.00 -8.00 +1.00
+16.00 +9.00 +4.00 -3.00 +1.00
b :
+1.00
+0.00
+0.00
+0.00
+0.00
Inv
+1.0000e+00 +1.0408e-17 -1.3878e-17 -1.3878e-17 -3.4694e-18
+4.0000e-02 +2.0000e-02 -8.0000e-02 +1.0000e-01 -4.0000e-02
-5.0000e+00 +0.0000e+00 -1.0000e+00 +1.0000e+00 +3.4694e-17
+4.0000e-02 +2.2000e-01 -6.8000e-01 +7.0000e-01 -2.4000e-01
+3.7600e+00 +4.8000e-01 +2.6800e+00 -2.8000e+00 +6.4000e-01
Press return to continue.
x = Inv * b
+1.0000
+0.0400
-5.0000
+0.0400
+3.7600
The coefficients a, b, c, d, e, of the curve are :
+1.00x**2 +0.04y**2 -5.00x +0.04y +3.76 = 0
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
41rn67aouwin4dg2dkzohljvx9lve0m
Mathc complexes/07f
0
82711
746471
2025-07-11T09:59:43Z
Xhungab
23827
news
746471
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00a.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
+1,0, +1,0, +1,0,
+4,0, +2,0, +1,0,
+9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
+6,0,
+3,0,
+5,0};
double xy[RA*(CXY*C2)] =
{1,0, 6,0,
2,0, 3,0,
3,0, 5,0,};
double **XY = ca_A_mZ(xy,i_mZ(RA,(CXY*C2)));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**2 x**1 x**0");
p_mRZ(A,S6,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S6,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 +6 +2 +3
+3 +5 +1 +1
+1 +4 +2 +1
A :
x**2 x**1 x**0
+1.00 +1.00 +1.00
+4.00 +2.00 +1.00
+9.00 +3.00 +1.00
b :
y
+6.00
+3.00
+5.00
Press return to continue.
Inv :
+5.0000e-01 -1.0000e+00 +5.0000e-01
-2.5000e+00 +4.0000e+00 -1.5000e+00
+3.0000e+00 -3.0000e+00 +1.0000e+00
x = Inv * b
+2.5000
-10.5000
+14.0000
The coefficients a, b, c of the curve are :
y = +2.50x**2 -10.50x +14.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
nvbn8kp1l39gp782g449xg6iltc6ah2
746476
746471
2025-07-11T10:14:27Z
Xhungab
23827
746476
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00a.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
+1,0, +1,0, +1,0,
+4,0, +2,0, +1,0,
+9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
+6,0,
+3,0,
+5,0};
double xy[RA*(CXY*C2)] =
{1,0, 6,0,
2,0, 3,0,
3,0, 5,0,};
double **XY = ca_A_mZ(xy,i_mZ(RA,CXY));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**2 x**1 x**0");
p_mRZ(A,S6,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S6,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 +6
+2 +3
+3 +5
A :
x**2 x**1 x**0
+1.00 +1.00 +1.00
+4.00 +2.00 +1.00
+9.00 +3.00 +1.00
b :
y
+6.00
+3.00
+5.00
Press return to continue.
Inv :
+5.0000e-01 -1.0000e+00 +5.0000e-01
-2.5000e+00 +4.0000e+00 -1.5000e+00
+3.0000e+00 -3.0000e+00 +1.0000e+00
x = Inv * b
+2.5000
-10.5000
+14.0000
The coefficients a, b, c of the curve are :
y = +2.50x**2 -10.50x +14.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
8efvejpbh166ckg4hm9p5wxfte0uv2e
Mathc complexes/07g
0
82712
746472
2025-07-11T10:01:28Z
Xhungab
23827
news
746472
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00b.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
+1,0, +1,0, +1,0,
+4,0, +2,0, +1,0,
+9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
-9,0,
+8,0,
-8,0,};
double xy[RA*(CXY*C2)] ={1,0, -9,0,
2,0, 8,0,
3,0, -8,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,(CXY*C2)));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**2 x**1 x**0");
p_mRZ(A,S6,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S6,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 -9 +2 +8
+3 -8 +1 +1
+1 +4 +2 +1
A :
x**2 x**1 x**0
+1.00 +1.00 +1.00
+4.00 +2.00 +1.00
+9.00 +3.00 +1.00
b :
y
-9.00
+8.00
-8.00
Press return to continue.
Inv :
+5.0000e-01 -1.0000e+00 +5.0000e-01
-2.5000e+00 +4.0000e+00 -1.5000e+00
+3.0000e+00 -3.0000e+00 +1.0000e+00
x = Inv * b
-16.5000
+66.5000
-59.0000
The coefficients a, b, c of the curve are :
y = -16.50x**2 +66.50x -59.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
rl20v7pt1o1jt665bc0l3ksb6m4g6zr
746477
746472
2025-07-11T10:18:14Z
Xhungab
23827
746477
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00b.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R3
#define CA C3
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
+1,0, +1,0, +1,0,
+4,0, +2,0, +1,0,
+9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
-9,0,
+8,0,
-8,0,};
double xy[RA*(CXY*C2)] ={1,0, -9,0,
2,0, 8,0,
3,0, -8,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,CXY));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**2 x**1 x**0");
p_mRZ(A,S6,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S6,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**2 %+.2fx %+.2f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 -9
+2 +8
+3 -8
A :
x**2 x**1 x**0
+1.00 +1.00 +1.00
+4.00 +2.00 +1.00
+9.00 +3.00 +1.00
b :
y
-9.00
+8.00
-8.00
Press return to continue.
Inv :
+5.0000e-01 -1.0000e+00 +5.0000e-01
-2.5000e+00 +4.0000e+00 -1.5000e+00
+3.0000e+00 -3.0000e+00 +1.0000e+00
x = Inv * b
-16.5000
+66.5000
-59.0000
The coefficients a, b, c of the curve are :
y = -16.50x**2 +66.50x -59.00
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
5in4k5tv6gs0eo5f7bqyxojyc2bm176
Mathc complexes/07h
0
82713
746473
2025-07-11T10:03:07Z
Xhungab
23827
news
746473
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00c.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
-125,0, +25,0, -5,0, +1,0,
-8,0, +4,0, -2,0, +1,0,
+8,0, +4,0, +2,0, +1,0,
+27,0, +9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
-3,0,
+0,0,
+3,0,
-2,0,};
double xy[RA*(CXY*C2)] ={ -5,0, -3,0,
-2,0, 0,0,
2,0, 3,0,
3,0, -2,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,(CXY*C2)));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P2,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**3 %+.2fx**2 %+.2fx %+.2f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],Invb[R4][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
-5 -3 -2 +0
+2 +3 +3 -2
-125 +25 -5 +1
-8 +4 -2 +1
A :
x**3 x**2 x**1 x**0
-125.00 +25.00 -5.00 +1.00
-8.00 +4.00 -2.00 +1.00
+8.00 +4.00 +2.00 +1.00
+27.00 +9.00 +3.00 +1.00
b :
y
-3.00
+0.00
+3.00
-2.00
Press return to continue.
Inv :
-5.9524e-03 +1.6667e-02 -3.5714e-02 +2.5000e-02
+1.7857e-02 +0.0000e+00 -1.4286e-01 +1.2500e-01
+2.3810e-02 -3.1667e-01 +3.9286e-01 -1.0000e-01
-7.1429e-02 +5.0000e-01 +1.0714e+00 -5.0000e-01
x = Inv * b
-0.14
-0.73
+1.31
+4.43
The coefficients a, b, c of the curve are :
y = -0.14x**3 -0.73x**2 +1.31x +4.43
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
i0fn18ul8qk07vtqb5enhf1msfydh72
746478
746473
2025-07-11T10:20:45Z
Xhungab
23827
746478
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00c.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
-125,0, +25,0, -5,0, +1,0,
-8,0, +4,0, -2,0, +1,0,
+8,0, +4,0, +2,0, +1,0,
+27,0, +9,0, +3,0, +1,0,};
double tb[RA*(Cb*C2)]={
-3,0,
+0,0,
+3,0,
-2,0,};
double xy[RA*(CXY*C2)] ={
-5,0, -3,0,
-2,0, 0,0,
2,0, 3,0,
3,0, -2,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,CXY));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P2,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**3 %+.2fx**2 %+.2fx %+.2f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],Invb[R4][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
-5 -3
-2 +0
+2 +3
+3 -2
A :
x**3 x**2 x**1 x**0
-125.00 +25.00 -5.00 +1.00
-8.00 +4.00 -2.00 +1.00
+8.00 +4.00 +2.00 +1.00
+27.00 +9.00 +3.00 +1.00
b :
y
-3.00
+0.00
+3.00
-2.00
Press return to continue.
Inv :
-5.9524e-03 +1.6667e-02 -3.5714e-02 +2.5000e-02
+1.7857e-02 +0.0000e+00 -1.4286e-01 +1.2500e-01
+2.3810e-02 -3.1667e-01 +3.9286e-01 -1.0000e-01
-7.1429e-02 +5.0000e-01 +1.0714e+00 -5.0000e-01
x = Inv * b
-0.14
-0.73
+1.31
+4.43
The coefficients a, b, c of the curve are :
y = -0.14x**3 -0.73x**2 +1.31x +4.43
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
l6pwpvfqpo3vu4193fkal16eqj98gy9
Mathc complexes/07i
0
82714
746474
2025-07-11T10:05:28Z
Xhungab
23827
news
746474
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00d.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
-125,0, +25,0, -5,0, +1,0,
-8,0, +4,0, -2,0, +1,0,
+8,0, +4,0, +2,0, +1,0,
+125,0, +25,0, +5,0, +1,0,};
double tb[RA*(Cb*C2)]={
-8,0,
+8,0,
-8,0,
+8,0,};
double xy[RA*(CXY*C2)] ={ -5,0, -8,0,
-2,0, 8,0,
2,0, -8,0,
5,0, 8,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,(CXY*C2)));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P2,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**3 %+.2fx \n\n"
,Invb[R1][C1],Invb[R3][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
-5 -8 -2 +8
+2 -8 +5 +8
-125 +25 -5 +1
-8 +4 -2 +1
A :
x**3 x**2 x**1 x**0
-125.00 +25.00 -5.00 +1.00
-8.00 +4.00 -2.00 +1.00
+8.00 +4.00 +2.00 +1.00
+125.00 +25.00 +5.00 +1.00
b :
y
-8.00
+8.00
-8.00
+8.00
Press return to continue.
Inv :
-4.7619e-03 +1.1905e-02 -1.1905e-02 +4.7619e-03
+2.3810e-02 -2.3810e-02 -2.3810e-02 +2.3810e-02
+1.9048e-02 -2.9762e-01 +2.9762e-01 -1.9048e-02
-9.5238e-02 +5.9524e-01 +5.9524e-01 -9.5238e-02
x = Inv * b
+0.27
+0.00
-5.07
+0.00
The coefficients a, b, c of the curve are :
y = +0.27x**3 -5.07x
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
0t1qjo2z00uri02kvyztpw911dtnh1j
746479
746474
2025-07-11T10:23:27Z
Xhungab
23827
746479
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00d.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R4
#define CA C4
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)] ={
-125,0, +25,0, -5,0, +1,0,
-8,0, +4,0, -2,0, +1,0,
+8,0, +4,0, +2,0, +1,0,
+125,0, +25,0, +5,0, +1,0,};
double tb[RA*(Cb*C2)]={
-8,0,
+8,0,
-8,0,
+8,0,};
double xy[RA*(CXY*C2)] ={
-5,0, -8,0,
-2,0, 8,0,
2,0, -8,0,
5,0, 8,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,CXY));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y \n");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P2,C10);
printf("\n The coefficients a, b, c of the curve are : \n\n"
" y = %+.2fx**3 %+.2fx \n\n"
,Invb[R1][C1],Invb[R3][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
-5 -8
-2 +8
+2 -8
+5 +8
A :
x**3 x**2 x**1 x**0
-125.00 +25.00 -5.00 +1.00
-8.00 +4.00 -2.00 +1.00
+8.00 +4.00 +2.00 +1.00
+125.00 +25.00 +5.00 +1.00
b :
y
-8.00
+8.00
-8.00
+8.00
Press return to continue.
Inv :
-4.7619e-03 +1.1905e-02 -1.1905e-02 +4.7619e-03
+2.3810e-02 -2.3810e-02 -2.3810e-02 +2.3810e-02
+1.9048e-02 -2.9762e-01 +2.9762e-01 -1.9048e-02
-9.5238e-02 +5.9524e-01 +5.9524e-01 -9.5238e-02
x = Inv * b
+0.27
+0.00
-5.07
+0.00
The coefficients a, b, c of the curve are :
y = +0.27x**3 -5.07x
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
f3dao395rqoghx3dxko37elauky2eza
Mathc complexes/07j
0
82715
746475
2025-07-11T10:08:30Z
Xhungab
23827
news
746475
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00e.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00e.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)]={
/* x**4 x**3 x**2 x**1 x**0 */
1,0, 1.,0, 1.,0, 1.,0, 1,0,
16.,0, 8.,0, 4.,0, 2.,0, 1,0,
81.,0, 27.,0, 9.,0, 3.,0, 1,0,
256.,0, 64.,0, 16.,0, 4.,0, 1,0,
625.,0, 125,0, 25.,0, 5.,0, 1,0,
};
double tb[RA*(Cb*C2)]={
/* y */
-5.,0,
8.,0,
-7.,0,
1.,0,
-4.,0,
};
double xy[RA*(CXY*C2)] ={
1,0, -5,0,
2,0, 8,0,
3,0, -7,0,
4,0, 1,0,
5,0, -4,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,(CXY*C2)));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**4 x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The Quartic equation Curve to Data : \n\n"
" s = %+.3ft**4 %+.3ft**3 %+.3f*t**2 %+.3ft %+.3f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 -5 +2 +8
+3 -7 +4 +1
+5 -4 +1 +1
+1 +1 +1 +16
+8 +4 +2 +1
A :
x**4 x**3 x**2 x**1 x**0
+1.00 +1.00 +1.00 +1.00 +1.00
+16.00 +8.00 +4.00 +2.00 +1.00
+81.00 +27.00 +9.00 +3.00 +1.00
+256.00 +64.00 +16.00 +4.00 +1.00
+625.00 +125.00 +25.00 +5.00 +1.00
b :
y
-5.00
+8.00
-7.00
+1.00
-4.00
Press return to continue.
Inv :
+4.1667e-02 -1.6667e-01 +2.5000e-01 -1.6667e-01 +4.1667e-02
-5.8333e-01 +2.1667e+00 -3.0000e+00 +1.8333e+00 -4.1667e-01
+2.9583e+00 -9.8333e+00 +1.2250e+01 -6.8333e+00 +1.4583e+00
-6.4167e+00 +1.7833e+01 -1.9500e+01 +1.0167e+01 -2.0833e+00
+5.0000e+00 -1.0000e+01 +1.0000e+01 -5.0000e+00 +1.0000e+00
x = Inv * b
-3.6250
+44.7500
-191.8750
+329.7500
-184.0000
The Quartic equation Curve to Data :
s = -3.625t**4 +44.750t**3 -191.875*t**2 +329.750t -184.000
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
75ddra78qdj9en985vqg82waeol0zmg
746480
746475
2025-07-11T10:25:29Z
Xhungab
23827
746480
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00e.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00e.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)]={
/* x**4 x**3 x**2 x**1 x**0 */
1,0, 1.,0, 1.,0, 1.,0, 1,0,
16.,0, 8.,0, 4.,0, 2.,0, 1,0,
81.,0, 27.,0, 9.,0, 3.,0, 1,0,
256.,0, 64.,0, 16.,0, 4.,0, 1,0,
625.,0, 125,0, 25.,0, 5.,0, 1,0,
};
double tb[RA*(Cb*C2)]={
/* y */
-5.,0,
8.,0,
-7.,0,
1.,0,
-4.,0,
};
double xy[RA*(CXY*C2)] ={
1,0, -5,0,
2,0, 8,0,
3,0, -7,0,
4,0, 1,0,
5,0, -4,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,CXY));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**4 x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The Quartic equation Curve to Data : \n\n"
" s = %+.3ft**4 %+.3ft**3 %+.3f*t**2 %+.3ft %+.3f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 -5
+2 +8
+3 -7
+4 +1
+5 -4
A :
x**4 x**3 x**2 x**1 x**0
+1.00 +1.00 +1.00 +1.00 +1.00
+16.00 +8.00 +4.00 +2.00 +1.00
+81.00 +27.00 +9.00 +3.00 +1.00
+256.00 +64.00 +16.00 +4.00 +1.00
+625.00 +125.00 +25.00 +5.00 +1.00
b :
y
-5.00
+8.00
-7.00
+1.00
-4.00
Press return to continue.
Inv :
+4.1667e-02 -1.6667e-01 +2.5000e-01 -1.6667e-01 +4.1667e-02
-5.8333e-01 +2.1667e+00 -3.0000e+00 +1.8333e+00 -4.1667e-01
+2.9583e+00 -9.8333e+00 +1.2250e+01 -6.8333e+00 +1.4583e+00
-6.4167e+00 +1.7833e+01 -1.9500e+01 +1.0167e+01 -2.0833e+00
+5.0000e+00 -1.0000e+01 +1.0000e+01 -5.0000e+00 +1.0000e+00
x = Inv * b
-3.6250
+44.7500
-191.8750
+329.7500
-184.0000
The Quartic equation Curve to Data :
s = -3.625t**4 +44.750t**3 -191.875*t**2 +329.750t -184.000
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
bbl9jm10hivhn63tsy1vlhw1p90ty02
Mathc complexes/07k
0
82716
746481
2025-07-11T10:27:30Z
Xhungab
23827
news
746481
wikitext
text/x-wiki
[[Catégorie:Mathc complexes (livre)]]
[[Mathc complexes/069| '''Application''']]
Installer et compiler ces fichiers dans votre répertoire de travail.
{{Fichier|c00f.c|largeur=70%|info=|icon=Crystal128-source-c.svg}}
<syntaxhighlight lang="c">
/* ------------------------------------ */
/* Save as : c00f.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R5
#define CA C5
#define Cb C1
#define CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*(CA*C2)]={
/* x**4 x**3 x**2 x**1 x**0 */
+1,0, +1,0, +1,0, +1,0, +1,0,
+16,0, +8,0, +4,0, +2,0, +1,0,
+81,0, +27,0, +9,0, +3,0, +1,0,
+256,0, +64,0, +16,0, +4,0, +1,0,
+625,0, +125,0, +25,0, +5,0, +1,0,
};
double tb[RA*(Cb*C2)]={
/* y */
-2,0,
-2,0,
3,0,
-9,0,
4,0,
};
double xy[RA*(CXY*C2)] ={
1,0, -2,0,
2,0, -2,0,
3,0, 3,0,
4,0, -9,0,
5,0, 4,0, };
double **XY = ca_A_mZ(xy,i_mZ(RA,CXY));
double **A = ca_A_mZ(ta,i_mZ(RA,CA));
double **b = ca_A_mZ(tb,i_mZ(RA,C1));
double **Inv = i_mZ(CA,RA);
double **Invb = i_mZ(CA,C1);
clrscrn();
printf(" Fitting a linear Curve to Data :\n\n");
printf(" x y");
p_mRZ(XY,S5,P0,C6);
printf(" A :\n x**4 x**3 x**2 x**1 x**0");
p_mRZ(A,S7,P2,C7);
printf(" b :\n y ");
p_mRZ(b,S7,P2,C7);
stop();
clrscrn();
printf(" Inv : ");
inv_mZ(A,Inv);
// invgj_mZ(A,Inv);
pE_mRZ(Inv,S12,P4,C10);
printf(" x = Inv * b ");
mul_mZ(Inv,b,Invb);
p_mRZ(Invb,S10,P4,C10);
printf(" The Quartic equation Curve to Data : \n\n"
" s = %+.3ft**4 %+.3ft**3 %+.3f*t**2 %+.3ft %+.3f\n\n"
,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1],
Invb[R4][C1],Invb[R5][C1]);
stop();
f_mZ(XY);
f_mZ(b);
f_mZ(A);
f_mZ(Inv);
f_mZ(Invb);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
</syntaxhighlight>
.
'''Exemple de sortie écran :'''
<syntaxhighlight lang="c">
Fitting a linear Curve to Data :
x y
+1 -2
+2 -2
+3 +3
+4 -9
+5 +4
A :
x**4 x**3 x**2 x**1 x**0
+1.00 +1.00 +1.00 +1.00 +1.00
+16.00 +8.00 +4.00 +2.00 +1.00
+81.00 +27.00 +9.00 +3.00 +1.00
+256.00 +64.00 +16.00 +4.00 +1.00
+625.00 +125.00 +25.00 +5.00 +1.00
b :
y
-2.00
-2.00
+3.00
-9.00
+4.00
Press return to continue.
Inv :
+4.1667e-02 -1.6667e-01 +2.5000e-01 -1.6667e-01 +4.1667e-02
-5.8333e-01 +2.1667e+00 -3.0000e+00 +1.8333e+00 -4.1667e-01
+2.9583e+00 -9.8333e+00 +1.2250e+01 -6.8333e+00 +1.4583e+00
-6.4167e+00 +1.7833e+01 -1.9500e+01 +1.0167e+01 -2.0833e+00
+5.0000e+00 -1.0000e+01 +1.0000e+01 -5.0000e+00 +1.0000e+00
x = Inv * b
+2.6667
-30.3333
+117.8333
-181.1667
+89.0000
The Quartic equation Curve to Data :
s = +2.667t**4 -30.333t**3 +117.833*t**2 -181.167t +89.000
Press return to continue.
</syntaxhighlight>
{{AutoCat}}
i0w6b2v99y4ngjq2m2ho7ap16f5m0ya