PDA

View Full Version : How would I accomplish something like this...



R0b0t1
01-04-2008, 04:49 AM
By the title, I mean how could I possibly compute it.

http://www.math.harvard.edu/computing/maxima/


Here's some console output I can show you...



Maxima 5.14.0 http://maxima.sourceforge.net
Using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (aka GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) solve(i*i+i^i/i/i=5,i);
i - 2 i - 2
(%o1) [i = - sqrt(5 - i ), i = sqrt(5 - i )]
(%i2) solve([i5i=5, 5i5=5],[i,i]);
Incorrect syntax: I5 is not an infix operator
solve([i5i=5,Space5i5=
^
(%i2) solve([i*5*i=5, 5*i*5=5],[i,i]);
(%o2) []
(%i3)


I know I can just look at the source, but c'mon! Thats like... Cheatin? Ya'know?

Rune Hacker
01-04-2008, 04:51 AM
What is the point of doing something that mathematically advanced?

R0b0t1
01-04-2008, 08:16 AM
If I could just get it to do basic algebra, I'd be happy.


Think of it as... a "loanable" home work "aid".

Yakman
01-05-2008, 01:14 PM
I know I can just look at the source, but c'mon! Thats like... Cheatin? Ya'know?

there was a time when I used to think like that as well, but if you have a very good resource like the complete source code, you should look at it.

you should only use your approach when you dont have the source and to crack or reverse-engineer the program.

BenLand100
01-05-2008, 07:54 PM
If you want to write a CAS then you need to just start somwhere, I sugest outlining the features you want then writeing a parser... However, doing something like that is next to impossible for one person. Yakman's got the right idea, there are some things that just aren't worth doing yourself. At least take hints from the way they abstract the data.

sherlockmeister
01-07-2008, 05:27 AM
ooh, i wrote one of these this as a little project while reading java tuts on sun.com. if you want an idea of how i started it was first with a parser that would format / error check input. then it converted the string input into arrays of polynomial objects (which had add, mul, pow, root, sub, div functions). then they were simplified (of course, there was a limited complexity that could be simplified). i never got around to making it an equation solver (i don't think i would be able to anyway), but it simplifies input algebraic expressions like this: "(a+b)(a+b)" => "a^2+2*a*b+b^2". anyway tell me if you want me to post the source, but it is in java.

R0b0t1
01-10-2008, 12:17 AM
Java is very similar to C, so go ahead.

sherlockmeister
01-10-2008, 02:54 AM
okey dokey, but bear in mind that when i wrote this i hadn't read the Pattern and Collections chapters in the tuts yet, so my code is pretty substandard. you will probably notice my unnecessary use of scanner and make-shift resizable arrays (not to mention a whole lot more). if i had returned to this project now i could have probably improved it but it became pretty boring. Anyway, you run this purely from the command line and syntax is as follows:
pow = '^' example: '5^a'
root = '|' '5|a'
mul = '*' '5*a'
div = '/' '5/a'
add = '+' '5+a'
sub = '-' '5-a'
the first argument is always the expression, example: "xx"
all following arguments are to assign vars values, example: "x=a+b"
"java main "xx" "x=a+b"" evalutes to "a^2+2*a*b+b^2"

keep in mind that "helloworld" evaluates to d*e*h*l^3*o^2*w not the variable "helloworld" so there are only 46 separate variables that you can use (a-z, A-Z)

also this will not simplify beyond a certain complexity,
example: "(a+b)^2" evaluates to "(a+b)^2"

last but not least, there might be bugs, i'm not perfect

i hope this helps you