Hi Friends i need your suggestions my requirement is to get the input in string for example X^2 + X^2 + 4X + 9X + X = 10 + 1 * 2 % 4 now we need to slove it and find the value of x like the link below link
we also need to do the validation of input that i already did just need suggestions how can we solve these equations using c#
I split the equation and create the function to get numeric array and operators now I am trying to figure out the logic how can we process it any suggestions?
- public class Calculation
-
- string[] opers = new string[] { "+", "-", "/", "*", "%", "^" };
- public string Process(string value)
- {
- string result = string.Empty;
- string[] equations = value.Split('=');
- calculate(equations[0]);
- calculate(equations[1]);
- return result;
- }
-
- private string calculate(string eq)
- {
- string result = eq;
- string variable = string.Empty;
- List<string> NumberList = new List<string>();
- List<string> OperatorList = new List<string>();
- GetLists(eq, ref NumberList, ref OperatorList);
-
-
- }
- private void GetLists(string value, ref List<string> numberlist, ref List<string> operatorList)
- {
- string[] operatorrArray = value.Split(' ');
- foreach (var item in operatorrArray)
- {
- if (opers.Contains(item))
- {
- operatorList.Add(item);
- }
- else
- {
- numberlist.Add(item);
- }
- }
- }
can you please help me out with logic how can we processed the sample input will be in string like following formate
- 2X – 1 = 0
- 3X + 8X = 33
- 4X - 7 = 8X - 5
- X / (x+12) = 1 / 13
- X^2 + X^2 + 4X + 9X + X = 10 + 1 * 2 % 4