Click here to Skip to main content
15,905,233 members
Home / Discussions / C#
   

C#

 
Questiondirectory path Pin
arkiboys13-Feb-11 22:12
arkiboys13-Feb-11 22:12 
AnswerRe: directory path Pin
Pete O'Hanlon13-Feb-11 22:17
mvePete O'Hanlon13-Feb-11 22:17 
GeneralRe: directory path Pin
arkiboys13-Feb-11 22:23
arkiboys13-Feb-11 22:23 
GeneralRe: directory path Pin
Pete O'Hanlon13-Feb-11 22:45
mvePete O'Hanlon13-Feb-11 22:45 
GeneralRe: directory path Pin
arkiboys13-Feb-11 23:22
arkiboys13-Feb-11 23:22 
AnswerRe: directory path Pin
Dalek Dave14-Feb-11 0:14
professionalDalek Dave14-Feb-11 0:14 
AnswerRe: directory path Pin
GenJerDan14-Feb-11 0:29
GenJerDan14-Feb-11 0:29 
GeneralRe: directory path Pin
Pete O'Hanlon14-Feb-11 0:34
mvePete O'Hanlon14-Feb-11 0:34 
AnswerRe: directory path Pin
Luc Pattyn14-Feb-11 1:01
sitebuilderLuc Pattyn14-Feb-11 1:01 
AnswerRe: directory path Pin
PIEBALDconsult14-Feb-11 2:00
mvePIEBALDconsult14-Feb-11 2:00 
QuestionCon open wait Pin
Ajay Kale New13-Feb-11 22:01
Ajay Kale New13-Feb-11 22:01 
AnswerRe: Con open wait Pin
Pete O'Hanlon13-Feb-11 22:13
mvePete O'Hanlon13-Feb-11 22:13 
AnswerRe: Con open wait Pin
Luc Pattyn14-Feb-11 0:52
sitebuilderLuc Pattyn14-Feb-11 0:52 
AnswerRe: Con open wait Pin
PIEBALDconsult14-Feb-11 1:42
mvePIEBALDconsult14-Feb-11 1:42 
QuestionUsing DotNetNuke in c# Pin
sarang_k13-Feb-11 20:08
sarang_k13-Feb-11 20:08 
AnswerRe: Using DotNetNuke in c# Pin
Richard MacCutchan13-Feb-11 22:35
mveRichard MacCutchan13-Feb-11 22:35 
Questionprogress bar while switching to new page Pin
Mugdha_Aditya13-Feb-11 18:26
Mugdha_Aditya13-Feb-11 18:26 
AnswerRe: progress bar while switching to new page Pin
Richard MacCutchan13-Feb-11 22:34
mveRichard MacCutchan13-Feb-11 22:34 
QuestionPolyLib Modifying the ToString method Pin
Ryano12113-Feb-11 5:03
Ryano12113-Feb-11 5:03 
AnswerRe: PolyLib Modifying the ToString method Pin
Eddy Vluggen13-Feb-11 6:03
professionalEddy Vluggen13-Feb-11 6:03 
GeneralRe: PolyLib Modifying the ToString method Pin
Ryano12113-Feb-11 7:43
Ryano12113-Feb-11 7:43 
AnswerRe: PolyLib Modifying the ToString method Pin
Luc Pattyn14-Feb-11 1:03
sitebuilderLuc Pattyn14-Feb-11 1:03 
GeneralRe: PolyLib Modifying the ToString method Pin
Ryano12114-Feb-11 2:22
Ryano12114-Feb-11 2:22 
Sorry about that

Basically the Polynomial class has a Complex[] field that stores the coefficients of the equation. e.g 1,7,12 for x^2 + 7x + 12. The class has an overriden ToString method that gives a representation of what the equation is. However the given implementation given below provides 12 + 7x + x^2 instead of the conventional x^2 + 7x + 12 that i am looking for.

public override string ToString()
          {
              if (this.IsZero()) return "0";
              else
              {
                  string s = "";                               
  
                  for (int i = 0; i < Degree + 1; i++)
                  {
                      if (Coefficients[i] != Complex.Zero)
                      {
                          if (Coefficients[i] == Complex.I)
                              s += "i";
                          else if (Coefficients[i] != Complex.One)
                          {
                              if (Coefficients[i].IsReal() && Coefficients[i].Re > 0)
                                  s += Coefficients[i].ToString();
                              else
                                  s += "(" + Coefficients[i].ToString() + ")";
                                  
                          }
                          else if (/*Coefficients[i] == Complex.One && */i == 0)
                              s += 1;
                                                  
                          if (i == 1)
                              s += "x";
                          else if (i > 1)
                              s += "x^" + i.ToString();                        
                      }
  
                      if (i < Degree && Coefficients[i + 1] != 0 && s.Length > 0)                    
                          s += " + ";                    
                  }
  
                  return s;
              }


Or also here

http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19446[^]

I have tried to modify the for loop to

for (int i = Degree -1; i >= 0; i--)


But that gives the + signs after the equation. I have also tried to modify other parts of the method yet it usually results in array index out of bounds exceptions.

Can anyone give me some pointers on how to modify the method to give the 'conventional' interpretation of equations?

Thanks again
GeneralMessage Removed Pin
14-Feb-11 2:24
Ryano12114-Feb-11 2:24 
GeneralRe: PolyLib Modifying the ToString method Pin
Luc Pattyn14-Feb-11 2:46
sitebuilderLuc Pattyn14-Feb-11 2:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.