Produit de 2 matrices/opérateur de conversion Vecteur en Matrice

abdallah11 Messages postés 2 Date d'inscription mardi 8 octobre 2013 Statut Membre Dernière intervention 8 octobre 2013 - Modifié par abdallah11 le 8/10/2013 à 21:41
 abdallah11 - 9 oct. 2013 à 00:19
Bonsoir,
Je voudrai comprendre comment ces 2 opérateurs : Produit de 2 matrices/opérateur de conversion Vecteur en Matrice ; merci

4 réponses

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 344
Modifié par jordane45 le 8/10/2013 à 21:26
0
abdallah11 Messages postés 2 Date d'inscription mardi 8 octobre 2013 Statut Membre Dernière intervention 8 octobre 2013
8 oct. 2013 à 21:44
Merci Mr. Jordane, je viens de reformuler ma question ; je ne veux pas une correction copier-coller mais je veux comprendre comment!! seulement la méthodologie
0
BunoCS Messages postés 15472 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 25 mars 2024 103
Modifié par BunoCS le 8/10/2013 à 23:01
Hello,
je ne veux pas une correction copier-coller
Pour cela, il faudrait nous montrer ton code ;)

Autant le produit de matrices, je vois ce que c'est, autant l'opérateur de conversion vecteur/matrice, je ne vois pas. Peux-tu être un peu plus explicite?

@+
Buno, Modo CS-CCM
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
0
bon scalaire.h

#ifndef SCALAIRE
#define SCALAIRE

typedef float Scalaire;

#endif


voici la vecteur.h :

#ifndef _VECTEUR
#define _VECTEUR
#include "scalaire.h"
using namespace std;

class vecteur
{
 private:
  int taille;
  Scalaire * valeur;
  void free();
 public:
  vecteur(int =1, Scalaire =0);
  vecteur(const vecteur &);
  ~vecteur();
  vecteur & operator=(const vecteur &);
  int size()const;
  void copy(const vecteur &);
  Scalaire & operator[] (int);
  Scalaire & operator[] (int) const;
  vecteur  operator+(const vecteur &)const;
  vecteur  operator-(const vecteur &)const;
  //friend vecteur operator*(const Scalaire &,const vecteur &);
  vecteur operator*(const Scalaire &);
  Scalaire operator*(const vecteur &);
  bool operator==(const vecteur&)const;
 bool operator!=(const vecteur&)const;
  friend istream& operator>>(istream& , vecteur&);
  friend ostream& operator<<(ostream& ,const vecteur&);
   
};
 vecteur operator*(const Scalaire &,const vecteur &);
#endif


voici vecteur.cc :

#include <iostream>
using namespace std;
#include "vecteur.h"

vecteur::vecteur(int n, Scalaire x)
{
  taille=n;
  valeur=new Scalaire[taille];
  
  for (int i=0;i<taille;i++)
    valeur[i]=x;
}
vecteur::vecteur(const vecteur & v)
{
  copy(v);
  
}
vecteur::~vecteur()
{
 free();
}
 void vecteur::copy(const vecteur & v)
 {
   taille = v.size();
  valeur = new Scalaire[taille];
  
    for(int i=0;i<taille;i++)
    {
      valeur[i]=v[i];
      // (*this)[i]= v[i];
      // valeur[i]= v.valeur[i];
    }
 }
void vecteur::free()
{
    delete valeur;
}
vecteur & vecteur::operator=(const vecteur & v)
{
  if (this != &v)
  {
    if(taille== v.size())
    {
      copy(v);
    }
    else 
    {
      free();
      copy(v);
    }
  }
  return (*this);
}
int vecteur::size()const
{
  return taille;
}
Scalaire & vecteur::operator[] (int i)
{
  return valeur[i];
}

Scalaire & vecteur::operator[] (int i) const
{
  return valeur[i];
}
vecteur  vecteur::operator+(const vecteur & v)const
{
  vecteur resultat(taille);
  
  if (taille == v.size())
  {
    for(int i=0;i<taille ;i++)
      {
        resultat[i]=valeur[i]+v[i];
      }
  }
  return resultat;
}

vecteur  vecteur::operator-(const vecteur & v)const
{
  vecteur resultat(taille);
  
  if (taille == v.size())
  {
    for(int i=0;i<taille ;i++)
      {
        resultat[i]=valeur[i]-v[i];
      }
  }
  return resultat;
}
 vecteur operator*(const Scalaire & s,const vecteur & v)
 {
   vecteur resultat(v.size());
   
   for(int i=0;i< v.size();i++)
   {
     resultat[i]= s * v[i]; 
   }
   return resultat;
 }
 vecteur vecteur::operator*(const Scalaire & s)
 {
   vecteur resultat(taille);
   
   for(int i=0;i<taille;i++)
   {
     resultat[i]= valeur[i]* s; 
   }
   return resultat;
 
 }
 Scalaire vecteur::operator*(const vecteur & v)
 {
   Scalaire scl;
   
   for(int i=0;i<taille;i++)
   {
     scl += ((*this)[i]*v[i]); 
   }
   return scl;
    
 }
 bool vecteur::operator==(vecteur& v)
{
    if((taille,v.size)==0)
    return true;
    else return false;
}
bool vecteur::operator!=(vecteur& v)
{
    return !(taille,v.taille);
}
ostream &operator<<(ostream &out,const vecteur &v)
{
     return out;
}
istream &operator>>(istream &in,vecteur &v)
{
     in>>v.taille;
     return in;
}



et pour la matrice (je ne l'ai pas encore fini ) matrice.h :

#ifndef _MATRICE
#define _MATRICE
#include "vecteur.h"
class matrice{
  int nblignes; // le nb de colonne sera la taille des vecteurs
  int nbcolonnes;// inutile,car clonné par la taille des vecteurs
  vecteur *matval;
  void free();
  void copy (const matrice&);
  
public:
  //-------- constructeur classic d'une matrice----------------
  matrice(int nbl=1, int nbc=1);
  ~matrice();
  matrice & operator=(const matrice &);
  Scalaire & matrice::operator[] (int i);
  Scalaire & matrice::operator[] (int i)const;
  matrice operator+(const matrice &)const;
  matrice operator-(const matrice &)const;
  matrice operator*(const matrice &)const;
 }
 #endif


et matrice.cc
#include <iostream>
using namespace std;
#include "matrice.h"
//-------- constructeur classic d'une matrice----------------
matrice::matrice(int nbl, int nbc)
{
  nblignes=nbl;
  nbcolonnes=nbc; 
  matval= new Vecteur[nbl];
  vecteur v(nbcolonnes,10);
  for(int i=o; i<nblignes; i++)
    matval[i]=v;//affectation de Vecteur
}

matrice::matrice(const matrice & m)
{
  copy(m);
 }
void matrice::copy(const matrice & m)
 {
   nblignes = m.nblignes;
   nbcolonnes = m.nbcolonnes;
  matval = new vecteur[nbl];
  
    for(int i=0;i<nblignes;;++i;)
    {
     matval[i]=m.matval[i];
    }

 void matrice::free()
{
  delete[]matval;
}
matrice::~matrice()
{
  free();
}
matrice & matrice::operator=(const matrice & m)
{
  if (this != &m)
  {
    if (nblignes == m.nblignes)&&(nbcolonnes == m.nbcolonnes)
    {
      copy(m);
    }
    else 
    {
      free();
      copy(m);
    }
  }
  return (*this);
}
Scalaire & matrice::operator[] (int i)
{
  return matval[i];
}

Scalaire & matrice::operator[] (int i) const
{
  return matval[i];
}
matrice matrice::operator+(const matrice & m)const
{
  matrice resultat(nblignes,nbcolonnes);
  
  // on supose (nblignes == m.nblignes)&&(nbcolonnes == m.nbcolonnes) 
  
    for(int i=0;i<nblignes ;++i)
    {
            resultat[i]=matval[i]+m[i];
     }
  
 return resultat;
}
matrice matrice::operator+(const matrice & m)const
{
  matrice resultat(nblignes,nbcolonnes);
  
  // on supose (nblignes == m.nblignes)&&(nbcolonnes == m.nbcolonnes) 
  
    for(int i=0;i<nblignes ;++i)
    {
            resultat[i]=matval[i]-m[i];
     }
 return resultat;
}

0
Rejoignez-nous