Math output

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2009
Posts: 331
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 61
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
0
  #51
Oct 5th, 2009
Okay, the FormatText function works, i wrote and tested it in a seperate app. Can you use a breakpoint and tell me what the input is at the start of the method and what it is at the end please.

Also, go line by line to see where it is hanging.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 331
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 61
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
0
  #52
Oct 5th, 2009
Ignore last post...thread hadnt updated to show your last message

Glad you got it working. Took some doing but we got there
Last edited by Ryshad; Oct 5th, 2009 at 10:57 am.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #53
24 Days Ago
For finding nth root , latex format is "\sqrt[]{}" and on button click the form which displays in textbox is : "root:[]{}" . Now to convert this "root:[]{}" into latex format i am using following code :
  1. const string matchNumerator1 = @"root:\((?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)";
  2. const string matchDenominator1 = @"\((?<Denominator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)";
  3. const string matchBoth1 = matchNumerator1 + matchDenominator1;
  4. System.Text.RegularExpressions.Match n = System.Text.RegularExpressions.Regex.Match(input, matchBoth1);
  5. while (n.Success)
  6. {
  7. string sNumerator1 = n.Groups["Numerator4"].Value;
  8. string sDenominator2 = n.Groups["Denominator4"].Value;
  9. string latex1 = @"\sqrt[" + sNumerator1.ToString() + "]{" + sDenominator2.ToString() + "}";
  10. input = input.Remove(n.Index, n.Length);
  11. input = input.Insert(n.Index, latex1);
  12. n = System.Text.RegularExpressions.Regex.Match(input, matchBoth1);
  13.  
  14. }

And I using this code just after the fraction code.
But this code is not giving desired result .
Kindly help me out..........
Last edited by vinnijain; 24 Days Ago at 8:55 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 331
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 61
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz
 
2
  #54
24 Days Ago
Of course it isnt working; you told me the format was root:()() so thats what it is looking for.

  1. const string matchNumerator1 = @"root:\[(?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]";
  2. const string matchDenominator1 = @"\{(?<Denominator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\}";

the above code will find the string you need.


Once again, i cannot understate the importance of learning what the code is doing. The numerator and denimonator code hasnt changed at all from the fraction regex. All that has changed is the enclosing parentheses.

\((?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)

root:\[(?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]

You could have easily changed the symbols yourself. I'm not trying to rant or condescend but, if you are trying to learn how to code, these are the kind of problems you will face all the time and learning how to overcome them yourself will make you a much stronger programmer. Every time you encounter new syntax, or a structure you havent used before, experiment with it, read the documentation for it, disect it. You need to understand exactly what its doing so that you can adapt it for future problems. The same goes for code that you are given in forums. We will gladly help you out and provide you with code, but its SO important that you dont just copy and paste the code and move on...learn why the code you are given works. Look at how it has been structured so that you can learn how other coders solve problems.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #55
24 Days Ago
Thanks for replying ........
This I have already done.......but problem is that it is not working when I am trying to enter fraction...........
I don't what's the problem............
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 331
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 61
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz
 
0
  #56
23 Days Ago
Originally Posted by vinnijain View Post
Thanks for replying ........
This I have already done.......but problem is that it is not working when I am trying to enter fraction...........
I don't what's the problem............

Have you added the code i gave you for powers, or have you replaced the old code with the new?

The old code replace fractions, the new code replaces powers. You need to have both. If you have implemented both correctly it will work fine for fractions within powers and vice versa:

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. textBox2.Text = FormatText(textBoxEquation.Text);
  4. }
  5.  
  6. private string FormatText(string input)
  7. {
  8. input = ReplaceFrac(input);
  9. input = ReplacePowers(input);
  10.  
  11. return input;
  12. }
  13.  
  14. private string ReplaceFrac(string input)
  15. {
  16. const string matchNumerator = @"\((?<Numerator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)";
  17. const string matchDenominator = @"\((?<Denominator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)";
  18. const string matchBoth = matchNumerator + @"\/" + matchDenominator;
  19.  
  20. System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  21. while (m.Success)
  22. {
  23. string dNumerator = m.Groups["Numerator"].Value;
  24. string dDenominator = m.Groups["Denominator"].Value;
  25. string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}";
  26. input = input.Remove(m.Index, m.Length);
  27. input = input.Insert(m.Index, latex);
  28.  
  29.  
  30. m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  31. }
  32.  
  33. return input;
  34. }
  35.  
  36. private string ReplacePowers(string input)
  37. {
  38. const string matchNumerator = @"root:\[(?<Numerator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]";
  39. const string matchDenominator = @"\{(?<Denominator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\}";
  40. const string matchBoth = matchNumerator + matchDenominator;
  41.  
  42. System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  43. while (m.Success)
  44. {
  45. string dNumerator = m.Groups["Numerator"].Value;
  46. string dDenominator = m.Groups["Denominator"].Value;
  47. string latex = @"\sqrt [" + dNumerator.ToString() + "]{" + dDenominator.ToString() + "}";
  48. input = input.Remove(m.Index, m.Length);
  49. input = input.Insert(m.Index, latex);
  50.  
  51.  
  52. m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  53. }
  54. return input;
  55. }
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 117
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster
 
0
  #57
23 Days Ago
Thanks a lot Ryshad...........
It works............
I hav'nt removed the code but the mistake which I have done was that I added both codes one after the another instead of making functions and the calling those functions.................

I understood my mistake..........
Now the code works fine......................
Thanks once again...............
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 331
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 61
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz
 
0
  #58
23 Days Ago
Originally Posted by vinnijain View Post
Thanks a lot Ryshad...........
It works............
I hav'nt removed the code but the mistake which I have done was that I added both codes one after the another instead of making functions and the calling those functions.................

I understood my mistake..........
Now the code works fine......................
Thanks once again...............
You can call them one after the other, it shouldnt cause a problem.(EDIT thats exactly what happens when you call the methods one after the other)

I just moved them to methods to make the code tidier/more readable/easier to maintain. Also, the regex variables are declared as const so you cant change them so if you wanted both pieces of code in the main method you would need to declare new variables for the new regex

Either way, glad it all works for ya...remember to mark the thread as solved and turn out the lights when you leave
Last edited by Ryshad; 23 Days Ago at 6:52 am.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 331
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 61
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz
 
0
  #59
23 Days Ago
Originally Posted by vinnijain View Post
I added both codes one after the another instead of making functions and the calling those functions
Just a footnote, in C# there arent technically functions. A function is generally a code block that exists outside of an object, a stand alone block of code. As C# is object oriented, all code is associated with a class and is therefore a method.

Many people (including myself on occasion) misuse the terms, so i thought i'd just throw this in to try and un-muddy the waters of c# jargon :p
Last edited by Ryshad; 23 Days Ago at 6:53 am.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC