Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Good afternoon
I make a calculator witch want to find integration value by use Rihman sum and find area
I make f(x) and want to find value of f(x) in each X=xi
so i need to replace X with value (xi) and find the result
I use
VB
dim T as string
t = textbox1.text
t.replace("X",1)


but I have error
for example
F(x)= 5*Sin(X)
and want to find area between 1-2
we divided filed [1-2] to 10
make a loop
while i<=2 then
Area = Area + F(i)
I have problem in replace
what I can do ?

[EDIT - OP Code from "Solution"]
I use VBProvider to compile the equation (as string) to find result
I use :CodeDom.Compiler.CompilerParameters
this find a value of any string like
Sin(1)*3-4
but to find a result of integration between [a,b] , I devided filed into 1000000 filed (dx)
while dx = [a-b]/n<br />


find value of integration we find value of f(x) in Xi then find dA=F(Xi)*dx
then find A = Sum(dA)
this method called Rihman sum
Now I make a loop find a value of F(Xi) where Xi between [a,b]
I have an equation as string (for example : F(x) = 3*Sin(x) )
I want to calculate integration between [1,2] so I must find F(x) value when
X=1
X=1.1
X=..
X=1.9
X=2
and find A=Sum(dA) = Sum (F(Xi))*dX
so I need a loop replace X with its value (1,1.1,1,2,....,1.9,2)
I wish you understand me Smile | :)
Posted
Updated 2-Nov-14 9:36am
v2
Comments
Sergey Alexandrovich Kryukov 31-Oct-14 13:58pm    
How numeric arithmetic can be related to string replace? If you need to find some area, use appropriate numeric calculations.
—SA
PIEBALDconsult 31-Oct-14 13:59pm    
I suspect you need to assign the result of t.replace("X",1) to some variable (perhaps t?).
In fact, how about t = textbox1.text.replace("X",1)

1 solution

If you want to evaluate expressions, please visit this: A Calculation Engine for .NET[^]. At the bottom of the article you'll find links to the other useful articles.
 
Share this answer
 
Comments
[no name] 31-Oct-14 15:08pm    
My favorite :-), my 5
Maciej Los 31-Oct-14 16:43pm    
Thank you, Bruno. Your answer inspired me ;)
Manas Bhardwaj 2-Nov-14 14:00pm    
Yes, +5!
Maciej Los 2-Nov-14 14:51pm    
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900