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

# 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!

ola
gonzales!

0
gonzalesblanco
• 6
• 4
1 Solution

Commented:
>>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 Commented:
he!

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

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

ola
gonzales
0

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

0

Author 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

Author 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

Author 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

Commented:
>>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

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

Author 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

Commented:

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;

etc etc
}

Maybe create a helper class like this one

class CMathCubic
{
public:
CMathCubic () { m_dxCubedPart = 0; .. zero all}
public:
{ m_dxCubedPart += dVal; }
{ m_dxSquraedpart += dVal; }
{ m_dxPart += 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 Commented:
Sorry for giving feedback so late!!!

Your idea works really fine!! Thank you!!

gonzalesblanco
0

## Featured Post

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