Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Problem with an equation.

I'm using a macro to build an equation where "x" is an unknown. When
finished calculations will be performed and "x" will be assigned values.

The right side of the equation is a series. The first time throught the
progaam it builts the first element of the series like so:

q = s * exp(t*x)

The next time through it adds another element like so:

q = s * exp(t*x) + s * exp(t*x)...

and so on until it is finished.

Since "t" and "s" have diferent values in each element I want the equation
to use the actual values in each element but leave the "x" unassigned like
so:

q = 20.5817 * exp(22*x) + 62.4573 * exp(58*x)...

I've tried every way to get this to work but it always assumes "x" = 0 and
computes the equation.

Can someone help me?

Jim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Problem with an equation.

Jim,
This approach might suit your needs. It builds each element of your
equation as a string and substitutes values of s and t.. When the last
element has been built, you can substitute y (cannot use x as the x in "exp"
will be changed!)

I haven't checked the maths!

Sub BuildEquation()
Dim qx()

str1 = "s * exp("
str2 = "t + y)"

For i = 1 To 5 <==== Change to suit you needs
sx = Rnd() * 100 ' Test value of s
tx = Int(Rnd() * 100) ' Test values of t
strA = Replace(str1, "s", sx)
strB = Replace(str2, "t", tx)
ReDim Preserve qx(i)
qx(i) = strA + strB
Next i

yx = 20 ' Subtitute value for y (x in your original)

q = 0
For i = 1 To UBound(qx)
strq = Replace(qx(i), "y", yx)
qVal = Evaluate(strq)
q = q + qVal
Next i

MsgBox q

End Sub


HTH
"jim simpson" wrote:

I'm using a macro to build an equation where "x" is an unknown. When
finished calculations will be performed and "x" will be assigned values.

The right side of the equation is a series. The first time throught the
progaam it builts the first element of the series like so:

q = s * exp(t*x)

The next time through it adds another element like so:

q = s * exp(t*x) + s * exp(t*x)...

and so on until it is finished.

Since "t" and "s" have diferent values in each element I want the equation
to use the actual values in each element but leave the "x" unassigned like
so:

q = 20.5817 * exp(22*x) + 62.4573 * exp(58*x)...

I've tried every way to get this to work but it always assumes "x" = 0 and
computes the equation.

Can someone help me?

Jim



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Problem with an equation.

Modified version which builds a single equation:

Sub BuildEquation()

Dim qstr As String, str1 As String, str2 As String
Dim strA As String, strB As String

str1 = "s * exp("
str2 = "t + y)"

For i = 1 To 5

sx = Rnd() * 100
tx = Int(Rnd() * 100)

strA = Replace(str1, "s", sx)
strB = Replace(str2, "t", tx)

qstr = qstr + strA + strB & " + "

Next i

yx = 20 ' Replace y with this value

qstr = Left(qstr, Len(qstr) - 3)
qstr = Replace(qstr, "y", yx)

MsgBox qstr
MsgBox Evaluate(qstr)

End Sub

"Toppers" wrote:

Jim,
This approach might suit your needs. It builds each element of your
equation as a string and substitutes values of s and t.. When the last
element has been built, you can substitute y (cannot use x as the x in "exp"
will be changed!)

I haven't checked the maths!

Sub BuildEquation()
Dim qx()

str1 = "s * exp("
str2 = "t + y)"

For i = 1 To 5 <==== Change to suit you needs
sx = Rnd() * 100 ' Test value of s
tx = Int(Rnd() * 100) ' Test values of t
strA = Replace(str1, "s", sx)
strB = Replace(str2, "t", tx)
ReDim Preserve qx(i)
qx(i) = strA + strB
Next i

yx = 20 ' Subtitute value for y (x in your original)

q = 0
For i = 1 To UBound(qx)
strq = Replace(qx(i), "y", yx)
qVal = Evaluate(strq)
q = q + qVal
Next i

MsgBox q

End Sub


HTH
"jim simpson" wrote:

I'm using a macro to build an equation where "x" is an unknown. When
finished calculations will be performed and "x" will be assigned values.

The right side of the equation is a series. The first time throught the
progaam it builts the first element of the series like so:

q = s * exp(t*x)

The next time through it adds another element like so:

q = s * exp(t*x) + s * exp(t*x)...

and so on until it is finished.

Since "t" and "s" have diferent values in each element I want the equation
to use the actual values in each element but leave the "x" unassigned like
so:

q = 20.5817 * exp(22*x) + 62.4573 * exp(58*x)...

I've tried every way to get this to work but it always assumes "x" = 0 and
computes the equation.

Can someone help me?

Jim



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Problem with an equation.

Topper,

Thanks for your help. I think it will work OK

Jim


"Toppers" wrote in message
...
Modified version which builds a single equation:

Sub BuildEquation()

Dim qstr As String, str1 As String, str2 As String
Dim strA As String, strB As String

str1 = "s * exp("
str2 = "t + y)"

For i = 1 To 5

sx = Rnd() * 100
tx = Int(Rnd() * 100)

strA = Replace(str1, "s", sx)
strB = Replace(str2, "t", tx)

qstr = qstr + strA + strB & " + "

Next i

yx = 20 ' Replace y with this value

qstr = Left(qstr, Len(qstr) - 3)
qstr = Replace(qstr, "y", yx)

MsgBox qstr
MsgBox Evaluate(qstr)

End Sub

"Toppers" wrote:

Jim,
This approach might suit your needs. It builds each element of

your
equation as a string and substitutes values of s and t.. When the last
element has been built, you can substitute y (cannot use x as the x in

"exp"
will be changed!)

I haven't checked the maths!

Sub BuildEquation()
Dim qx()

str1 = "s * exp("
str2 = "t + y)"

For i = 1 To 5 <==== Change to suit you needs
sx = Rnd() * 100 ' Test value of s
tx = Int(Rnd() * 100) ' Test values of t
strA = Replace(str1, "s", sx)
strB = Replace(str2, "t", tx)
ReDim Preserve qx(i)
qx(i) = strA + strB
Next i

yx = 20 ' Subtitute value for y (x in your original)

q = 0
For i = 1 To UBound(qx)
strq = Replace(qx(i), "y", yx)
qVal = Evaluate(strq)
q = q + qVal
Next i

MsgBox q

End Sub


HTH
"jim simpson" wrote:

I'm using a macro to build an equation where "x" is an unknown. When
finished calculations will be performed and "x" will be assigned

values.

The right side of the equation is a series. The first time throught

the
progaam it builts the first element of the series like so:

q = s * exp(t*x)

The next time through it adds another element like so:

q = s * exp(t*x) + s * exp(t*x)...

and so on until it is finished.

Since "t" and "s" have diferent values in each element I want the

equation
to use the actual values in each element but leave the "x" unassigned

like
so:

q = 20.5817 * exp(22*x) + 62.4573 * exp(58*x)...

I've tried every way to get this to work but it always assumes "x" = 0

and
computes the equation.

Can someone help me?

Jim





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel equation problem Jackie Excel Worksheet Functions 1 August 14th 09 05:27 PM
Equation Editor- problem when editing an equation Gaby L. Excel Discussion (Misc queries) 0 September 27th 05 09:24 PM
Problem with Equation Display Doug Excel Discussion (Misc queries) 3 August 26th 05 02:48 AM
Equation setup problem Hansel Excel Discussion (Misc queries) 2 June 21st 05 02:31 AM
equation problem Dinie Excel Worksheet Functions 1 December 8th 04 06:26 PM


All times are GMT +1. The time now is 05:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"