fusioneko Posted October 11, 2007 Share Posted October 11, 2007 1. 4k - 11k + 8k - 9k 2. 19j + 16j 3. 10r - 18r + 3r2 - 5r2 4. 13t + 16v + 2t 5. 3e - 6e 6. 7h - 12h2 + 18h2 7. 5s - 17s2 - 4s - 9s 8. 1g + 12g - 15g + 3g + 4g 9. 19m - 11m2 - 5m + 7m2 10. 8z + 16z - 19z 11. 2b + 11a + 13w – 6b – 3w 12. 12y + 8x + 13y + 4x when y= 2, x= 5 13. 9n + 17b when n= 2, b= 7 14. 16f - 11u – 10f - 8u – 3u 15. 2t2 + 3t2 - 4t + 12t Im trying to think of a method to actually.. deal with this. I don't even understand the work my school is sending me. Even I read it I have no idea what the letters mean. (WTF why do I need to learn crap like this, why not a 1 + 1 example pl0x) anywya, Is their anyway to write a caculator out for this stuff? Quote Link to comment Share on other sites More sharing options...
btherl Posted October 11, 2007 Share Posted October 11, 2007 I think you should ask your teacher about it. Isn't there a description of the problem at the top of these questions? Some kind of explanation of what you should be doing? Quote Link to comment Share on other sites More sharing options...
wsantos Posted October 11, 2007 Share Posted October 11, 2007 Dude it's basic algebra. 1. 4k - 11k + 8k - 9k = -4k 2. 19j + 16j = 35j and so on for cases like... 7. 5s - 17s2 - 4s - 9s => 17s2 means 17 s squared for cases like 12. 12y + 8x + 13y + 4x when y= 2, x= 5 you substitute the value 12*(5) + 8*5 + 13*2 +4*5 why need php for such basic problems?... in any case what I would do is parse it with the arithmethic operators and store it an array...hope this help Quote Link to comment Share on other sites More sharing options...
fusioneko Posted October 11, 2007 Author Share Posted October 11, 2007 I feel like learning how to make a caculator, the need to learn how to seems fun, but I don't yet understand how to deal with math on this level, It seems very intresting and fun. Basic algebra or not. You can say im 'Speacial', and I figure I'd learn how ot actually do the math even better if I make a caculator script for it. then Quote Link to comment Share on other sites More sharing options...
Barand Posted October 11, 2007 Share Posted October 11, 2007 WTF why do I need to learn crap like this, If you can't handle variables in basic algebra, how do you expect to handle them when programming? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 11, 2007 Share Posted October 11, 2007 Forgive me for laughing, but lol. First, making a calculator to solve those for you is significantly more difficult than just solving them on pen and paper. Second, I had a ton of trouble with algebra when it was first introduced to me. Let's see, I was in 7th grade, had missed some school, came back and went to math class. Then the teacher assigns us some work and I see all these letters all over the place in my otherwise normal problems. I'm thinking, "WTF?!" I asked my teachers and class mates about it numerous times, but no one explained it properly so I was confused as shit for a while. Not only that, but until that point I'd been a whiz at math so I was very frustrated to not know what was going on. So here's my explanation for you. 1 + 3 * 4 Let's say I was talking to you in real life and I wanted to tell you that I had thirteen apples. Which of the following two sentences would I use in real life if I were talking: #1: "I have 1 plus 3 times 4 apples!" #2: "I have 13 apples!" Obviously I would use sentence #2. It is easier for me to say and you don't have to think about the number thirteen, you already understand 13. But if I told you how many apples I had as math formula, you'd have to compute it in your head before you knew how many apples I had; that's inconvenient for you. The process of taking a math formula and solving it as much as possible is called simplification. In the problems you posted the teacher is probably wanting you to simplify the math formulas. Let's say you are holding 2 nickels in your left hand and 3 nickels in your right hand; how many nickels are you holding altogether? Easily enough we know you're holding 5. But how do we write that in algebra? Let's let n stand for a nickel. You have two nickels in your left hand, so 2n represents your left hand. You have three nickels in your right hand, so 3n represents your right hand. 2n + 3n If we add 2 n's to 3 n's, we'll have a total of 5 n's. In other words, we have 5 nickels, which we knew already. We write this as an equality using an equal sign: 2n + 3n = 5n Basically, those letters in the formulas represent arbitrary things in the real world. The numbers next to them represent how many of them you have. Here, you have 2 x's 2x Now you have 3 y's 3y An important concept in algebra is what we call like terms. "Like terms" are those with the same variable. The following are like terms since they all contain x: 3x 4x 20x The following are not like terms since they all contain different variables (letters): 2a 3b 5c Whenever you see variables in a formula, you can combine the like terms. 2a + 3b +7a +4c -1b First we rewrite the formula so that like terms appear near each other: 2a + 7a + 3b - 1b + 4c Now we perform the math where the variables are the same (we combine the a terms with the other a terms, the b terms with the other b terms, and there is only a single c term so it remains unchanged) 9a + 2b +4c Let me know if that helps some. Quote Link to comment Share on other sites More sharing options...
fusioneko Posted October 11, 2007 Author Share Posted October 11, 2007 Yeah I understand now, and heres a Scary part Im in 11th grade and I finnaly got this. Reasons why is becuase im placed on some independent educational plan. Otherwise, I did want to add the values up, I feel the need to learn really. Yeah your explanation seems all clear, It appears, I'm hhaving trouble understanding like terms, But yeah. But what boggles me more is WTF would it be needed for, I understand how some of this works. Most of it seems clear, But I'm not to sure if I think It's clear or I just believe it's clear, and im lying to myself. Anyway. anyway to make a calculator with this? Quote Link to comment Share on other sites More sharing options...
corbin Posted October 12, 2007 Share Posted October 12, 2007 1. 4k - 11k + 8k - 9k = -4k That would actually be -8k ;p. Was just scrolling by and saw that hehe ;p. Anyway, when would you need it.... Hmmm.... hard to think of an example off the top of my head that would make sense in real life without getting too complicated.... Actually... I can't think of a useful example of that off the top of my head, but once you get into more complex algebra, geometry, so on, things become more useful. For example: Bob has a roof line where it's a triangle (90 degree angle for simplisity). something like: -| - | - | - | - | _________| (pretend it looks like a triangle) He knows the right side is 3 meters tall, and he knows the bottom is 4 meters long, but he doesn't know how long to make the hypotenuse. Thanks to a guy named Pythagoras (slightly sarcastic) we know that a^2 + b^c = c^2 where c is the hypotenuse, or the side opposite the 90 degree angle (the longest side). a and b can be either of the legs besides the hypotenuse. So 3^2 + 4^2 = c^2 16 = c^2 So, to get rid of the power, you would find the square root of 16 which would be 4, thus the hypotenuse would need to be 4m. Sounds kind of pointless there, and that's not exactly what you're doing right now, but it was the only example I could think of in my tired state.... lol -------------------- As for doing it with PHP.... lemme write something really quickly.... Quote Link to comment Share on other sites More sharing options...
btherl Posted October 12, 2007 Share Posted October 12, 2007 Here's an example.. let's say you have 4 apples, 3 oranges and a banana. Then someone gives you 2 apples and 2 bananas. You can write it as: 4a + 3o + b (what you start with) 4a + 3o + b + 2a + 2b (plus 2 apples and bananas) = 6a + 3o + 3b (the total) That may not seem so useful, but it gives an idea of why you might want to keep the like terms together. It's because each term represents some different thing in reality. It's possible that terms are equal, but until you know they are you have to keep them separate, because they might be different. Maybe what you thought was oranges were actually bananas (and you need new glasses), so you can merge b and o into b. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 12, 2007 Share Posted October 12, 2007 But what boggles me more is WTF would it be needed for Everything. Algebra is the basis for calculus which is the basis for physics. Physics forms the basis for everything you take for granted in life. Without this stuff there would be no electronics, no space exploration, no way to engineer earthquake safe buildings, etc. Likewise, many of physical equations allow us to prove certain things. For example, by measuring the length of skid marks you can estimate very accurately how fast someone was driving before a collision. This would be useful in court when trying to prove someone is at fault for causing an accident because they were driving too fast for the weather conditions. Just learn the process now. Gradually over time you will learn the application. Of course, if your greatest ambition in life is to flip hamburgers then you don't need to pay any attention at all. Quote Link to comment Share on other sites More sharing options...
corbin Posted October 12, 2007 Share Posted October 12, 2007 Ahhh I must say I love roopurt18's response, and I don't think I would have bothered with my example in the middle had I seen it before I typed all of this out, but here it is anyway: Ahhh got distracted with something irl, but here it is.... This script is very limited in what it can do.... It basically can only parse expressions (not equations). Also, in these expressions, all exponents must be 1, all numbers must be integral, grouping is not evaluated, and operations aren't evaluated. Things that would work: a+4b+4a-9c would be simplified to 5a+b-9c Basically anything with anything but 1-9, -, +, and a-z in it cannot be parsed by this script (you might notice the regexp pattern is similar ;p). Another example of using variables would be (this is a little more advanced than what you're doing, but I just want to show an example use): Let's say a school is charging $2 for students to get in at a football game and $5 for anyone else. Let's also say that they want to make $500. How many student tickets and/or other tickets would they need to sell to meet their goal? Well, we can call the number of student tickets sold s, and the number of other tickets sold called o. That would mean that the price of s times the number of student tickets sold + the price of other tickets times the number of tickets sold would need to be 500. This can also be expressed as 500 = 2s + 5o. To do something with this, it would be useful to get one of the variables on a side alone. Slope intercept form (don't worry about what that is ;p), which is a way of expressing a graph (ok math people don't freak out; I know that's worded oddly, and is kind of vague), is y = mx+b where m is the slope, and b is the y intercept (where the line crosses the Y axis). Well, we need to make s and o into x and y. I will use o as x and s as y since that's the alphabetical order. Then, I need to solve for s. 2s = -5o + 500 s = (-5/2)o + 250 This would mean that s, the independant variable, is equal to negative five halves of o + 250. Why is this important? Well, let's say they sold 100 other tickets. How many student tickets would they need to sell? If you plug in 100 for o, you can solve for the amount of student tickets. s = (-5/2)(100) + 250 s = -250 + 250 s = 0 Thus, if you sold 100 other tickets, you would have to sell 0 student tickets to meet your goal. What if you sold 200 student tickets? How many other tickets would you need to sell? (200) = (-5/2)o + 250 (200) - 250 = (-5/2)o + 250 - 250 {add 250 to both sides to get rid of it on the right} -50 = (-5/2)o To get rid of the fraction, you have to divide by it since it's multiplying on the right side: -50/(-5/2) = o o = 20 So, if you sold 200 student tickets, you would need to sell 20 other tickets to make $500. On a graph, you could pick any x or y coordinate on the line made, and it would satisfy this equation. Hopefully that all made sense.... It's kind of ahead of adding like terms, but I can't think of when combining like terms would really have a use, although btherl did have a good example.... Oh... The parsing script: <?php $problems = "4k - 11k + 8k - 9k 19j + 16j 10r - 18r + 3r2 - 5r2 13t + 16v + 2t 3e - 6e 7h - 12h2 + 18h2 5s - 17s2 - 4s - 9s 1g + 12g - 15g + 3g + 4g 19m - 11m2 - 5m + 7m2 8z + 16z - 19z 2b + 11a + 13w - 6b - 3w 16f - 11u - 10g - 8u - 3u"; //12y + 8x + 13y + 4x when y= 2, x= 5 //9n + 17b when n= 2, b= 7 //It can't parse those... It could with a few mods though ;p //2t2 + 3t2 - 4t + 12t bleh i don't feel like messing with exponents... removed that too $problems = explode("\r\n", $problems); //split the problems string on newlines foreach($problems as $v) { //foreach problems as v $v = trim($v); //strip the line break from the end, and any white space on the left or right $v = str_replace(' ', '', $v); //replace spaces with nothing echo "Expression {$v} simplifies to " . ParseVars($v) . "\r\n"; //echo the original equation, and the equation post-parse } function ParseVars($prob) { //name the func and declare the args $match_count = preg_match_all('/([+-]{0,1})([0-9]*)([a-z]{1})/', $prob, $m); //match all of the pattern in the problem string, and dump the results into $m if($match_count == false) return false; //if there are 0 matches, or there is an error (preg_match_all returns bool false) make the function return false; $letter_sols = array(); //This array will be an associtive array that will keep track of letters and their values for($i = 0; $i < $match_count; $i++) { //i = 0; while i < match_count increment i //set some vars because I hate typing $sign = $m[1][$i]; //sign (+ or -) $val = (!empty($m[2][$i])) ? $m[2][$i] : 1; //value of the variable... for example 4k, this would be 4 $letter = $m[3][$i]; //letter... in 4k this would be k if($sign == '-') $val = -$val; //if the sign is -, since this is a string, the value needs to be negated. $letter_sols[$letter] = (isset($letter_sols[$letter])) ? $letter_sols[$letter] + $val : $val; //if the lettersol key isn't set, make it the value, else add the value //Since the value could be negative, adding a negative is the same as subtracting a positive.... for example, x - 4 is the same as x + (-4) } ksort($letter_sols); //orders the array in alphabetical order.... $out = ''; //make an empty string for the output $f = true; //first run = true... kind of a ghetto way to do this, but oh well ;p foreach($letter_sols as $k => $v) { //foreach of the letter soloutions, set k to the key and v to its value if($v == 0) continue; //if the value is 0, there's no reason to output the letter, so just skip it. $out .= ($v > 0 && $f != true) ? '+' . $v : $v; //if v is > 0 and it's not the first run, make it +{value} where value is the value. if it's the first run, or the value is negative, just output the value //this means it would be x+y or something, not +x+y since. This would keep - infront if it was negative. $out .= $k; //add the letter to the output string $f = false; //set the first run varaible to false } return $out; //return the out string } ?> Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 7, 2007 Share Posted November 7, 2007 1. 4k - 11k + 8k - 9k = -4k That would actually be -8k ;p. Was just scrolling by and saw that hehe ;p. Anyway, when would you need it.... Hmmm.... hard to think of an example off the top of my head that would make sense in real life without getting too complicated.... Actually... I can't think of a useful example of that off the top of my head, but once you get into more complex algebra, geometry, so on, things become more useful. For example: Bob has a roof line where it's a triangle (90 degree angle for simplisity). something like: -| - | - | - | - | _________| (pretend it looks like a triangle) He knows the right side is 3 meters tall, and he knows the bottom is 4 meters long, but he doesn't know how long to make the hypotenuse. Thanks to a guy named Pythagoras (slightly sarcastic) we know that a^2 + b^c = c^2 where c is the hypotenuse, or the side opposite the 90 degree angle (the longest side). a and b can be either of the legs besides the hypotenuse. So 3^2 + 4^2 = c^2 16 = c^2 So, to get rid of the power, you would find the square root of 16 which would be 4, thus the hypotenuse would need to be 4m. Sounds kind of pointless there, and that's not exactly what you're doing right now, but it was the only example I could think of in my tired state.... lol -------------------- As for doing it with PHP.... lemme write something really quickly.... sorry dude very sleepy when I replied...don't get me wrong I'am definitely good in Math...just tired and sleepy... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.