PDA

View Full Version : mini MATLAB in Flash ;)

amen0
11-27-2005, 12:44 AM
hi all just wanna see a flash application that can evaluate a math. expression
like
>>2+8-(5*3)
>>ans=
-5
>>sin(pi*3/2)+3
>>ans=
2
let's see ...
only to make it simple make only the arithmetic operation
as for me i can do the first one coz i programmed it in C# long ago and it's easy but the seconde i think is the Challenges.
ok guys let's see what u can do ... ;)

Laguana
11-30-2005, 09:31 AM
Is this supposed to be in 25 < lines of code? 'Cause i've made a calculator already (works in base 12 :P) but I'm pretty sure it's more than 25 lines. Also, there's a math.eval function someone's put on layer51 which works with pretty much everything, which is pretty cool. It's certainly more than 25 lines.

amen0
11-30-2005, 03:14 PM
hi, can u show us ur .swf file.:)

Laguana
12-01-2005, 11:42 AM
Well, it's at http://thor.prohosting.com/laguana/B12Calc.swf. It's still buggy i think, 'cause i was just messing 'round with it. Also, it uses crazy symbols 'cause me and my friends made up our own base 12 notation :P

If i recall, | is a decimal place, so 1|2 is 1.2, in base 12, so it's 1 and 2 12ths. V is 10, X is 11. ~ is the negative button, so pressing 1 then ~ should make it -1. The other symbols should be recognised already. It works fine for single operations, and follows order of operations, but brackets break it really easially.

Morg
12-01-2005, 11:57 AM
Slightly off the topic...

Which is correct?
4+5*6=54
or
4+5*6=34

???

I keep wondering about this.. Conventional calclators (as in Windows calculator) show 54 as being correct... YET, scientific calculators, apply BODMAS to the equation before working it out... :(

If anyone knows, please let me know too...

amen0
12-01-2005, 05:05 PM
well Laguna this is totally different for what i m asking for :)
have'nt u work in the MatLap Program
it's like this
ur input is a string
>> 2*6-3
then the program respond 9
u know not input are buttons ( ur calculator is too easy to make) sorry but it's not the challenge i m asking for ;)

12-01-2005, 08:26 PM
Slightly off the topic...

Which is correct?
4+5*6=54
or
4+5*6=34

???

I keep wondering about this.. Conventional calclators (as in Windows calculator) show 54 as being correct... YET, scientific calculators, apply BODMAS to the equation before working it out... :(

If anyone knows, please let me know too...

definitely not off topic. the order of operations is imperitive for a calculator that allows input strings. basic calculators that perform one operation at a time (such as the windows calculator) don't need to worry about the order of operations, as they only compute two numbers at a time.

the equation (4+5*6) is ALWAYS equal to 34. the only reason basic calculators would return 54 is user error (it is up to YOU to enter the numbers in the right order).

aren't challenges supposed to be started with a working example? it's always suspicious when people describe a complicated task, but don't put forth the effort to do it themselves. it makes me think the originator is posting his/her CS homework assignment hoping someone will do the work for him/her for free.

Morg
12-02-2005, 08:20 AM

Yea, I spoke to one of my old math teachers yesterday... He said the same thing. If theres no brackets, then start at the left, and run through it normally.

Thanks for the response! Much appreciated! :D

amen0
12-02-2005, 09:14 AM
oh yeah this thread is about calculation and Math Calculator, LOL :)

Morg
12-02-2005, 10:32 AM
Ok, so back to the challenge:

amen0, you are looking for a basically 2 textfields; the ones an input field and the other an output field? You type a long equation in there, and then hit answer to see the program work it out for you?

Have you done one already?

amen0
12-02-2005, 06:55 PM
well some kind of that
i ve done the first(basic calculation) one in C#

amen0
12-03-2005, 05:43 AM
ok guys i made my own (arithmetic of course )
let's see yours...
http://amen.cjb.cc/matlab/matLab.html

Laguana
12-03-2005, 12:12 PM
Actually amen0, the buttons just add things to the string, which is then worked on. All the buttons do is limit your ability to stuff it up, by adding, say, a & in there which would result in a NaN and breaking things. The way i've done it, the button presses form a string (shown to the left of the little window), then the string is split into arrays within arrays in reverse order of operations, and then solved from the deepest out. It's horribly inefficient i'm sure, and brackets stuff it over as i said, but it works as much as some calculators do, so i'm happy with it as far as it goes ;) It's just a novelty, but it does fit at least mostly what you asked for, I believe.

amen0
12-03-2005, 06:12 PM
sorry Laguana :), but i thought your app is just a calculator,
well if just u can modify it to get a result just like mine and more than that
(no buttons) :P it can calculate the sin and cos and.... with the arithmetic operation
considere the thread is closed :) ;)

12-04-2005, 09:20 AM
i threw together something that does the four basic operations (*/+-) and follows the order of operations. it wouldn't take long to add in trig functions, but i don't have very much spare time at the moment.

cool thing about this is that it walks you through the steps while it simplifies the equation. this technique would be very useful for grade schoolers being introduced to the order of operations in Algebra I

i included the FLA. sorry, no comments, and it could use more organization with the flow. written in AS1 and is set to export as FP6.

have fun :)

amen0
12-04-2005, 09:28 AM
Cool ,i like the way you display every iteration ;)
till next one :p
 i reopened the thread coz after testing urs with this exp ((1*2)-3/5)) it gives a wrong answer but i m sure if u have time u can make it all perfect ;) coz ur idea is so right :)

12-05-2005, 03:53 PM
o.O !!
yep.. definitely a bug

i try to test as many situations as possible, but apparently missed that one. it gets tricky when you have to determine if the "-" is making a number negative, or if it's being used for subtraction from the number to the left of it.

i through in some extra tests to give the program a little better idea of what's going on in the equation :)

don't close the thread! i don't think we're quite finished. keep testing what i have so far and let me know if anything else crashes it.

i think the thread should be finished when someone creates one that solves equations that contain trig functions!

[EDIT] - i encourage anyone to use mine as a base and add functionality. unfortunately, it won't be easy, the code is a little chaotic and lacking some organization. but if you can make sense of it, add to it! :D

amen0
12-05-2005, 11:31 PM
Great Work. Now,It;s in testing Area...

hangalot
12-06-2005, 06:02 PM

Yea, I spoke to one of my old math teachers yesterday... He said the same thing. If theres no brackets, then start at the left, and run through it normally.

Thanks for the response! Much appreciated! :D
wrong.
* and / have precedence over + and -, standard fare programming languages

12-07-2005, 07:37 PM
i haven't had any time to open up the flash file to add in the trig functionality. the invitation is still open for anyone else to make their own or improve on the one i posted. if you want to start with mine as a base, feel free to post code snippets you have questions about.

this could actually be quite interesting. with more functionality and an interface (note: i said 'an interface' rather than 'a better interface'.. what it has right now can hardly be considered an interface) this could be very useful to students taking algebra and trig courses. scientific calculators fall short because they don't explain how they got the answer.

abacajan
12-09-2005, 10:42 PM

Yea, I spoke to one of my old math teachers yesterday... He said the same thing. If theres no brackets, then start at the left, and run through it normally.

Thanks for the response! Much appreciated! :D

with 4+5*6 it equals 34.
B rackets
O ver
D ivision
M ultiplication
S ubtraction

Meaning you always evaluate the equation in the brackets first then * and / then + and -. But scince there is no brackets you do the multiplication first to simplify the question to 4 + 30. The reason windows calculator gets 54 is because you type 4 + 5 * 6 But it sees it as this : 4+5=9; 9*6=54. Whenever you press a +-/ or* it works out what you have just done and remembers it. BUT with a scientific calculator it has a seperate area for the formula and the answer. So it evaluates the entire question in one go, applying BODMAS.

abacajan
12-09-2005, 10:49 PM
Cool ,i like the way you display every iteration ;)
till next one :p
 i reopened the thread coz after testing urs with this exp ((1*2)-3/5)) it gives a wrong answer but i m sure if u have time u can make it all perfect ;) coz ur idea is so right :)

Not a bug. A simple error in your equation. I thought an action scripter of all people would remember to close all they're brackets. ((1*2)-3/5)) Didn't close it.

amen0
12-10-2005, 01:55 AM
@abacajan yeah your right about it but it still give a wrong answer
input
((1*2)-3/5)
output
((1*2)-3/5) // Multiply: 1 times 2
(2-3/5) // Divide: 2-3 divided by 5
0.4

12-12-2005, 11:10 PM
it was definitely a bug. even if the equation had been entered properly, the script would fail A-B/C (or A-B*C). the script wasn't looking carefully enough to see if the - was subtraction or if it was making B negative.

it is fixed with the newer version (two posts later).

i was a little lazy when adding in support for negative numbers. i put the "-" character in the group of digits, that way it would pull out -A and -B out of (-A*-B). i *should* have created a second statement, but i was lazy. it should check to see if the character is a digit, then move on if it is. if it isn't, then check to see if it's "-" and then check to see if it's being used for subraction or to make the number negative.

instead of going back and separating it into multiple statements (then updating all other parts of the script that rely on the current method), i created a workaround for it.

still haven't had time to add in trigonometry or anything... busy busy

darkzak
12-15-2005, 04:50 PM
Found this math parser which seems to do everything you wanted.

http://flashgizmo.com/parser.html

amen0
12-15-2005, 04:59 PM
lol, nice very nice ;) i like it .

skdrift
08-08-2007, 10:22 PM
I was wondering if someone could help me out I have to do this project for my class I am done with the code that does the half life of an element that starts at 100. But I need help using a if statement so that the program will only display the 3th number instead of all 24: this is using matlab or octave

clear
half_life=100
for time=1:1:24
half_life=(half_life)./2
end

thank you

skdrift
08-08-2007, 10:26 PM
sorry I wrote the wrong information before I need to see if the program could display number every third half life instead of all 24

xwielder
01-04-2008, 02:59 PM
wrong.
* and / have precedence over + and -, standard fare programming languages

Hangalot is correct.

Either your teacher is wrong or you misunderstood what your teacher was saying.