Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi

I want to solve an equation in asp.net c#
 
Equation is

 int x0 = 5;
      int x1 = 2;
 
then

y = (x-x0)/(x0-x1)
it should return like
 
y = (x-5)/3;
 
But
 
It shows an error like x is undefined....
 

Please help me in solving this.
 

With Regards
 
Thanks in Advance
 
Manju K
Posted 9-Aug-11 0:32am
Edited 9-Aug-11 0:39am
Slacker00771.5K
v3
Comments
digimanus at 9-Aug-11 6:36am
   
please show all code. in your code above there is no int x;
Syed Salman Raza Zaidi at 9-Aug-11 6:36am
   
Yes, it will give error as where are you assigining value for x??userinput or hardcoded?
BlackJack99 at 9-Aug-11 6:55am
   
i think he meant x as the user input and y as the return value.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Please have a look this site which might help you,
 
Converting math equations to C#[^]
 
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i don't see you have been declare variable x, y
so that the compiler throws that error
 
to solve that error, you can declare x, y variable inside your function like:
int x = 100; // value 100 is an example 
int y = 100; // value 100 is an example 
int x0 = 5;
int x1 = 2;
....
 
or write an function like:
public int MyEquation(int x)
{
     int y;
 
     // here is your code

     return y;
}
  Permalink  
v2
Comments
manjukgowda at 9-Aug-11 6:43am
   
I want to make it as it should return an equation like y = (x-5)/3;
Van Hua at 9-Aug-11 6:46am
   
public int MyEquation(int x)
{
return (x - 5) / 3;
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to tell us what exactly you are trying to acheieve here. With the given information, this can be very easily done through String.Format. But does it help you? I think it will not.
 
int x0 = 5;
int x1 = 3;
string originalString = "y = (x-{0})/({1})";
 
string updatedString = string.Format(originalString, x0, (x0 - x1));
 
You need to implement a parser of your own which could solve the equations. One needs to be well aware of your requirements to help you out. Search google for "C# Equation Parser". It may give you some ideas to start with.
  Permalink  
v2
Comments
manjukgowda at 9-Aug-11 6:41am
   
You are not getting my question
 
I want to make it as it should return like y = (x-5)/3;
d@nish at 9-Aug-11 6:47am
   
Yes, I got it right after posting my first reply. I have updated my answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

of course it will ,you haven't declared x,I see you have declared x0 and x1 only , the compiler won't understand what you want till you tell it
 

the solution of this type of problem is treating with variables of an equation (not of program asp...etc ) as string and using post-fix notation to solve it with some change that you will determine the variable as it is with out value
e.g
(X-x0)/(x0-x1)---post-fix--> Xx0-x0x1-/
the X means that it's variable of an equation solve it using stack I'll post the solution later.....

 

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

That's because you haven't declared x yet.
 
(Engineers shouldn't be allowed to do their own programming.)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Programming languages (usually) don't directly support symbolic algebra manipulation, have a look at Computer Algebra Systems[^] page at Wikipedia to get an idea about what you are trying to do.
  Permalink  
v3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 Gihan Liyanage 272
2 vikinghunter 176
3 ClimerChinna 172
4 Richard MacCutchan 150
0 Sergey Alexandrovich Kryukov 8,653
1 OriginalGriff 7,132
2 CPallini 2,598
3 Richard MacCutchan 2,060
4 Abhinav S 1,808


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 9 Aug 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100