• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Handle math. variables?

hello,

how can i handle math. variables in a mfc-app. for example:

x+3+x^2+5+3x erg: x^2+4x+8;

which datatype is the x variable (there is no value for x, its only symbolic!)

want to use the erg for further math operations!

thank you for every advice!!

ola
gonzales!






















0
gonzalesblanco
Asked:
gonzalesblanco
  • 6
  • 4
1 Solution
 
FrenchFriesCommented:
>>which datatype is the x variable (there is no value for >>x, its only symbolic!)

I would recommend you to use CString class and Format method ;
then you could format and convert into desired data type .
Do you want to write an mathematical expression parser ?  
0
 
gonzalesblancoAuthor Commented:
he!

first thank you for answering!

I have to include a curve-interpolation into my app., never thougt about this problem, but now i have it.

ad your tipp:

i won't be able to do math. operations with tis method!!!
but i have to!

ola
gonzales
0
 
FrenchFriesCommented:
>>i won't be able to do math. operations with tis method!!!
why won't you be able ?
Please tell me
( if you're a speaking spanish person please explain your problem and send me an e-mail :martymat_m@yahoo.com)


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gonzalesblancoAuthor Commented:
He FrenchFries!

Unfortunately I'm a native-german(austrian)-speaker! (the name is dedicated to RAUL!!!) But I try to explain my Problem in English more detailed.

I have to do a interpolation, i came up to this:
x = always x!!!!! not a Value (x1, ...is a float/int value)

L(o)= (x-x1)*(x-x2)../(x0-x1)*(x0-x2)...
L(1)= ......
 
P=y0*L0 +y1*L1....

this should give a formular like: L=x^3+x^2+x+d

this should describe my curve!!!

I need to get the P out of 40 L Formulas.

The Problem for me is how to type that in as a code, cause i can not to type L = ....(see above), cause it is not possible (??) to add/div/mult/subtr a symbol (x) from/to x!

Have I to think about a hand-made structure to do this, or is there a ready class, which can help me!!

danke!
gonzalesBlanco

0
 
gonzalesblancoAuthor Commented:
He FrenchFries!

Unfortunately I'm a native-german(austrian)-speaker! (the name is dedicated to RAUL!!!) But I try to explain my Problem in English more detailed.

I have to do a interpolation, i came up to this:
x = always x!!!!! not a Value (x1, ...is a float/int value)

L(o)= (x-x1)*(x-x2)../(x0-x1)*(x0-x2)...
L(1)= ......
 
P=y0*L0 +y1*L1....

this should give a formular like: L=x^3+x^2+x+d

this should describe my curve!!!

I need to get the P out of 40 L Formulas.

The Problem for me is how to type that in as a code, cause i can not to type L = ....(see above), cause it is not possible (??) to add/div/mult/subtr a symbol (x) from/to x!

Have I to think about a hand-made structure to do this, or is there a ready class, which can help me!!

danke!
gonzalesBlanco

0
 
gonzalesblancoAuthor Commented:
He FrenchFries!

Unfortunately I'm a native-german(austrian)-speaker! (the name is dedicated to RAUL!!!) But I try to explain my Problem in English more detailed.

I have to do a interpolation, i came up to this:
x = always x!!!!! not a Value (x1, ...is a float/int value)

L(o)= (x-x1)*(x-x2)../(x0-x1)*(x0-x2)...
L(1)= ......
 
P=y0*L0 +y1*L1....

this should give a formular like: L=x^3+x^2+x+d

this should describe my curve!!!

I need to get the P out of 40 L Formulas.

The Problem for me is how to type that in as a code, cause i can not to type L = ....(see above), cause it is not possible (??) to add/div/mult/subtr a symbol (x) from/to x!

Have I to think about a hand-made structure to do this, or is there a ready class, which can help me!!

danke!
gonzalesBlanco

0
 
FrenchFriesCommented:
>>Have I to think about a hand-made structure to do this, >>or is there a ready class

Unfortunately no,  there is no such a class among MFC classes.
One solution would be to use mechanisms like stacks (or even collections / linked lists) :
as you are reading the formula you push every term on to the stack and then you can pop it from the stack when needed.
With a stack mechanism you can also get the index of your element and the order of list creation

See CList , CArray , CTypedPtrList...

0
 
FrenchFriesCommented:
(Sorry I didn't know that Raul Gonzales Blanco was a soccer player :-))
0
 
gonzalesblancoAuthor Commented:
He FrenchFries!

Unfortunately I'm a native-german(austrian)-speaker! (the name is dedicated to RAUL!!!) But I try to explain my Problem in English more detailed.

I have to do a interpolation, i came up to this:
x = always x!!!!! not a Value (x1, ...is a float/int value)

L(o)= (x-x1)*(x-x2)../(x0-x1)*(x0-x2)...
L(1)= ......
 
P=y0*L0 +y1*L1....

this should give a formular like: L=x^3+x^2+x+d

this should describe my curve!!!

I need to get the P out of 40 L Formulas.

The Problem for me is how to type that in as a code, cause i can not to type L = ....(see above), cause it is not possible (??) to add/div/mult/subtr a symbol (x) from/to x!

Have I to think about a hand-made structure to do this, or is there a ready class, which can help me!!

danke!
gonzalesBlanco

0
 
williamcampbellCommented:

 Do you have a set formulae for L[0]?
 If you do then expand it out completely (you must do this)

 so you end up with aX^3 + bX^2 + cX + d

 where a = (x1-x2/x2*x1)  etc

 Then create a function called LFormula

 LFormula ( double x1, double x2, double Y1, double Y2 )
 {
    CMathCubic mc;
    mc.AddXCubed ( x1-x2/x2*x3 );
 
    etc etc
 }

Maybe create a helper class like this one
 
  class CMathCubic
  {
      public:
          CMathCubic () { m_dxCubedPart = 0; .. zero all}
      public:
             AddXCubed ( double dVal )
             { m_dxCubedPart += dVal; }
             AddXSqPart ( double dVal )
             { m_dxSquraedpart += dVal; }
             AddXPart ( double dVal )
             { m_dxPart += dVal; }
             AddConstant ( double dVal )
             { m_dConstant += dVal; }

      public:
            CString& GetFormula ()
            {
              m_csFormula.Format (" %.1fx^3 %.1fx^2 %.1fx %.1f", m_dxCubedPart, m_dxSqaredPart ... etc

               return m_csFormula;
            }
      private:
          double m_dxCubedPart;
          double m_dxSqaredPart;
          double m_dxPart;
          double m_dConstant;
          Cstring m_csFormula;
  };
 
 
0
 
gonzalesblancoAuthor Commented:
Sorry for giving feedback so late!!!

Your idea works really fine!! Thank you!!

gonzalesblanco
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now