Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,277 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,201 people online right now. Registration is fast and FREE... Join Now!




Calculus Operations

 
Reply to this topicStart new topic

Calculus Operations, Probably WAY outta my league...

Locke37
post 25 Sep, 2008 - 01:54 PM
Post #1


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 911



Thanked 30 times

Dream Kudos: 300
My Contributions


Welp, I've finally decided to actually give this a shot. I've wanted to make a program derive equations that are fed into it.

I've gotten some functionality out of it...but I can only input in a certain format. I CANNOT have spaces in between terms and operators...

4x^2+2x+1 = OK
4x^2 + 2x + 1 != OK

I'm using Java for this, mainly because I don't know squat about Regular Expressions, which are used in .Net. The only language of .Net I know worth anything is VB, which I still don't feel comfortable with, since I learned it on my own, and relied on a lot of my VB6 knowledge.

Any suggestions on how to go about this...?

And yes I know there are better ways to implement these things, but this is a rough version, I started it yesterday.

PS: It works for any terms (with no negative or multi-term exponents) (using the power rule)

f(x) = x^n ----> f'(x) = nx^(n-1)

I don't have any other rules coded out yet.

Here's the source code if you wanna look at it. It's just one file for now, with a small main method for testing.

Attached File  Function.zip ( 1.73k ) Number of downloads: 10


This post has been edited by Locke37: 25 Sep, 2008 - 02:23 PM
User is offlineProfile CardPM

Go to the top of the page

Moonbat
post 25 Sep, 2008 - 01:57 PM
Post #2


D.I.C Regular

Group Icon
Joined: 30 Jun, 2008
Posts: 383



Thanked 22 times

Dream Kudos: 600
My Contributions


Doesn't Java have any function to strip certain characters away? You can just get rid of the spaces.

I found this with Google. It says it can strip characters away, but I'm no Java expert, so you can take a look at it yourself:

http://www.java-tips.org/java-se-tips/java...m-a-string.html
User is offlineProfile CardPM

Go to the top of the page

Locke37
post 25 Sep, 2008 - 02:01 PM
Post #3


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 911



Thanked 30 times

Dream Kudos: 300
My Contributions


I'm way outta my league with this...I know...

I can strip spaces and such, it's just that it's hard to get at individual terms the way I did it, and if you enter spaces...it can't get at the terms correctly, it adds a null term.

And dammit I lost that idea...

This post has been edited by Locke37: 25 Sep, 2008 - 02:06 PM
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 25 Sep, 2008 - 02:53 PM
Post #4


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,983



Thanked 78 times

Dream Kudos: 1175
My Contributions


Here is a very simple little "eliminate spaces" script that I came up with.:

CODE
public class Runner
{
    public static void main(String[] args){
        String test = new String("TESTing this thing out");
        //test.split(" ");
        String fin = "";
        for(int i=0; i<test.length(); i++){
            if(test.charAt(i) != ' ')
            fin += ""+test.charAt(i);
        }
        System.out.println("The String '"+test+"' has been turned into '"+fin+"'");
    }
}


And here is another quicky:
CODE
public class Runner
{
    public static void main(String[] args){
        String test = new String("TESTing this thing out");
        String fin = "";
        fin = test.replaceAll(" ", fin);
        System.out.println("The String '"+test+"' has been turned into '"+fin+"'");
    }
}


Hope that comes into use and you can get it to work nicely with your project smile.gif
User is offlineProfile CardPM

Go to the top of the page

GWatt
post 25 Sep, 2008 - 03:20 PM
Post #5


human inside

Group Icon
Joined: 1 Dec, 2005
Posts: 2,150



Thanked 16 times

Dream Kudos: 450
My Contributions


Java Strings have a split method.
string.split("\\s");
Will return an array of strings that have been split around whitespace.

You can then iterate through the array and append all of the elements to another sting.
User is online!Profile CardPM

Go to the top of the page

baavgai
post 25 Sep, 2008 - 03:46 PM
Post #6


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,960



Thanked 95 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


You're making this way too hard. This quick test seems fine:
java

String s = "4x^2 + 2x + 1";
System.out.println(s);
s = s.replaceAll(" ", "");
System.out.println(s);


User is offlineProfile CardPM

Go to the top of the page

Locke37
post 26 Sep, 2008 - 07:48 AM
Post #7


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 911



Thanked 30 times

Dream Kudos: 300
My Contributions


QUOTE(baavgai @ 25 Sep, 2008 - 04:46 PM) *

You're making this way too hard. This quick test seems fine:
java

String s = "4x^2 + 2x + 1";
System.out.println(s);
s = s.replaceAll(" ", "");
System.out.println(s);



That makes sense...duh unsure.gif

I R dum. Because that worked...can't believe I didn't think of that, it's so simple.

Thanks a lot by the way!

This post has been edited by Locke37: 26 Sep, 2008 - 07:53 AM
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 26 Sep, 2008 - 12:17 PM
Post #8


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


This might help you along the way. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Locke37
post 27 Sep, 2008 - 06:47 PM
Post #9


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 911



Thanked 30 times

Dream Kudos: 300
My Contributions


Ok, new task. Figuring out how to do the quotient rule.

For those of you who don't know...

f(x) = a / b --> f'(x) = (ba' - ab') / (b^2)

And, this is a future task, but...any ideas on how to actually make the program figure out what method to use to derive the given term/equation?
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 12:40AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month