1

I have no idea if this is even remotely possible (I looked up "computing algebra" etc with discouraging results). How can one compute Algebra and find Derivatives with Unity?

For example, simplifying the distance formula with one variable (x unkown, some function f(x) known):

d = sqrt( (int-x)^2 + (int-f(x))^2 );

and then finding the derivative of this simplified expression?:

d=>d'

Thank you for your time and any light you can shed on this question. And once again, I have no idea if algebraic operations are even commonplace among most programs, let alone Unity-script specifically.

I have also noticed a few systems claiming algebra manipulation (e.g. http://coffeequate.readthedocs.org/en/latest/), but even if this is so how would one go about applying these systems to unity?

Fattie
  • 27,874
  • 70
  • 431
  • 719
DrakeTruber
  • 327
  • 1
  • 6
  • 21
  • Derivatives are calculus, no? – guest271314 Apr 13 '16 at 01:38
  • @guest271314 yes, they are, which is why I addressed them as "Algebra and Derivatives" since Derivatives are not apart of Algebra. Luckily, Derivatives are the only Calculus operation I'm interested in at the moment. – DrakeTruber Apr 13 '16 at 01:40
  • 1
    See http://mathjs.org/docs/datatypes/complex_numbers.html – guest271314 Apr 13 '16 at 01:43
  • 1
    @guest271314 this looks like a good math system, but unfortunately I'm not seeing any hint to it having algebraic manipulation capabilities or of finding derivatives – DrakeTruber Apr 13 '16 at 01:49
  • 1
    It has been a while, would have to dig up notes, though fairly certain that the Fundamental Theorems of Calculus http://mathworld.wolfram.com/images/equations/FundamentalTheoremsofCalculus/NumberedEquation1.gif can be reduced to multiplication and subtraction to find derivative; see http://mathworld.wolfram.com/FundamentalTheoremsofCalculus.html – guest271314 Apr 13 '16 at 01:52
  • http://stackoverflow.com/questions/14927494/how-to-create-a-calculus-derivative-solver-using-javascript , http://stackoverflow.com/questions/6399777/looking-for-derivative-script , http://stackoverflow.com/questions/3162674/is-there-a-calculus-library-for-javascript – guest271314 Apr 13 '16 at 01:59
  • 1
    @DrakeSwartzy - you can't use "unityscript" anymore, it is deprecated and gone. you'd have to use c#. What you're looking for is really totally irrelevant to Unity. Further setting aside unity, it does not - really - exist. – Fattie Apr 13 '16 at 02:52
  • @JoeBlow you think so? Javascript seemed like a really prominent language in Unity along side c# – DrakeTruber Apr 13 '16 at 13:23
  • yes, forget it. c#. (btw it was never "javascript", but a weird thing "unityscript") even if available it's a total nonstarter for something like symbol manipulation, not even in the ballpark – Fattie Apr 13 '16 at 13:24
  • 1
    btw for this type of thing, to program "in c#" means to program ".Net". you're essentially looking for ".Net (that is to say, c#) math libraries". since the entire universe as well as all of commerce, manufacturing etc, runs on maths, yes, obviously there are any number of these - no problem. you can pick and choose. – Fattie Apr 13 '16 at 13:31
  • @JoeBlow That's unfortunate to hear indeed, I just transferred from AS3 and thought Unityscript would be the best decision since it is more similar than c#. Note that for the project I am working on I have simple goals, and what I'm asking for above is probably the most complicated thing I am trying to achieve. So there really isn't a way around using C#? I know very little of the language and would be a shame to have to drop what I've learned already and start a new one but I'm willing to do it if need be – DrakeTruber Apr 13 '16 at 13:37
  • Also perhaps it would be best to write in C# just for this aspect of the project? I don't even know if the two languages are compatible with each other – DrakeTruber Apr 13 '16 at 13:38
  • totally forget about "unityscript". note that (FWIW) c# is far easier – Fattie Apr 13 '16 at 13:43
  • @JoeBlow alright will do – DrakeTruber Apr 13 '16 at 13:47
  • open unity, make a new project, make a 3D cube. click to create a c# script. type in a couple lines. what about adding a Debug.Log to the Start routine. you're off! – Fattie Apr 13 '16 at 14:25
  • @JoeBlow exactly! C# is catching on a lot faster than I thought it would – DrakeTruber Apr 13 '16 at 14:35
  • 1
    yes, unfortunately in programming, languages *per se* mean almost nothing. it's little more than a syntax change. any experienced programmer can change between any language at any time. what you're learning is more the **system, IDE or API in question**. i'm a unity expert because I know exactly what `AddForce` does and i know how to connect to the interweb and get a file or whatsver. if, as it happened, unity suddenly had to use some different language, it would make almost literally no difference. enjoy! – Fattie Apr 13 '16 at 14:38
  • 1
    be sure to learn to use `List<>` it's totally central to unity. just make a simple List, load it up with a few strings, and print them out using Debug.Log. – Fattie Apr 13 '16 at 14:41
  • @JoeBlow I'll be sure to look into this, thanks for the advice – DrakeTruber Apr 13 '16 at 14:42
  • 1
    secondly I urge you to learn to use **extensions** from the very get-go! they are really central to Unity idiom. here's a quick tutorial from some drunk http://stackoverflow.com/a/35629303/294884 – Fattie Apr 13 '16 at 14:43
  • 1
    and finally! :) one of the best things in Unity and most important - *particularly for what you are interested in* - is the so-called "new" UI in unity. (unity used to have incredibly bad UI, but some years ago they introduced the "new" UI, which is fantastic). just click **"add canvas"**. be sure to select "scale with screen size". simply, add some stuff (say a couple Text items and some Buttons) under your Canvas. have a ball. put a simple function in one of your script `public void Clicked()` and learn how to "drag" that to your button. Enjoy. in the function, `Debug.Log("hello");` – Fattie Apr 13 '16 at 14:46
  • @JoeBlow excellent! thank you once again – DrakeTruber Apr 13 '16 at 14:49
  • no worries i like to talk so there you go. – Fattie Apr 13 '16 at 14:54

1 Answers1

1

If you are writing in C#, you can pull off derivatives with delegates and the definition of a derivative, like this:

delegate double MathFunc(double d);
MathFunc derive(MathFunc f, float h) {
    return (x) => (f(x+h) - f(x)) / h;
}

where f in the function you are taking the derivative of, and h determines how accurate your derivative is.

sowrd299
  • 149
  • 6
  • Excellent. Is there a Unity Javascript equivalent? And any idea how I could go about solving algebra? – DrakeTruber Apr 13 '16 at 13:27
  • i believe OP is literally trying to do symbolic algebra. (comments like "solve algebra"). in that case you need a research project like SymPy, http://www.sympy.org/en/index.html (it's relatively easy to wrap python with c# and hence to unity) – Fattie Apr 13 '16 at 13:34
  • @JoeBlow would would be involved with achieving this? How could this library be brought into Unity? I'm completely new to this idea – DrakeTruber Apr 13 '16 at 13:43
  • 1
    you would have to build basic skills with unity, with .Net, and then at adding libraries and so on. it would be much like asking "how to build a house?" on a forum for builders. it's a meaningless question. you can only really ask specific questions like "I'm having trouble with the sand percentage on some stone quoining" and the answer might be "try 14%!" you're literally asking the equivalent of "how to I build a house" or "how do I make an airplane". software engineering is the most difficult of things, it takes 10+ man-years to be merely competent. just start slowly and have fun! – Fattie Apr 13 '16 at 14:27
  • @JoeBlow it sounds as though importing one of these software would not be the wisest decision for me then at this point, I should probably stick with just what I'm given for C# in Unity. But eventually I'll definitely look into that and use it for my future projects. Thanks for the help – DrakeTruber Apr 13 '16 at 14:39