?
Solved

Handle math. variables?

Posted on 2003-03-14
14
Medium Priority
?
261 Views
Last Modified: 2013-11-20
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
Comment
Question by:gonzalesblanco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
14 Comments
 

Expert Comment

by:FrenchFries
ID: 8135794
>>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
 

Author Comment

by:gonzalesblanco
ID: 8135862
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
 

Expert Comment

by:FrenchFries
ID: 8136084
>>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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 

Author Comment

by:gonzalesblanco
ID: 8136230
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
 

Author Comment

by:gonzalesblanco
ID: 8136446
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
 

Author Comment

by:gonzalesblanco
ID: 8136449
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
 

Expert Comment

by:FrenchFries
ID: 8136518
>>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
 

Expert Comment

by:FrenchFries
ID: 8136532
(Sorry I didn't know that Raul Gonzales Blanco was a soccer player :-))
0
 

Author Comment

by:gonzalesblanco
ID: 8136559
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
 
LVL 12

Accepted Solution

by:
williamcampbell earned 200 total points
ID: 8138071

 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
 

Author Comment

by:gonzalesblanco
ID: 8174408
Sorry for giving feedback so late!!!

Your idea works really fine!! Thank you!!

gonzalesblanco
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question